Skip to content

Commit

Permalink
Override timezone in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acarapetis committed Jul 31, 2024
1 parent 3c3743f commit baaef93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: pip install -e .[test]
- name: Run tests
run: python -m pytest
env:
TZ: AUS Eastern Standard Time
15 changes: 15 additions & 0 deletions tests/test_renamer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import time
from shroudstone.renamer import Replay, new_name_for
from tests.conftest import ReplayCase

Expand All @@ -6,6 +8,19 @@
"{time:%Y-%m-%d %H.%M} {duration} {players_with_factions} - {map_name}.SGReplay"
)

# Since we have to resort to getting replay timestamps from the *local time*
# in the filename, shroudstone's behaviour is dependent upon the system timezone.
# Thus for the purposes of a consistent test suite we override TZ.
if os.environ.get("TZ") not in ("Australia/Melbourne", "AUS Eastern Standard Time"):
if hasattr(time, "tzset"):
os.environ["TZ"] = "Australia/Melbourne"
time.tzset()
else:
raise RuntimeError(
"Incorrect timezone set and tzset is not available, "
"so tests would fail. Please set TZ=Australia/Melbourne to run the tests on Windows."
)


def test_replay_renaming(replay_case: ReplayCase, request):
replay = Replay.from_path(replay_case.replay_file)
Expand Down

0 comments on commit baaef93

Please sign in to comment.