def test_AsTimespec(self): from _testcapi import PyTime_AsTimespec def timespec_converter(ns): return divmod(ns, SEC_TO_NS) self.check_int_rounding(lambda ns, rnd: PyTime_AsTimespec(ns), timespec_converter, NS_TO_SEC, value_filter=self.time_t_filter)
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)