Skip to content

Commit e7400d7

Browse files
miss-islingtonpicnixzvstinner
authored
[3.12] gh-125997: Increase test coverage for time.sleep() (GH-128751) (#128795)
gh-125997: Increase test coverage for `time.sleep()` (GH-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 552b2a0 commit e7400d7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Lib/test/test_time.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,19 @@ def test_conversions(self):
153153
self.assertEqual(int(time.mktime(time.localtime(self.t))),
154154
int(self.t))
155155

156-
def test_sleep(self):
156+
def test_sleep_exceptions(self):
157+
self.assertRaises(TypeError, time.sleep, [])
158+
self.assertRaises(TypeError, time.sleep, "a")
159+
self.assertRaises(TypeError, time.sleep, complex(0, 0))
160+
157161
self.assertRaises(ValueError, time.sleep, -2)
158162
self.assertRaises(ValueError, time.sleep, -1)
159-
time.sleep(1.2)
163+
self.assertRaises(ValueError, time.sleep, -0.1)
164+
165+
def test_sleep(self):
166+
for value in [-0.0, 0, 0.0, 1e-100, 1e-9, 1e-6, 1, 1.2]:
167+
with self.subTest(value=value):
168+
time.sleep(value)
160169

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

0 commit comments

Comments
 (0)