(self)
| 4873 | self.assertEqual(dt.tzinfo, None) |
| 4874 | |
| 4875 | def test_even_more_compare(self): |
| 4876 | # The test_compare() and test_more_compare() inherited from TestDate |
| 4877 | # and TestDateTime covered non-tzinfo cases. |
| 4878 | |
| 4879 | # Smallest possible after UTC adjustment. |
| 4880 | t1 = self.theclass(1, 1, 1, tzinfo=FixedOffset(1439, "")) |
| 4881 | # Largest possible after UTC adjustment. |
| 4882 | t2 = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999999, |
| 4883 | tzinfo=FixedOffset(-1439, "")) |
| 4884 | |
| 4885 | # Make sure those compare correctly, and w/o overflow. |
| 4886 | self.assertTrue(t1 < t2) |
| 4887 | self.assertTrue(t1 != t2) |
| 4888 | self.assertTrue(t2 > t1) |
| 4889 | |
| 4890 | self.assertEqual(t1, t1) |
| 4891 | self.assertEqual(t2, t2) |
| 4892 | |
| 4893 | # Equal after adjustment. |
| 4894 | t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, "")) |
| 4895 | t2 = self.theclass(2, 1, 1, 3, 13, tzinfo=FixedOffset(3*60+13+2, "")) |
| 4896 | self.assertEqual(t1, t2) |
| 4897 | |
| 4898 | # Change t1 not to subtract a minute, and t1 should be larger. |
| 4899 | t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(0, "")) |
| 4900 | self.assertTrue(t1 > t2) |
| 4901 | |
| 4902 | # Change t1 to subtract 2 minutes, and t1 should be smaller. |
| 4903 | t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(2, "")) |
| 4904 | self.assertTrue(t1 < t2) |
| 4905 | |
| 4906 | # Back to the original t1, but make seconds resolve it. |
| 4907 | t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""), |
| 4908 | second=1) |
| 4909 | self.assertTrue(t1 > t2) |
| 4910 | |
| 4911 | # Likewise, but make microseconds resolve it. |
| 4912 | t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""), |
| 4913 | microsecond=1) |
| 4914 | self.assertTrue(t1 > t2) |
| 4915 | |
| 4916 | # Make t2 naive and it should differ. |
| 4917 | t2 = self.theclass.min |
| 4918 | self.assertNotEqual(t1, t2) |
| 4919 | self.assertEqual(t2, t2) |
| 4920 | # and > comparison should fail |
| 4921 | with self.assertRaises(TypeError): |
| 4922 | t1 > t2 |
| 4923 | |
| 4924 | # It's also naive if it has tzinfo but tzinfo.utcoffset() is None. |
| 4925 | class Naive(tzinfo): |
| 4926 | def utcoffset(self, dt): return None |
| 4927 | t2 = self.theclass(5, 6, 7, tzinfo=Naive()) |
| 4928 | self.assertNotEqual(t1, t2) |
| 4929 | self.assertEqual(t2, t2) |
| 4930 | |
| 4931 | # OTOH, it's OK to compare two of these mixing the two ways of being |
| 4932 | # naive. |
nothing calls this directly
no test coverage detected