diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-27 18:19:03 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-27 18:19:03 +0100 |
commit | 34dc0f46ae5c0c9ec91d9402fac61111b802855f (patch) | |
tree | 274e9bac8b7049fabac4f16161676edfd847c771 /Lib/test/test_time.py | |
parent | 7181dec3f12f11c9a5f4adc6336b1c7273452308 (diff) | |
download | cpython-git-34dc0f46ae5c0c9ec91d9402fac61111b802855f.tar.gz |
Issue #22117: The signal modules uses the new _PyTime_t API
* Add _PyTime_AsTimespec()
* Add unit tests for _PyTime_AsTimespec()
Diffstat (limited to 'Lib/test/test_time.py')
-rw-r--r-- | Lib/test/test_time.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 817da8a01d..cfec329f01 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -10,6 +10,11 @@ try: import threading except ImportError: threading = None +try: + import _testcapi +except ImportError: + _testcapi = None + # Max year is only limited by the size of C int. SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4 @@ -768,7 +773,8 @@ class TestPytime(unittest.TestCase): self.assertIs(lt.tm_zone, None) -@support.cpython_only +@unittest.skipUnless(_testcapi is not None, + 'need the _testcapi module') class TestPyTime_t(unittest.TestCase): def test_FromSecondsObject(self): from _testcapi import PyTime_FromSecondsObject @@ -896,6 +902,27 @@ class TestPyTime_t(unittest.TestCase): self.assertEqual(PyTime_AsSecondsDouble(nanoseconds), seconds) + @unittest.skipUnless(hasattr(_testcapi, 'PyTime_AsTimespec'), + 'need _testcapi.PyTime_AsTimespec') + def test_timespec(self): + from _testcapi import PyTime_AsTimespec + for ns, ts in ( + # nanoseconds + (0, (0, 0)), + (1, (0, 1)), + (-1, (-1, 999999999)), + + # seconds + (2 * SEC_TO_NS, (2, 0)), + (-3 * SEC_TO_NS, (-3, 0)), + + # seconds + nanoseconds + (1234567890, (1, 234567890)), + (-1234567890, (-2, 765432110)), + ): + with self.subTest(nanoseconds=ns, timespec=ts): + self.assertEqual(PyTime_AsTimespec(ns), ts) + if __name__ == "__main__": unittest.main() |