Skip to content

Commit

Permalink
Merge pull request #289 from noamkush/support_issubclass
Browse files Browse the repository at this point in the history
Add support for issubclass
  • Loading branch information
boxed committed Feb 19, 2019
2 parents d4be006 + 70de2cf commit 9347d13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions freezegun/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ class FakeDateMeta(type):
def __instancecheck__(self, obj):
return isinstance(obj, real_date)

@classmethod
def __subclasscheck__(cls, subclass):
return issubclass(subclass, real_date)


def datetime_to_fakedatetime(datetime):
return FakeDatetime(datetime.year,
Expand Down Expand Up @@ -285,6 +289,10 @@ class FakeDatetimeMeta(FakeDateMeta):
def __instancecheck__(self, obj):
return isinstance(obj, real_datetime)

@classmethod
def __subclasscheck__(cls, subclass):
return issubclass(subclass, real_datetime)


class FakeDatetime(with_metaclass(FakeDatetimeMeta, real_datetime, FakeDate)):
def __new__(cls, *args, **kwargs):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_class_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def test_isinstance_works():
freezer.stop()


def test_issubclass_works():
real_date = datetime.date
real_datetime = datetime.datetime

freezer = freeze_time('2011-01-01')
freezer.start()
assert issubclass(real_date, datetime.date)
assert issubclass(real_datetime, datetime.datetime)
freezer.stop()


def test_fake_uses_real_when_ignored():
real_time_before = time.time()
with freeze_time('2012-01-14', ignore=['tests.fake_module']):
Expand Down

0 comments on commit 9347d13

Please sign in to comment.