Skip to content

Commit 17e4920

Browse files
committed
improve tests for time.sleep()
1 parent 3a570c6 commit 17e4920

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Lib/test/test_time.py

Lines changed: 11 additions & 2 deletions
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-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)