Skip to content

Tests compare against Home Assistant's date, and 1.15.1 - #18

Merged
AboveColin merged 1 commit into
mainfrom
fix/test-dates
Sep 23, 2026
Merged

AboveColin merged 1 commit into
mainfrom
fix/test-dates

Conversation

@AboveColin

Copy link
Copy Markdown
Owner

Three usage tests failed every day between midnight UTC and midnight in US/Pacific. This fixes the tests and releases 1.15.1. The integration code does not change.

Cause

tests/test_ai_task.py and tests/test_init.py built the expected day with date.today(), which is the system date. The integration uses Home Assistant's clock, and the test harness sets it to US/Pacific. When the two dates differ, the tests fail:

  • test_what_the_task_spends_lands_in_the_day_s_usage: date(2026, 9, 22) == date(2026, 9, 23) fails.
  • test_yesterdays_total_does_not_count_against_today: '101' == '2' fails. The stored "yesterday" was today for Home Assistant.
  • test_a_spent_budget_skips_the_probe_and_still_says_so.

The tests now use dt_util.now().date().

Gate

Run at 05:30 in Europe/Amsterdam, inside the window where main fails.

Check main this branch
test_ai_task.py + test_init.py, TZ=Europe/Amsterdam 3 failed 67 passed
same, TZ=UTC 3 failed 67 passed
same, TZ=America/Los_Angeles 67 passed 67 passed
same, TZ=Pacific/Kiritimati not run 67 passed
ruff check, ruff format --check pass
mypy --strict no issues in 20 source files
pytest 407 passed, 12 skipped, 97% coverage, config_flow.py 100%
mkdocs build --strict, hassfest pass, 0 invalid integrations

Three usage tests built their expected day with date.today(). The integration and the test harness use Home Assistant's clock, which pytest-homeassistant-custom-component sets to US/Pacific. Between midnight UTC and midnight in US/Pacific the two dates differ, and the tests failed. They now use dt_util.now().date(). The same 67 tests pass with TZ set to Europe/Amsterdam, UTC, America/Los_Angeles and Pacific/Kiritimati.

Version 1.15.1. The integration code does not change.
@AboveColin
AboveColin merged commit 661eb43 into main Sep 23, 2026
12 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.

1 participant