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

Method test_even_more_compare

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

Source from the content-addressed store, hash-verified

5060 self.assertEqual(dt.tzinfo, None)
5061
5062 def test_even_more_compare(self):
5063 # The test_compare() and test_more_compare() inherited from TestDate
5064 # and TestDateTime covered non-tzinfo cases.
5065
5066 # Smallest possible after UTC adjustment.
5067 t1 = self.theclass(1, 1, 1, tzinfo=FixedOffset(1439, ""))
5068 # Largest possible after UTC adjustment.
5069 t2 = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999999,
5070 tzinfo=FixedOffset(-1439, ""))
5071
5072 # Make sure those compare correctly, and w/o overflow.
5073 self.assertTrue(t1 < t2)
5074 self.assertTrue(t1 != t2)
5075 self.assertTrue(t2 > t1)
5076
5077 self.assertEqual(t1, t1)
5078 self.assertEqual(t2, t2)
5079
5080 # Equal after adjustment.
5081 t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""))
5082 t2 = self.theclass(2, 1, 1, 3, 13, tzinfo=FixedOffset(3*60+13+2, ""))
5083 self.assertEqual(t1, t2)
5084
5085 # Change t1 not to subtract a minute, and t1 should be larger.
5086 t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(0, ""))
5087 self.assertTrue(t1 > t2)
5088
5089 # Change t1 to subtract 2 minutes, and t1 should be smaller.
5090 t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(2, ""))
5091 self.assertTrue(t1 < t2)
5092
5093 # Back to the original t1, but make seconds resolve it.
5094 t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""),
5095 second=1)
5096 self.assertTrue(t1 > t2)
5097
5098 # Likewise, but make microseconds resolve it.
5099 t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""),
5100 microsecond=1)
5101 self.assertTrue(t1 > t2)
5102
5103 # Make t2 naive and it should differ.
5104 t2 = self.theclass.min
5105 self.assertNotEqual(t1, t2)
5106 self.assertEqual(t2, t2)
5107 # and > comparison should fail
5108 with self.assertRaises(TypeError):
5109 t1 > t2
5110
5111 # It's also naive if it has tzinfo but tzinfo.utcoffset() is None.
5112 class Naive(tzinfo):
5113 def utcoffset(self, dt): return None
5114 t2 = self.theclass(5, 6, 7, tzinfo=Naive())
5115 self.assertNotEqual(t1, t2)
5116 self.assertEqual(t2, t2)
5117
5118 # OTOH, it's OK to compare two of these mixing the two ways of being
5119 # naive.

Callers

nothing calls this directly

Calls 7

FixedOffsetClass · 0.85
NaiveClass · 0.85
assertTrueMethod · 0.80
assertNotEqualMethod · 0.80
BogusClass · 0.70
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected