Skip to content

Commit

Permalink
[3.13] gh-125997: Increase test coverage for time.sleep() (GH-128751)…
Browse files Browse the repository at this point in the history
… (#128796)

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 <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
3 people authored Jan 13, 2025
1 parent 1079619 commit f2a2809
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,19 @@ def test_conversions(self):
self.assertEqual(int(time.mktime(time.localtime(self.t))),
int(self.t))

def test_sleep(self):
def test_sleep_exceptions(self):
self.assertRaises(TypeError, time.sleep, [])
self.assertRaises(TypeError, time.sleep, "a")
self.assertRaises(TypeError, time.sleep, complex(0, 0))

self.assertRaises(ValueError, time.sleep, -2)
self.assertRaises(ValueError, time.sleep, -1)
time.sleep(1.2)
self.assertRaises(ValueError, time.sleep, -0.1)

def test_sleep(self):
for value in [-0.0, 0, 0.0, 1e-100, 1e-9, 1e-6, 1, 1.2]:
with self.subTest(value=value):
time.sleep(value)

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

0 comments on commit f2a2809

Please sign in to comment.