test: build test dates from Predbat's clock, not the machine's - #4877
Open
romain-intel wants to merge 1 commit into
Open
test: build test dates from Predbat's clock, not the machine's#4877romain-intel wants to merge 1 commit into
romain-intel wants to merge 1 commit into
Conversation
test_saving_session and test_alert_feed construct their fixtures with datetime.now(), then assert
against what Predbat produced. Predbat is not on that clock: it runs on the timezone set in
apps.yaml, Europe/London in the test harness. When the machine sits in another zone the two are on
different dates for part of every day, and the tests fail for no reason connected to the code.
Running them under TZ=America/Los_Angeles at 21:30 local, which is 05:30 the next morning in London:
ERROR: Expecting ... 'Joined Octopus saving event Sun 30/08 18:30-19:30' got 'Mon 31/08 ...'
ERROR: Free slot - expecting 60 minutes at rate 0, got 0
ERROR: Expecting alert text to be 'Yellow wind warning until ...' got ''
The free-slot case is the clearest: load_free_slot() measures a slot against midnight_utc, so a
window built for the machine's "today" starts before Predbat's day began and is dropped entirely.
Dates now come from my_predbat.midnight_utc, which is the clock the code under test is using. No
production code changes and no assertions weakened - the same windows are still built, just anchored
to the right day.
Verified across TZ=America/Los_Angeles, Pacific/Auckland, Europe/London, UTC and America/New_York:
all pass after, and Los_Angeles fails before.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_saving_session and test_alert_feed construct their fixtures with datetime.now(), then assert against what Predbat produced. Predbat is not on that clock: it runs on the timezone set in apps.yaml, Europe/London in the test harness. When the machine sits in another zone the two are on different dates for part of every day, and the tests fail for no reason connected to the code.
Running them under TZ=America/Los_Angeles at 21:30 local, which is 05:30 the next morning in London:
The free-slot case is the clearest: load_free_slot() measures a slot against midnight_utc, so a window built for the machine's "today" starts before Predbat's day began and is dropped entirely.
Dates now come from my_predbat.midnight_utc, which is the clock the code under test is using. No production code changes and no assertions weakened - the same windows are still built, just anchored to the right day.
Verified across TZ=America/Los_Angeles, Pacific/Auckland, Europe/London, UTC and America/New_York: all pass after, and Los_Angeles fails before.