]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-125997: Increase test coverage for `time.sleep()` (#128751)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Mon, 13 Jan 2025 16:58:11 +0000 (17:58 +0100)
committerGitHub <noreply@github.com>
Mon, 13 Jan 2025 16:58:11 +0000 (17:58 +0100)
- 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>
Lib/test/test_time.py

index 1c540bed33c71ea28552f505464709dc9f7c64ab..1147997d8d86bf21c4d09d4e38514e38d5637131 100644 (file)
@@ -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: