Skip to content

test: build test dates from Predbat's clock, not the machine's - #4877

Merged
springfall2008 merged 1 commit into
springfall2008:mainfrom
romain-intel:pr/fix-clock-tests
Sep 3, 2026
Merged

test: build test dates from Predbat's clock, not the machine's#4877
springfall2008 merged 1 commit into
springfall2008:mainfrom
romain-intel:pr/fix-clock-tests

Conversation

@romain-intel

Copy link
Copy Markdown
Contributor

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.

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>
@springfall2008
springfall2008 merged commit 9a63af4 into springfall2008:main Sep 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants