diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-03-02 21:54:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-03-02 21:54:03 (GMT) |
commit | 643cd68ea4b8d33a6d0163ef693ef6518f76b88f (patch) | |
tree | 4dda5f7783635633cc2d092dd975461ba263d2c0 /Lib | |
parent | 1c13f84f5554cecbdce8bf42dbfb609c1f72282a (diff) | |
download | cpython-643cd68ea4b8d33a6d0163ef693ef6518f76b88f.zip cpython-643cd68ea4b8d33a6d0163ef693ef6518f76b88f.tar.gz cpython-643cd68ea4b8d33a6d0163ef693ef6518f76b88f.tar.bz2 |
Issue #13964: signal.sigtimedwait() timeout is now a float instead of a tuple
Add a private API to convert an int or float to a C timespec structure.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_signal.py | 10 | ||||
-rw-r--r-- | Lib/test/test_time.py | 21 |
2 files changed, 24 insertions, 7 deletions
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index fdeb4c2..6be259b 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -662,7 +662,7 @@ class PendingSignalsTests(unittest.TestCase): self.wait_helper(signal.SIGALRM, ''' def test(signum): signal.alarm(1) - info = signal.sigtimedwait([signum], (10, 1000)) + info = signal.sigtimedwait([signum], 10.1000) if info.si_signo != signum: raise Exception('info.si_signo != %s' % signum) ''') @@ -675,7 +675,7 @@ class PendingSignalsTests(unittest.TestCase): def test(signum): import os os.kill(os.getpid(), signum) - info = signal.sigtimedwait([signum], (0, 0)) + info = signal.sigtimedwait([signum], 0) if info.si_signo != signum: raise Exception('info.si_signo != %s' % signum) ''') @@ -685,7 +685,7 @@ class PendingSignalsTests(unittest.TestCase): def test_sigtimedwait_timeout(self): self.wait_helper(signal.SIGALRM, ''' def test(signum): - received = signal.sigtimedwait([signum], (1, 0)) + received = signal.sigtimedwait([signum], 1.0) if received is not None: raise Exception("received=%r" % (received,)) ''') @@ -694,9 +694,7 @@ class PendingSignalsTests(unittest.TestCase): 'need signal.sigtimedwait()') def test_sigtimedwait_negative_timeout(self): signum = signal.SIGALRM - self.assertRaises(ValueError, signal.sigtimedwait, [signum], (-1, -1)) - self.assertRaises(ValueError, signal.sigtimedwait, [signum], (0, -1)) - self.assertRaises(ValueError, signal.sigtimedwait, [signum], (-1, 0)) + self.assertRaises(ValueError, signal.sigtimedwait, [signum], -1.0) @unittest.skipUnless(hasattr(signal, 'sigwaitinfo'), 'need signal.sigwaitinfo()') diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index a89c511..26492c1 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -497,12 +497,31 @@ class TestStrftime4dyear(_TestStrftimeYear, _Test4dYear): pass +class TestPytime(unittest.TestCase): + def test_timespec(self): + from _testcapi import pytime_object_to_timespec + for obj, timespec in ( + (0, (0, 0)), + (-1, (-1, 0)), + (-1.0, (-1, 0)), + (-1e-9, (-1, 999999999)), + (-1.2, (-2, 800000000)), + (1.123456789, (1, 123456789)), + ): + self.assertEqual(pytime_object_to_timespec(obj), timespec) + + for invalid in (-(2 ** 100), -(2.0 ** 100.0), 2 ** 100, 2.0 ** 100.0): + self.assertRaises(OverflowError, pytime_object_to_timespec, invalid) + + + def test_main(): support.run_unittest( TimeTestCase, TestLocale, TestAsctime4dyear, - TestStrftime4dyear) + TestStrftime4dyear, + TestPytime) if __name__ == "__main__": test_main() |