MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_subclass_timedelta

Method test_subclass_timedelta

Lib/test/datetimetester.py:907–936  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

905 self.assertFalse(timedelta(0))
906
907 def test_subclass_timedelta(self):
908
909 class T(timedelta):
910 @staticmethod
911 def from_td(td):
912 return T(td.days, td.seconds, td.microseconds)
913
914 def as_hours(self):
915 sum = (self.days * 24 +
916 self.seconds / 3600.0 +
917 self.microseconds / 3600e6)
918 return round(sum)
919
920 t1 = T(days=1)
921 self.assertIs(type(t1), T)
922 self.assertEqual(t1.as_hours(), 24)
923
924 t2 = T(days=-1, seconds=-3600)
925 self.assertIs(type(t2), T)
926 self.assertEqual(t2.as_hours(), -25)
927
928 t3 = t1 + t2
929 self.assertIs(type(t3), timedelta)
930 t4 = T.from_td(t3)
931 self.assertIs(type(t4), T)
932 self.assertEqual(t3.days, t4.days)
933 self.assertEqual(t3.seconds, t4.seconds)
934 self.assertEqual(t3.microseconds, t4.microseconds)
935 self.assertEqual(str(t3), str(t4))
936 self.assertEqual(t4.as_hours(), -1)
937
938 def test_subclass_date(self):
939 class DateSubclass(date):

Callers

nothing calls this directly

Calls 6

as_hoursMethod · 0.95
strFunction · 0.85
from_tdMethod · 0.80
TClass · 0.70
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected