Skip to content

Commit

Permalink
Use Freezegun in test_format_current_moment
Browse files Browse the repository at this point in the history
The earlier patch resulted in `unsupported operand type(s) for -: 'datetime' and 'datetime'` on Pypy3.
  • Loading branch information
akx committed Nov 11, 2020
1 parent 61f0324 commit 000a767
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions tests/test_dates.py
Expand Up @@ -15,6 +15,7 @@
from datetime import date, datetime, time, timedelta
import unittest

import freezegun
import pytest
import pytz
from pytz import timezone
Expand Down Expand Up @@ -809,19 +810,10 @@ def test_zh_TW_format():
assert dates.format_time(datetime(2016, 4, 8, 12, 34, 56), locale='zh_TW') == u'\u4e0b\u534812:34:56'


def test_format_current_moment(monkeypatch):
import datetime as datetime_module
def test_format_current_moment():
frozen_instant = datetime.utcnow()

class frozen_datetime(datetime):

@classmethod
def utcnow(cls):
return frozen_instant

# Freeze time! Well, some of it anyway.
monkeypatch.setattr(datetime_module, "datetime", frozen_datetime)
assert dates.format_datetime(locale="en_US") == dates.format_datetime(frozen_instant, locale="en_US")
with freezegun.freeze_time(time_to_freeze=frozen_instant):
assert dates.format_datetime(locale="en_US") == dates.format_datetime(frozen_instant, locale="en_US")


@pytest.mark.all_locales
Expand Down

0 comments on commit 000a767

Please sign in to comment.