Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_diff_for_humans():
with pendulum.test(pendulum.datetime(2016, 8, 29)):
diff_for_humans()
def test_diff_for_humans_other_and_months():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "2 months before" == pendulum.now().diff_for_humans(
pendulum.now().add(months=2)
)
def test_from_format(text, fmt, expected):
with pendulum.test(pendulum.create(2015, 11, 12)):
assert pendulum.from_format(text, fmt, formatter='alternative').isoformat() == expected
def test_diff_for_humans_absolute_years():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "1 year" == pendulum.now().diff_for_humans(
pendulum.now().subtract(years=1), True
)
assert "1 year" == pendulum.now().diff_for_humans(
pendulum.now().add(years=1), True
)
def test_diff_for_humans_now_and_future_years():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "in 2 years" == pendulum.now().add(years=2).diff_for_humans()
def test_diff_for_humans_now_and_hour():
with pendulum.test(pendulum.today().at(12, 34, 56)):
now = pendulum.now().time()
assert now.subtract(hours=1).diff_for_humans() == "1 hour ago"
def test_diff_for_humans_other_and_future_seconds():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "a few seconds after" == pendulum.now().diff_for_humans(
pendulum.now().subtract(seconds=2)
)
def test_diff_for_humans_now_and_month():
with pendulum.test(pendulum.datetime(2016, 3, 1)):
today = pendulum.today().date()
assert "4 weeks ago" == today.subtract(weeks=4).diff_for_humans()
assert "1 month ago" == today.subtract(months=1).diff_for_humans()
with pendulum.test(pendulum.datetime(2017, 2, 28)):
today = pendulum.today().date()
assert "1 month ago" == today.subtract(weeks=4).diff_for_humans()
def test_diff_for_humans_absolute_weeks():
with pendulum.test(pendulum.datetime(2012, 1, 1, 1, 2, 3)):
assert "2 weeks" == pendulum.now().diff_for_humans(
pendulum.now().subtract(weeks=2), True
)
assert "2 weeks" == pendulum.now().diff_for_humans(
pendulum.now().add(weeks=2), True
)