Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5c2376

Browse files
committed
issue #8687: provides a test suite for sched.py module
1 parent 934abdd commit b5c2376

3 files changed

Lines changed: 85 additions & 1 deletion

File tree

Lib/test/test_sched.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python
2+
3+
import sched
4+
import time
5+
import unittest
6+
from test import support
7+
8+
9+
class TestCase(unittest.TestCase):
10+
11+
def test_enter(self):
12+
l = []
13+
fun = lambda x: l.append(x)
14+
scheduler = sched.scheduler(time.time, time.sleep)
15+
for x in [0.05, 0.04, 0.03, 0.02, 0.01]:
16+
z = scheduler.enter(x, 1, fun, (x,))
17+
scheduler.run()
18+
self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05])
19+
20+
def test_enterabs(self):
21+
l = []
22+
fun = lambda x: l.append(x)
23+
scheduler = sched.scheduler(time.time, time.sleep)
24+
for x in [0.05, 0.04, 0.03, 0.02, 0.01]:
25+
z = scheduler.enterabs(x, 1, fun, (x,))
26+
scheduler.run()
27+
self.assertEqual(l, [0.01, 0.02, 0.03, 0.04, 0.05])
28+
29+
def test_priority(self):
30+
l = []
31+
fun = lambda x: l.append(x)
32+
scheduler = sched.scheduler(time.time, time.sleep)
33+
for priority in [1, 2, 3, 4, 5]:
34+
z = scheduler.enter(0.01, priority, fun, (priority,))
35+
scheduler.run()
36+
self.assertEqual(l, [1, 2, 3, 4, 5])
37+
38+
def test_cancel(self):
39+
l = []
40+
fun = lambda x: l.append(x)
41+
scheduler = sched.scheduler(time.time, time.sleep)
42+
event1 = scheduler.enter(0.01, 1, fun, (0.01,))
43+
event2 = scheduler.enter(0.02, 1, fun, (0.02,))
44+
event3 = scheduler.enter(0.03, 1, fun, (0.03,))
45+
event4 = scheduler.enter(0.04, 1, fun, (0.04,))
46+
event5 = scheduler.enter(0.05, 1, fun, (0.05,))
47+
scheduler.cancel(event1)
48+
scheduler.cancel(event5)
49+
scheduler.run()
50+
self.assertEqual(l, [0.02, 0.03, 0.04])
51+
52+
def test_empty(self):
53+
l = []
54+
fun = lambda x: l.append(x)
55+
scheduler = sched.scheduler(time.time, time.sleep)
56+
self.assertTrue(scheduler.empty())
57+
for x in [0.05, 0.04, 0.03, 0.02, 0.01]:
58+
z = scheduler.enterabs(x, 1, fun, (x,))
59+
self.assertFalse(scheduler.empty())
60+
scheduler.run()
61+
self.assertTrue(scheduler.empty())
62+
63+
def test_queue(self):
64+
l = []
65+
events = []
66+
fun = lambda x: l.append(x)
67+
scheduler = sched.scheduler(time.time, time.sleep)
68+
self.assertEqual(scheduler._queue, [])
69+
for x in [0.05, 0.04, 0.03, 0.02, 0.01]:
70+
events.append(scheduler.enterabs(x, 1, fun, (x,)))
71+
self.assertEqual(scheduler._queue.sort(), events.sort())
72+
scheduler.run()
73+
self.assertEqual(scheduler._queue, [])
74+
75+
76+
def test_main():
77+
support.run_unittest(TestCase)
78+
79+
if __name__ == "__main__":
80+
test_main()

Lib/test/test_sundry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def test_at_least_import_untested_modules(self):
5757
import pstats
5858
import py_compile
5959
import rlcompleter
60-
import sched
6160
import sndhdr
6261
import symbol
6362
import tabnanny

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ Tools/Demos
105105
- Issue #8867: Fix ``Tools/scripts/serve.py`` to work with files containing
106106
non-ASCII content.
107107

108+
Tests
109+
-----
110+
111+
- Issue #8687: provide a test suite for sched.py module.
112+
108113

109114
What's New in Python 3.2 Alpha 1?
110115
=================================

0 commit comments

Comments
 (0)