summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2025-01-13 16:58:11 (GMT)
committerGitHub <noreply@github.com>2025-01-13 16:58:11 (GMT)
commitb70a567575db37846beecbe8b40fb56b875274db (patch)
treeb8b4af75469d7310bbde572d491beb493c15815e
parent53e8942e6938df3a32b783815f1bd4b76eed3dd0 (diff)
downloadcpython-b70a567575db37846beecbe8b40fb56b875274db.zip
cpython-b70a567575db37846beecbe8b40fb56b875274db.tar.gz
cpython-b70a567575db37846beecbe8b40fb56b875274db.tar.bz2
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 <vstinner@python.org>
-rw-r--r--Lib/test/test_time.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 1c540be..1147997 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -158,10 +158,19 @@ class TimeTestCase(unittest.TestCase):
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: