File tree 3 files changed +13
-0
lines changed
3 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ def __repr__(self) -> str:
73
73
return "<UndateInterval %s>" % self
74
74
75
75
def __eq__ (self , other ) -> bool :
76
+ # currently doesn't support comparison with any other types
77
+ if not isinstance (other , UndateInterval ):
78
+ return NotImplemented
76
79
# consider interval equal if both dates are equal
77
80
return self .earliest == other .earliest and self .latest == other .latest
78
81
Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ def test_eq(self):
82
82
)
83
83
assert UndateInterval (Undate (2022 , 5 )) == UndateInterval (Undate (2022 , 5 ))
84
84
85
+ def test_eq_type_check (self ):
86
+ # doesn't currently support comparison with anything else
87
+ interval = UndateInterval (Undate (900 ))
88
+ # returns NotIplemented if comparison with this type is not supported
89
+ assert interval .__eq__ ("foo" ) == NotImplemented
90
+
85
91
def test_not_eq (self ):
86
92
assert UndateInterval (Undate (2022 ), Undate (2023 )) != UndateInterval (
87
93
Undate (2022 ), Undate (2024 )
Original file line number Diff line number Diff line change @@ -152,6 +152,10 @@ def test_to_undate(self):
152
152
assert isinstance (undate_from_dt , Undate )
153
153
assert undate_from_dt == Undate (now .year , now .month , now .day )
154
154
155
+ # unsupported type
156
+ with pytest .raises (TypeError ):
157
+ Undate .to_undate ("foo" )
158
+
155
159
# test properties for accessing parts of date
156
160
def test_year_property (self ):
157
161
# two, three, four five digit years; numeric and string
You can’t perform that action at this time.
0 commit comments