Skip to content

Commit

Permalink
Improve error message and test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Sep 19, 2023
1 parent 44bc939 commit 6c5694a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/time_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def move_to(
def shift(self, delta: dt.timedelta | int | float) -> None:
if self.traveller is None:
raise RuntimeError(
"Initialize with `move_to()` first before using `shift()`"
"Initialize time_machine with move_to() before using shift()."
)
assert self.coordinates is not None
self.coordinates.shift(delta=delta)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_time_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,13 @@ def test_fixture_move_to_and_shift(time_machine):


def test_fixture_shift_without_move_to(time_machine):
with pytest.raises(RuntimeError):
with pytest.raises(RuntimeError) as excinfo:
time_machine.shift(100)

assert excinfo.value.args == (
"Initialize time_machine with move_to() before using shift().",
)


# escape hatch tests

Expand Down

0 comments on commit 6c5694a

Please sign in to comment.