How to use the freezegun.api function in freezegun

To help you get started, we’ve selected a few freezegun 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 spulec / freezegun / tests / test_utils.py View on Github external
def test_should_not_skip_cpython():
    reload(api)
    reload(utils)
    function_mock = mock.MagicMock(__name__='function')
    try:
        utils.cpython_only(function_mock)()
    except SkipTest:
        raise AssertionError("Test was skipped in CPython")
    assert function_mock.called
github spulec / freezegun / tests / test_datetimes.py View on Github external
def test_should_use_real_time():
    frozen = datetime.datetime(2015, 3, 5)
    expected_frozen = 1425513600.0
    # TODO: local time seems to leak the local timezone, so this test fails in CI
    # expected_frozen_local = (2015, 3, 5, 1, 0, 0, 3, 64, -1)
    expected_frozen_gmt = (2015, 3, 5, 0, 0, 0, 3, 64, -1)
    expected_clock = 0

    from freezegun import api
    api.call_stack_inspection_limit = 100  # just to increase coverage

    current_time = time.gmtime()

    with freeze_time(frozen):
        assert time.time() == expected_frozen
        # assert time.localtime() == expected_frozen_local
        assert time.gmtime() == expected_frozen_gmt
        if HAS_CLOCK:
            assert time.clock() == expected_clock
        if HAS_TIME_NS:
            assert time.time_ns() == expected_frozen * 1e9

        assert calendar.timegm(current_time) == expected_frozen

    with freeze_time(frozen, ignore=['_pytest', 'nose']):
        assert time.time() != expected_frozen
github spulec / freezegun / tests / test_utils.py View on Github external
def test_should_skip_non_cpython():
    reload(api)
    reload(utils)
    function_mock = mock.MagicMock(__name__='function', skipped=False)
    try:
        utils.cpython_only(function_mock)()
    except SkipTest:
        function_mock.skipped = True
    assert not function_mock.called
    assert function_mock.skipped