MCPcopy Index your code
hub / github.com/python/cpython / test_microsecond_rounding

Method test_microsecond_rounding

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

Source from the content-addressed store, hash-verified

865 self.assertRaises(OverflowError, day.__mul__, -INF)
866
867 def test_microsecond_rounding(self):
868 td = timedelta
869 eq = self.assertEqual
870
871 # Single-field rounding.
872 eq(td(milliseconds=0.4/1000), td(0)) # rounds to 0
873 eq(td(milliseconds=-0.4/1000), td(0)) # rounds to 0
874 eq(td(milliseconds=0.5/1000), td(microseconds=0))
875 eq(td(milliseconds=-0.5/1000), td(microseconds=-0))
876 eq(td(milliseconds=0.6/1000), td(microseconds=1))
877 eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
878 eq(td(milliseconds=1.5/1000), td(microseconds=2))
879 eq(td(milliseconds=-1.5/1000), td(microseconds=-2))
880 eq(td(seconds=0.5/10**6), td(microseconds=0))
881 eq(td(seconds=-0.5/10**6), td(microseconds=-0))
882 eq(td(seconds=1/2**7), td(microseconds=7812))
883 eq(td(seconds=-1/2**7), td(microseconds=-7812))
884
885 # Rounding due to contributions from more than one field.
886 us_per_hour = 3600e6
887 us_per_day = us_per_hour * 24
888 eq(td(days=.4/us_per_day), td(0))
889 eq(td(hours=.2/us_per_hour), td(0))
890 eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1))
891
892 eq(td(days=-.4/us_per_day), td(0))
893 eq(td(hours=-.2/us_per_hour), td(0))
894 eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1))
895
896 # Test for a patch in Issue 8860
897 eq(td(microseconds=0.5), 0.5*td(microseconds=1.0))
898 eq(td(microseconds=0.5)//td.resolution, 0.5*td.resolution//td.resolution)
899
900 def test_massive_normalization(self):
901 td = timedelta(microseconds=-1)

Callers

nothing calls this directly

Calls 1

eqFunction · 0.90

Tested by

no test coverage detected