From: Giampaolo RodolĂ  Date: Wed, 4 Aug 2010 09:28:05 +0000 (+0000) Subject: issue #8687: provides a test suite for sched.py module X-Git-Tag: v3.2a2~478 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b5c23761d3ef63d596d5f0c1f1e510b30fdf21e1;p=thirdparty%2FPython%2Fcpython.git issue #8687: provides a test suite for sched.py module --- diff --git a/Lib/test/test_sched.py b/Lib/test/test_sched.py new file mode 100644 index 000000000000..29fd277746f7 --- /dev/null +++ b/Lib/test/test_sched.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import sched +import time +import unittest +from test import support + + +class TestCase(unittest.TestCase): + + def test_enter(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + for x in [0.05, 0.04, 0.03, 0.02, 0.01]: + z = scheduler.enter(x, 1, fun, (x,)) + scheduler.run() + self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + + def test_enterabs(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + for x in [0.05, 0.04, 0.03, 0.02, 0.01]: + z = scheduler.enterabs(x, 1, fun, (x,)) + scheduler.run() + self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05]) + + def test_priority(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + for priority in [1, 2, 3, 4, 5]: + z = scheduler.enter(0.01, priority, fun, (priority,)) + scheduler.run() + self.assertEqual(l, [1, 2, 3, 4, 5]) + + def test_cancel(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + event1 = scheduler.enter(0.01, 1, fun, (0.01,)) + event2 = scheduler.enter(0.02, 1, fun, (0.02,)) + event3 = scheduler.enter(0.03, 1, fun, (0.03,)) + event4 = scheduler.enter(0.04, 1, fun, (0.04,)) + event5 = scheduler.enter(0.05, 1, fun, (0.05,)) + scheduler.cancel(event1) + scheduler.cancel(event5) + scheduler.run() + self.assertEqual(l, [0.02, 0.03, 0.04]) + + def test_empty(self): + l = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + self.assertTrue(scheduler.empty()) + for x in [0.05, 0.04, 0.03, 0.02, 0.01]: + z = scheduler.enterabs(x, 1, fun, (x,)) + self.assertFalse(scheduler.empty()) + scheduler.run() + self.assertTrue(scheduler.empty()) + + def test_queue(self): + l = [] + events = [] + fun = lambda x: l.append(x) + scheduler = sched.scheduler(time.time, time.sleep) + self.assertEqual(scheduler._queue, []) + for x in [0.05, 0.04, 0.03, 0.02, 0.01]: + events.append(scheduler.enterabs(x, 1, fun, (x,))) + self.assertEqual(scheduler._queue.sort(), events.sort()) + scheduler.run() + self.assertEqual(scheduler._queue, []) + + +def test_main(): + support.run_unittest(TestCase) + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_sundry.py b/Lib/test/test_sundry.py index a956b3b94601..065c6851a9a0 100644 --- a/Lib/test/test_sundry.py +++ b/Lib/test/test_sundry.py @@ -57,7 +57,6 @@ class TestUntestedModules(unittest.TestCase): import pstats import py_compile import rlcompleter - import sched import sndhdr import symbol import tabnanny diff --git a/Misc/NEWS b/Misc/NEWS index f051eb4465a1..98b8da116ff6 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -105,6 +105,11 @@ Tools/Demos - Issue #8867: Fix ``Tools/scripts/serve.py`` to work with files containing non-ASCII content. +Tests +----- + +- Issue #8687: provide a test suite for sched.py module. + What's New in Python 3.2 Alpha 1? =================================