How to use the pendulum.test function in pendulum

To help you get started, we’ve selected a few pendulum examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sdispater / pendulum / tests / localization / test_de.py View on Github external
def test_diff_for_humans():
    with pendulum.test(pendulum.datetime(2016, 8, 29)):
        diff_for_humans()
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
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)
        )
github sdispater / pendulum / tests / pendulum_tests / test_create_from_format.py View on Github external
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
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
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
        )
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
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()
github sdispater / pendulum / tests / time / test_diff.py View on Github external
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"
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
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)
        )
github sdispater / pendulum / tests / date / test_diff.py View on Github external
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()
github sdispater / pendulum / tests / datetime / test_diff.py View on Github external
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
        )