| 4845 | |
| 4846 | |
| 4847 | class WeekdayTest(unittest.TestCase): |
| 4848 | def testInvalidNthWeekday(self): |
| 4849 | with self.assertRaises(ValueError): |
| 4850 | FR(0) |
| 4851 | |
| 4852 | def testWeekdayCallable(self): |
| 4853 | # Calling a weekday instance generates a new weekday instance with the |
| 4854 | # value of n changed. |
| 4855 | from dateutil.rrule import weekday |
| 4856 | self.assertEqual(MO(1), weekday(0, 1)) |
| 4857 | |
| 4858 | # Calling a weekday instance with the identical n returns the original |
| 4859 | # object |
| 4860 | FR_3 = weekday(4, 3) |
| 4861 | self.assertIs(FR_3(3), FR_3) |
| 4862 | |
| 4863 | def testWeekdayEquality(self): |
| 4864 | # Two weekday objects are not equal if they have different values for n |
| 4865 | self.assertNotEqual(TH, TH(-1)) |
| 4866 | self.assertNotEqual(SA(3), SA(2)) |
| 4867 | |
| 4868 | def testWeekdayEqualitySubclass(self): |
| 4869 | # Two weekday objects equal if their "weekday" and "n" attributes are |
| 4870 | # available and the same |
| 4871 | class BasicWeekday: |
| 4872 | def __init__(self, weekday): |
| 4873 | self.weekday = weekday |
| 4874 | |
| 4875 | class BasicNWeekday(BasicWeekday): |
| 4876 | def __init__(self, weekday, n=None): |
| 4877 | super().__init__(weekday) |
| 4878 | self.n = n |
| 4879 | |
| 4880 | MO_Basic = BasicWeekday(0) |
| 4881 | |
| 4882 | self.assertNotEqual(MO, MO_Basic) |
| 4883 | self.assertNotEqual(MO(1), MO_Basic) |
| 4884 | |
| 4885 | TU_BasicN = BasicNWeekday(1) |
| 4886 | |
| 4887 | self.assertEqual(TU, TU_BasicN) |
| 4888 | self.assertNotEqual(TU(3), TU_BasicN) |
| 4889 | |
| 4890 | WE_Basic3 = BasicNWeekday(2, 3) |
| 4891 | self.assertEqual(WE(3), WE_Basic3) |
| 4892 | self.assertNotEqual(WE(2), WE_Basic3) |
| 4893 | |
| 4894 | def testWeekdayReprNoN(self): |
| 4895 | no_n_reprs = ('MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU') |
| 4896 | no_n_wdays = (MO, TU, WE, TH, FR, SA, SU) |
| 4897 | |
| 4898 | for repstr, wday in zip(no_n_reprs, no_n_wdays): |
| 4899 | self.assertEqual(repr(wday), repstr) |
| 4900 | |
| 4901 | def testWeekdayReprWithN(self): |
| 4902 | with_n_reprs = ('WE(+1)', 'TH(-2)', 'SU(+3)') |
| 4903 | with_n_wdays = (WE(1), TH(-2), SU(+3)) |
| 4904 |
nothing calls this directly
no outgoing calls
no test coverage detected