Skip to content

Commit

Permalink
more tests for dayname detection
Browse files Browse the repository at this point in the history
  • Loading branch information
geier committed Apr 14, 2024
1 parent e766c89 commit 4106678
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions tests/parse_datetime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,47 @@ def test_weekdaypstr_invalid():
weekdaypstr('foobar')


def test_construct_daynames():
with freeze_time('2016-9-19'):
assert construct_daynames(dt.date(2016, 9, 19), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Today'
assert construct_daynames(dt.date(2016, 9, 20), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Tomorrow'
assert construct_daynames(dt.date(2016, 9, 21), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Wednesday'

class TestConstructDayNames:
def test_construct_daynames(self):
with freeze_time('2016-9-19'):
assert construct_daynames(dt.date(2016, 9, 18), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Sunday'
assert construct_daynames(dt.date(2016, 9, 19), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Today'
assert construct_daynames(dt.date(2016, 9, 20), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Tomorrow'
assert construct_daynames(dt.date(2016, 9, 21), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Wednesday'

# freeztime freezes to UTC but construct_daynames should give as back the
# daynames relative the the user's local timezone
def test_construct_daynames_with_datetime(self):
with freeze_time('2016-9-19 22:53'):
assert construct_daynames(dt.date(2016, 9, 18), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Sunday'
assert construct_daynames(dt.date(2016, 9, 19), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Monday'
assert construct_daynames(dt.date(2016, 9, 20), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Today'
assert construct_daynames(dt.date(2016, 9, 21), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Tomorrow'
assert construct_daynames(dt.date(2016, 9, 22), local_timezone=LOCALE_BERLIN['local_timezone']) == 'Thursday'

def test_construct_daynames_los_angeles(self):
with freeze_time('2016-9-19 22:53'):
assert construct_daynames(dt.date(2016, 9, 18), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Sunday'
assert construct_daynames(dt.date(2016, 9, 19), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Today'
assert construct_daynames(dt.date(2016, 9, 20), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Tomorrow'
assert construct_daynames(dt.date(2016, 9, 21), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Wednesday'
assert construct_daynames(dt.date(2016, 9, 22), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Thursday'

def test_construct_daynames_los_angeles_morning(self):
with freeze_time('2016-9-19 06:30'):
assert construct_daynames(dt.date(2016, 9, 18), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Today'
assert construct_daynames(dt.date(2016, 9, 19), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Tomorrow'
assert construct_daynames(dt.date(2016, 9, 20), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Tuesday'
assert construct_daynames(dt.date(2016, 9, 21), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Wednesday'
assert construct_daynames(dt.date(2016, 9, 22), local_timezone=pytz.timezone('America/Los_Angeles')) == 'Thursday'

def test_construct_daynames_auckland(self):
with freeze_time('2016-9-19 22:53'):
assert construct_daynames(dt.date(2016, 9, 18), local_timezone=pytz.timezone('Pacific/Auckland')) == 'Sunday'
assert construct_daynames(dt.date(2016, 9, 19), local_timezone=pytz.timezone('Pacific/Auckland')) == 'Monday'
assert construct_daynames(dt.date(2016, 9, 20), local_timezone=pytz.timezone('Pacific/Auckland')) == 'Today'
assert construct_daynames(dt.date(2016, 9, 21), local_timezone=pytz.timezone('Pacific/Auckland')) == 'Tomorrow'
assert construct_daynames(dt.date(2016, 9, 22), local_timezone=pytz.timezone('Pacific/Auckland')) == 'Thursday'

class TestGuessDatetimefstr:

Expand Down

0 comments on commit 4106678

Please sign in to comment.