Skip to content

Commit b70a567

Browse files
picnixzvstinner
andauthored
gh-125997: Increase test coverage for time.sleep() (#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. --------- Co-authored-by: Victor Stinner <[email protected]>
1 parent 53e8942 commit b70a567

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
@@ -158,10 +158,19 @@ def test_conversions(self):
158158
self.assertEqual(int(time.mktime(time.localtime(self.t))),
159159
int(self.t))
160160

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

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

0 commit comments

Comments
 (0)