Skip to content

Commit 40afd30

Browse files
authored
Stateful tests with Dataset (#8658)
* Stateful tests with Dataset * Disable check_default_indexes when needed * Add Zarr roundtrip * Randomize dimension choice * Fix a bug * Add reset_index * Add stack, unstack * [revert] Disable Zarr till we control attrs strategy * Try making unique names * Share names strategy to ensure uniques? * cleanup * Try sharing strategies better * Fix endianness * Better swap_dims * More improvements * WIP * Drop duplicates before unstacking * Add reset_index * Better duplicate assumption * Move * Fix reset_index * Skip if hypothesis not installed * Better precondition around reset_index * Note * Try a bundle * Use unique_subset_of * Use Bundles more * Add index_variables strategy * Small improvement * fix * Use st.shared * Revert "Use st.shared" This reverts commit 50f6030. * fix unstacking * cleanup * WIP * Remove bundles * Fixes * Add hypothesis cache to CI * Prevent index variables with NaNs, infs * [revert] * Always save hypothesis cache * Expand dtypes * Add invariant check for #8646 * Add drop_dims * Add create_index to stack * Generalize a bit * limit number of indexes to stack * Fix endianness? * uniquify drop_dims * Avoid NaTs in index vars HypothesisWorks/hypothesis#3943 * Guard swap_dims * Revert "Add invariant check for #8646" This reverts commit 4a958dc. * Add drop_indexes * Add assign_coords * Fix max_period for pandas timedelta * Add xfailed test * Add notes * Skip timedelta indexes * to_zarr * small tweaks * Remove NaT assume * Revert "[revert]" This reverts commit 6a38e27. * Add hypothesis workflow * Swtich out * fix * Use st.builds * cleanup * Add initialize * review feedback
1 parent c5b90c5 commit 40afd30

File tree

7 files changed

+429
-3
lines changed

7 files changed

+429
-3
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ jobs:
3535
runs-on: "ubuntu-latest"
3636
needs: detect-ci-trigger
3737
if: needs.detect-ci-trigger.outputs.triggered == 'false'
38+
3839
defaults:
3940
run:
4041
shell: bash -l {0}
41-
4242
env:
4343
CONDA_ENV_FILE: ci/requirements/environment.yml
4444
PYTHON_VERSION: "3.11"
45-
4645
steps:
4746
- uses: actions/checkout@v4
4847
with:

.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ jobs:
127127
run: |
128128
python -c "import xarray"
129129
130+
- name: Restore cached hypothesis directory
131+
uses: actions/cache@v4
132+
with:
133+
path: .hypothesis/
134+
key: cache-hypothesis
135+
enableCrossOsArchive: true
136+
save-always: true
137+
130138
- name: Run tests
131139
run: python -m pytest -n 4
132140
--timeout 180

.github/workflows/hypothesis.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Slow Hypothesis CI
2+
on:
3+
push:
4+
branches:
5+
- "main"
6+
pull_request:
7+
branches:
8+
- "main"
9+
types: [opened, reopened, synchronize, labeled]
10+
workflow_dispatch: # allows you to trigger manually
11+
12+
jobs:
13+
detect-ci-trigger:
14+
name: detect ci trigger
15+
runs-on: ubuntu-latest
16+
if: |
17+
github.repository == 'pydata/xarray'
18+
&& (github.event_name == 'push' || github.event_name == 'pull_request')
19+
outputs:
20+
triggered: ${{ steps.detect-trigger.outputs.trigger-found }}
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 2
25+
- uses: xarray-contrib/ci-trigger@v1
26+
id: detect-trigger
27+
with:
28+
keyword: "[skip-ci]"
29+
30+
hypothesis:
31+
name: Slow Hypothesis Tests
32+
runs-on: "ubuntu-latest"
33+
needs: detect-ci-trigger
34+
if: |
35+
always()
36+
&& (
37+
(github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')
38+
|| needs.detect-ci-trigger.outputs.triggered == 'true'
39+
|| contains( github.event.pull_request.labels.*.name, 'run-slow-hypothesis')
40+
)
41+
defaults:
42+
run:
43+
shell: bash -l {0}
44+
45+
env:
46+
CONDA_ENV_FILE: ci/requirements/environment.yml
47+
PYTHON_VERSION: "3.12"
48+
49+
steps:
50+
- uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0 # Fetch all history for all branches and tags.
53+
54+
- name: set environment variables
55+
run: |
56+
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
57+
58+
- name: Setup micromamba
59+
uses: mamba-org/setup-micromamba@v1
60+
with:
61+
environment-file: ci/requirements/environment.yml
62+
environment-name: xarray-tests
63+
create-args: >-
64+
python=${{env.PYTHON_VERSION}}
65+
pytest-reportlog
66+
cache-environment: true
67+
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
68+
69+
- name: Install xarray
70+
run: |
71+
python -m pip install --no-deps -e .
72+
- name: Version info
73+
run: |
74+
conda info -a
75+
conda list
76+
python xarray/util/print_versions.py
77+
- name: Restore cached hypothesis directory
78+
uses: actions/cache@v4
79+
with:
80+
path: .hypothesis/
81+
key: cache-hypothesis
82+
enableCrossOsArchive: true
83+
save-always: true
84+
- name: Run slow Hypothesis tests
85+
if: success()
86+
id: status
87+
run: |
88+
python -m pytest --hypothesis-show-statistics --run-slow-hypothesis properties/*.py \
89+
--report-log output-${{ matrix.python-version }}-log.jsonl
90+
- name: Generate and publish the report
91+
if: |
92+
failure()
93+
&& steps.status.outcome == 'failure'
94+
&& github.event_name == 'schedule'
95+
&& github.repository_owner == 'pydata'
96+
uses: xarray-contrib/issue-from-pytest-log@v1
97+
with:
98+
log-path: output-${{ matrix.python-version }}-log.jsonl
99+
issue-title: "Nightly Hypothesis tests failed"
100+
issue-label: "topic-hypothesis"

properties/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption(
6+
"--run-slow-hypothesis",
7+
action="store_true",
8+
default=False,
9+
help="run slow hypothesis tests",
10+
)
11+
12+
13+
def pytest_collection_modifyitems(config, items):
14+
if config.getoption("--run-slow-hypothesis"):
15+
return
16+
skip_slow_hyp = pytest.mark.skip(reason="need --run-slow-hypothesis option to run")
17+
for item in items:
18+
if "slow_hypothesis" in item.keywords:
19+
item.add_marker(skip_slow_hyp)
20+
21+
122
try:
223
from hypothesis import settings
324
except ImportError:

0 commit comments

Comments
 (0)