Skip to content

Commit 0044fc0

Browse files
committed
Add unit test for as_calendar method
1 parent 8b3030b commit 0044fc0

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/undate/undate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def set_calendar(self, calendar: Union[str, Calendar]):
197197
to change calendar."""
198198
if calendar is not None:
199199
# if not passed as a Calendar instance, do a lookup
200-
if not isinstance(calendar, Calendar):
200+
if isinstance(calendar, str):
201201
# look for calendar by upper-case name
202202
try:
203203
calendar = Calendar[calendar.upper()]

tests/test_undate.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ def test_calendar(self):
130130
with pytest.raises(ValueError, match="Calendar `foobar` is not supported"):
131131
Undate(848, calendar="foobar")
132132

133+
def test_as_calendar(self):
134+
# changes calendar *without* converting dates
135+
assert Undate(1243, 5, 7).as_calendar(Calendar.ISLAMIC) == Undate(
136+
1243, 5, 7, calendar=Calendar.ISLAMIC
137+
)
138+
# should also work with string
139+
assert Undate(1243, 5, 7).as_calendar("islamic") == Undate(
140+
1243, 5, 7, calendar=Calendar.ISLAMIC
141+
)
142+
133143
def test_init_invalid(self):
134144
with pytest.raises(ValueError):
135145
Undate("19??")

0 commit comments

Comments
 (0)