From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:16:25 +0000 (+0100) Subject: [3.12] gh-125997: Increase test coverage for `time.sleep()` (GH-128751) (#128795) X-Git-Tag: v3.12.9~79 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e7400d787734ecf1ee3ae7a877ecf9aaeb76cf6c;p=thirdparty%2FPython%2Fcpython.git [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 b70a567575db37846beecbe8b40fb56b875274db) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> Co-authored-by: Victor Stinner --- diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 9463adda88db..9ec51bd365a7 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -153,10 +153,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: