Skip to content

Commit 3d87bf2

Browse files
picnixzvstinner
authored andcommitted
pythongh-125997: Increase test coverage for time.sleep() (pythonGH-128751)
- Add tests for durations of invalid types. - Add tests for `int` and `float` durations, including signed zeroes durations. - Add tests for nonzero very small durations and durations close to the clock resolution. --------- (cherry picked from commit b70a567) Co-authored-by: Bénédikt Tran <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
1 parent 1079619 commit 3d87bf2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Lib/test/test_time.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,19 @@ def test_conversions(self):
157157
self.assertEqual(int(time.mktime(time.localtime(self.t))),
158158
int(self.t))
159159

160-
def test_sleep(self):
160+
def test_sleep_exceptions(self):
161+
self.assertRaises(TypeError, time.sleep, [])
162+
self.assertRaises(TypeError, time.sleep, "a")
163+
self.assertRaises(TypeError, time.sleep, complex(0, 0))
164+
161165
self.assertRaises(ValueError, time.sleep, -2)
162166
self.assertRaises(ValueError, time.sleep, -1)
163-
time.sleep(1.2)
167+
self.assertRaises(ValueError, time.sleep, -0.1)
168+
169+
def test_sleep(self):
170+
for value in [-0.0, 0, 0.0, 1e-100, 1e-9, 1e-6, 1, 1.2]:
171+
with self.subTest(value=value):
172+
time.sleep(value)
164173

165174
def test_epoch(self):
166175
# bpo-43869: Make sure that Python use the same Epoch on all platforms:

0 commit comments

Comments
 (0)