diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 33bc7d1..71dcaf9 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,3 +20,5 @@ jobs: run: pip install -e .[test] - name: Run tests run: python -m pytest + env: + TZ: AUS Eastern Standard Time diff --git a/tests/test_renamer.py b/tests/test_renamer.py index 85a03bf..5e10a29 100644 --- a/tests/test_renamer.py +++ b/tests/test_renamer.py @@ -1,3 +1,5 @@ +import os +import time from shroudstone.renamer import Replay, new_name_for from tests.conftest import ReplayCase @@ -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)