Пример #1
0
 def test_to_timestamp(self):
     """Happy path to test converter from TimeSpan to timedelta."""
     # Test hours, minutes and seconds
     assert to_timedelta("00:00:00") == timedelta(seconds=0)
     assert to_timedelta("00:00:03") == timedelta(seconds=3)
     assert to_timedelta("00:04:03") == timedelta(minutes=4, seconds=3)
     assert to_timedelta("02:04:03") == timedelta(hours=2,
                                                  minutes=4,
                                                  seconds=3)
     # Test milliseconds
     assert to_timedelta("00:00:00.099") == timedelta(milliseconds=99)
     assert to_timedelta("02:04:03.0123") == timedelta(hours=2,
                                                       minutes=4,
                                                       seconds=3,
                                                       microseconds=12300)
     # Test days
     assert to_timedelta("01.00:00:00") == timedelta(days=1)
     assert to_timedelta("02.04:05:07") == timedelta(days=2,
                                                     hours=4,
                                                     minutes=5,
                                                     seconds=7)
     # Test negative
     assert to_timedelta("-01.00:00:00") == -timedelta(days=1)
     assert to_timedelta("-02.04:05:07") == -timedelta(
         days=2, hours=4, minutes=5, seconds=7)
     # Test all together
     assert to_timedelta("00.00:00:00.000") == timedelta(seconds=0)
     assert to_timedelta("02.04:05:07.789") == timedelta(days=2,
                                                         hours=4,
                                                         minutes=5,
                                                         seconds=7,
                                                         milliseconds=789)
     assert to_timedelta("03.00:00:00.111") == timedelta(days=3,
                                                         milliseconds=111)
     # Test from Ticks
     assert to_timedelta(-80080008) == timedelta(microseconds=-8008001)
     assert to_timedelta(10010001) == timedelta(microseconds=1001000)
 def test_to_timestamp(self):
     """Happy path to test converter from TimeSpan to timedelta."""
     # Test None
     self.assertIsNone(to_timedelta(None))
     # Test hours, minutes and seconds
     self.assertEqual(to_timedelta("00:00:00"), timedelta(seconds=0))
     self.assertEqual(to_timedelta("00:00:03"), timedelta(seconds=3))
     self.assertEqual(to_timedelta("00:04:03"),
                      timedelta(minutes=4, seconds=3))
     self.assertEqual(to_timedelta("02:04:03"),
                      timedelta(hours=2, minutes=4, seconds=3))
     # Test milliseconds
     self.assertEqual(to_timedelta("00:00:00.099"),
                      timedelta(milliseconds=99))
     self.assertEqual(
         to_timedelta("02:04:03.0123"),
         timedelta(hours=2, minutes=4, seconds=3, microseconds=12300))
     # Test days
     self.assertEqual(to_timedelta("01.00:00:00"), timedelta(days=1))
     self.assertEqual(to_timedelta("02.04:05:07"),
                      timedelta(days=2, hours=4, minutes=5, seconds=7))
     # Test negative
     self.assertEqual(to_timedelta("-01.00:00:00"), -timedelta(days=1))
     self.assertEqual(to_timedelta("-02.04:05:07"),
                      -timedelta(days=2, hours=4, minutes=5, seconds=7))
     # Test all together
     self.assertEqual(to_timedelta("00.00:00:00.000"), timedelta(seconds=0))
     self.assertEqual(
         to_timedelta("02.04:05:07.789"),
         timedelta(days=2, hours=4, minutes=5, seconds=7, milliseconds=789))
     self.assertEqual(to_timedelta("03.00:00:00.111"),
                      timedelta(days=3, milliseconds=111))
     # Test from Ticks
     self.assertEqual(to_timedelta(-80080008),
                      timedelta(microseconds=-8008001))
     self.assertEqual(to_timedelta(10010001),
                      timedelta(microseconds=1001000))