Skip to content

Commit def8113

Browse files
committed
Add GHA to run canary tests; add a canary test for PRISM.
1 parent c80fdd1 commit def8113

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

.github/workflows/canary-test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Runs automated canary tests
2+
3+
# These tests perform minimal checks to validate that our integration with an external
4+
# service is still valid. We want these tests to be as small as possible and rare so that we
5+
# minimize excess traffic on our partners. However we also don't want ADRIOs (for example)
6+
# to start failing without us noticing. So it's a trade-off.
7+
8+
name: Canary test
9+
10+
on:
11+
workflow_dispatch:
12+
schedule:
13+
- cron: "0 16 1 * *" # 1st of every month, 9AM Arizona
14+
15+
jobs:
16+
canary-test:
17+
name: Canary matrix
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Check out code
21+
uses: actions/checkout@v4
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v5
25+
with:
26+
enable-cache: true
27+
version: ${{ vars.UV_VERSION }}
28+
29+
- name: Set up Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version-file: ".python-version"
33+
34+
- name: Install dependencies
35+
run: uv sync --frozen --all-extras --dev
36+
37+
- name: Run canary tests
38+
run: uv run pytest tests/canary

tests/canary/prism_canary_test.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import random
2+
from datetime import date, timedelta
3+
4+
import numpy as np
5+
6+
from epymorph.adrio import prism
7+
from epymorph.kit import *
8+
9+
10+
def test_prism_data_source(monkeypatch):
11+
"""
12+
This canary test fetches one data file from PRISM just to quickly verify that our
13+
ADRIO implementation appears to be valid still. Naturally caching must be disabled
14+
for the duration of this test.
15+
16+
Because this still uses the full ADRIO processing, a test failure may be caused by
17+
issues not related to the fetching of data. You must rule out other causes by
18+
running the other PRISM tests, which focus on our logic's handling of the data.
19+
(The other tests will use cached data to avoid excess stress on PRISM's servers.)
20+
"""
21+
monkeypatch.setenv("EPYMORPH_CACHE_DISABLED", "true")
22+
23+
# Pick a random day in 2020 to avoid hitting the same file repeatedly.
24+
# (2020 was a leap year, so it had 366 days.)
25+
random_date = date(2020, 1, 1) + timedelta(days=random.randint(0, 365)) # noqa: S311
26+
print(f"date_loaded: {random_date}") # noqa: T201
27+
28+
result = (
29+
prism.Temperature(temp_var="Minimum")
30+
.with_context(
31+
params={
32+
"centroid": np.array([(-112.0777, 33.4482)], dtype=CentroidDType),
33+
},
34+
scope=CustomScope(["PHX"]),
35+
time_frame=TimeFrame.range(random_date, random_date),
36+
)
37+
.evaluate()
38+
)
39+
assert result.shape == (1, 1)
40+
assert np.issubdtype(result.dtype, np.float64)
41+
assert result[0, 0] > 0

0 commit comments

Comments
 (0)