Skip to content

Commit

Permalink
Add ability to omit start date during contract initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
realsuayip committed Jan 19, 2024
1 parent fced377 commit e2ee0c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pcontract/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __getitem__(self, item: int) -> Branch:
def init(
cls,
*,
start_at: datetime | None,
start_at: datetime | None = None,
end_at: datetime,
data: dict[str, Any],
meta: dict[str, Any] | None = None,
Expand Down
11 changes: 11 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,14 @@ def test_contract_init_spans_nothing(self):
end_at=self.start - datetime.timedelta(days=1),
data={"key": "venus"},
)

def test_contract_init_without_start_date(self):
delta = datetime.timedelta(hours=1)
contract = Contract.init(data={}, end_at=datetime.datetime.now(tz=utc) + delta)
(branch,) = contract.items
# get away from adding freezegun
self.assertAlmostEqual(
delta.total_seconds(),
branch.span.total_seconds(),
places=5,
)

0 comments on commit e2ee0c5

Please sign in to comment.