Skip to content

Commit

Permalink
More test coverage around strict and timedelta addition
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw296 committed Jun 16, 2023
1 parent 05c9c37 commit 544b436
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion testfixtures/tests/test_date.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date as d, timedelta
from datetime import date as d, timedelta, date
from time import strptime
from typing import cast, Type

Expand Down Expand Up @@ -300,3 +300,15 @@ def test_tick_with_timedelta_instance(self):
def test_old_import(self):
from testfixtures import test_date
assert test_date is mock_date

def test_add_timedelta_not_strict(self):
mock_class = mock_date()
value = mock_class.today() + timedelta(days=1)
assert isinstance(value, date)
assert type(value) is date

def test_add_timedelta_strict(self):
mock_class = mock_date(strict=True)
value = mock_class.today() + timedelta(days=1)
assert isinstance(value, date)
assert type(value) is mock_class
14 changes: 13 additions & 1 deletion testfixtures/tests/test_datetime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import date, datetime
from datetime import datetime as d
from datetime import timedelta
from datetime import tzinfo
Expand Down Expand Up @@ -433,3 +433,15 @@ def test_tick_with_timedelta_instance(self):
def test_old_import(self):
from testfixtures import test_datetime
assert test_datetime is mock_datetime

def test_add_timedelta_not_strict(self):
mock_class = mock_datetime()
value = mock_class.now() + timedelta(seconds=10)
assert isinstance(value, datetime)
assert type(value) is datetime

def test_add_timedelta_strict(self):
mock_class = mock_datetime(strict=True)
value = mock_class.now() + timedelta(seconds=10)
assert isinstance(value, datetime)
assert type(value) is mock_class

0 comments on commit 544b436

Please sign in to comment.