def test_time_t(self): from _testcapi import pytime_object_to_time_t # Conversion giving the same result for all rounding methods for rnd in ALL_ROUNDING_METHODS: for obj, seconds in ( # int (-1, -1), (0, 0), (1, 1), # float (-1.0, -1), (1.0, 1), ): with self.subTest(obj=obj, round=rnd, seconds=seconds): self.assertEqual(pytime_object_to_time_t(obj, rnd), seconds) # Conversion giving different results depending on the rounding method FLOOR = _PyTime.ROUND_FLOOR CEILING = _PyTime.ROUND_CEILING HALF_UP = _PyTime.ROUND_HALF_UP for obj, time_t, rnd in ( (-1.9, -2, FLOOR), (-1.9, -1, CEILING), (-1.9, -2, HALF_UP), (1.9, 1, FLOOR), (1.9, 2, CEILING), (1.9, 2, HALF_UP), # half up (-0.999, -1, HALF_UP), (-0.510, -1, HALF_UP), (-0.500, -1, HALF_UP), (-0.490, 0, HALF_UP), ( 0.490, 0, HALF_UP), ( 0.500, 1, HALF_UP), ( 0.510, 1, HALF_UP), ( 0.999, 1, HALF_UP), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) # Test OverflowError rnd = _PyTime.ROUND_FLOOR for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid, rnd)
def test_time_t(self): from _testcapi import pytime_object_to_time_t # Conversion giving the same result for all rounding methods for rnd in ALL_ROUNDING_METHODS: for obj, seconds in ( # int (-1, -1), (0, 0), (1, 1), # float (-1.0, -1), (1.0, 1), ): with self.subTest(obj=obj, round=rnd, seconds=seconds): self.assertEqual(pytime_object_to_time_t(obj, rnd), seconds) # Conversion giving different results depending on the rounding method FLOOR = _PyTime.ROUND_FLOOR CEILING = _PyTime.ROUND_CEILING HALF_UP = _PyTime.ROUND_HALF_UP for obj, time_t, rnd in ( (-1.9, -2, FLOOR), (-1.9, -1, CEILING), (-1.9, -2, HALF_UP), (1.9, 1, FLOOR), (1.9, 2, CEILING), (1.9, 2, HALF_UP), # half up (-0.999, -1, HALF_UP), (-0.510, -1, HALF_UP), (-0.500, -1, HALF_UP), (-0.490, 0, HALF_UP), (0.490, 0, HALF_UP), (0.500, 1, HALF_UP), (0.510, 1, HALF_UP), (0.999, 1, HALF_UP), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) # Test OverflowError rnd = _PyTime.ROUND_FLOOR for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid, rnd)
def test_time_t(self): from _testcapi import pytime_object_to_time_t for obj, time_t in ((0, 0), (-1, -1), (-1.0, -1), (-1.9, -1), (1.0, 1), (1.9, 1)): self.assertEqual(pytime_object_to_time_t(obj), time_t) for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid)
def test_time_t(self): from _testcapi import pytime_object_to_time_t # Conversion giving the same result for all rounding methods for rnd in ALL_ROUNDING_METHODS: for obj, time_t in ( # int (0, 0), (-1, -1), # float (1.0, 1), (-1.0, -1), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) # Conversion giving different results depending on the rounding method FLOOR = _PyTime.ROUND_FLOOR CEILING = _PyTime.ROUND_CEILING HALF_EVEN = _PyTime.ROUND_HALF_EVEN for obj, time_t, rnd in ( (-1.9, -2, FLOOR), (-1.9, -2, HALF_EVEN), (-1.9, -1, CEILING), (1.9, 1, FLOOR), (1.9, 2, HALF_EVEN), (1.9, 2, CEILING), # half even (-1.5, -2, HALF_EVEN), (-0.9, -1, HALF_EVEN), (-0.5, 0, HALF_EVEN), ( 0.5, 0, HALF_EVEN), ( 0.9, 1, HALF_EVEN), ( 1.5, 2, HALF_EVEN), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) # Test OverflowError rnd = _PyTime.ROUND_FLOOR for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid, rnd)
def test_time_t(self): from _testcapi import pytime_object_to_time_t for obj, time_t in ( (0, 0), (-1, -1), (-1.0, -1), (-1.9, -1), (1.0, 1), (1.9, 1), ): self.assertEqual(pytime_object_to_time_t(obj), time_t) for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid)
def test_time_t(self): from _testcapi import pytime_object_to_time_t for obj, time_t, rnd in ( # Round towards minus infinity (-inf) (0, 0, _PyTime.ROUND_FLOOR), (-1, -1, _PyTime.ROUND_FLOOR), (-1.0, -1, _PyTime.ROUND_FLOOR), (-1.9, -2, _PyTime.ROUND_FLOOR), (1.0, 1, _PyTime.ROUND_FLOOR), (1.9, 1, _PyTime.ROUND_FLOOR), # Round towards infinity (+inf) (0, 0, _PyTime.ROUND_CEILING), (-1, -1, _PyTime.ROUND_CEILING), (-1.0, -1, _PyTime.ROUND_CEILING), (-1.9, -1, _PyTime.ROUND_CEILING), (1.0, 1, _PyTime.ROUND_CEILING), (1.9, 2, _PyTime.ROUND_CEILING), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) rnd = _PyTime.ROUND_FLOOR for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid, rnd)
def test_time_t(self): from _testcapi import pytime_object_to_time_t for obj, time_t, rnd in ( # Round towards zero (0, 0, _PyTime_ROUND_DOWN), (-1, -1, _PyTime_ROUND_DOWN), (-1.0, -1, _PyTime_ROUND_DOWN), (-1.9, -1, _PyTime_ROUND_DOWN), (1.0, 1, _PyTime_ROUND_DOWN), (1.9, 1, _PyTime_ROUND_DOWN), # Round away from zero (0, 0, _PyTime_ROUND_UP), (-1, -1, _PyTime_ROUND_UP), (-1.0, -1, _PyTime_ROUND_UP), (-1.9, -2, _PyTime_ROUND_UP), (1.0, 1, _PyTime_ROUND_UP), (1.9, 2, _PyTime_ROUND_UP), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) rnd = _PyTime_ROUND_DOWN for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid, rnd)
def test_time_t(self): from _testcapi import pytime_object_to_time_t for obj, time_t, rnd in ( # Round towards zero (0, 0, _PyTime.ROUND_DOWN), (-1, -1, _PyTime.ROUND_DOWN), (-1.0, -1, _PyTime.ROUND_DOWN), (-1.9, -1, _PyTime.ROUND_DOWN), (1.0, 1, _PyTime.ROUND_DOWN), (1.9, 1, _PyTime.ROUND_DOWN), # Round away from zero (0, 0, _PyTime.ROUND_UP), (-1, -1, _PyTime.ROUND_UP), (-1.0, -1, _PyTime.ROUND_UP), (-1.9, -2, _PyTime.ROUND_UP), (1.0, 1, _PyTime.ROUND_UP), (1.9, 2, _PyTime.ROUND_UP), ): self.assertEqual(pytime_object_to_time_t(obj, rnd), time_t) rnd = _PyTime.ROUND_DOWN for invalid in self.invalid_values: self.assertRaises(OverflowError, pytime_object_to_time_t, invalid, rnd)