Skip to content

Commit 8661573

Browse files
bsipoczcsaluski
authored andcommitted
Merge pull request astropy#52 from astropy/dependabot/github_actions/dot-github/workflows/actions-9b6bb90773
Bump OpenAstronomy/github-actions-workflows from 1.15.0 to 1.16.0 in /.github/workflows in the actions group
2 parents 3efa963 + cc9b790 commit 8661573

5 files changed

+66
-2
lines changed

.github/workflows/ci_workflows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ concurrency:
1414

1515
jobs:
1616
tests:
17-
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@9f1f43251dde69da8613ea8e11144f05cdea41d5 # v1.15.0
17+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@8c0fde6f7e926df6ed7057255d29afa9c1ad5320 # v1.16.0
1818
with:
1919
envs: |
2020
- linux: codestyle
@@ -31,7 +31,7 @@ jobs:
3131
- linux: py312-test-devdeps
3232
publish:
3333
needs: tests
34-
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@9f1f43251dde69da8613ea8e11144f05cdea41d5 # v1.15.0
34+
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@8c0fde6f7e926df6ed7057255d29afa9c1ad5320 # v1.16.0
3535
with:
3636
test_extras: test
3737
test_command: pytest $GITHUB_WORKSPACE/tests; pytest --arraydiff $GITHUB_WORKSPACE/tests

pytest_arraydiff/plugin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,17 @@ def pytest_runtest_call(self, item):
309309

310310
# Find test name to use as plot name
311311
filename = compare.kwargs.get('filename', None)
312+
derive_classes = compare.kwargs.get('derive_classes', False)
313+
312314
if filename is None:
313315
if single_reference:
314316
filename = item.originalname + '.' + extension
317+
elif derive_classes:
318+
filename = test_name
319+
filename = filename.replace('.', '_')
320+
filename = filename + '.' + extension
321+
filename = filename.replace('[', '_').replace(']', '_')
322+
filename = filename.replace('_.' + extension, '.' + extension)
315323
else:
316324
filename = item.name + '.' + extension
317325
filename = filename.replace('[', '_').replace(']', '_')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
0 1 2 3
2+
4 5 6 7
3+
8 9 10 11
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0 1 2 3 4
2+
5 6 7 8 9

tests/test_pytest_arraydiff.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,54 @@ def test_single_reference(self, spam):
176176

177177
def test_nofile():
178178
pass
179+
180+
class BaseTestClass:
181+
arrays = None
182+
@pytest.mark.array_compare(reference_dir=reference_dir, file_format='text', derive_classes=True)
183+
def test_array_one(self):
184+
return self.array
185+
class TestDerivedOne(BaseTestClass):
186+
array = np.arange(3 * 4).reshape((3, 4))
187+
188+
class TestDerivedTwo(BaseTestClass):
189+
array = np.arange(2 * 5).reshape((2, 5))
190+
191+
192+
193+
DERIVED_FAILING = """
194+
import pytest
195+
import numpy as np
196+
class BaseTestClass:
197+
arrays = None
198+
@pytest.mark.array_compare(reference_dir="{reference_dir}", file_format='text')
199+
def test_array_one(self):
200+
return self.array
201+
class TestDerivedOne(BaseTestClass):
202+
array = np.arange(3 * 4).reshape((3, 4))
203+
204+
class TestDerivedTwo(BaseTestClass):
205+
array = np.arange(2 * 5).reshape((2, 5))
206+
"""
207+
208+
209+
def test_derived_fails():
210+
211+
tmpdir = tempfile.mkdtemp()
212+
213+
test_file = os.path.join(tmpdir, 'test.py')
214+
gen_dir = os.path.join(tmpdir, 'spam', 'egg')
215+
with open(test_file, 'w') as f:
216+
f.write(DERIVED_FAILING.format(reference_dir=gen_dir))
217+
218+
# If we use --arraydiff, it should detect that the file is missing
219+
code = subprocess.call(f'pytest --arraydiff {test_file}', shell=True)
220+
assert code != 0
221+
222+
# when we generate the test files without the derive option the test should succeed
223+
code = subprocess.call(['pytest', f'--arraydiff-generate-path={gen_dir}', test_file],
224+
timeout=10)
225+
assert code == 0
226+
227+
# but when the test is run again, it should fail
228+
code = subprocess.call(f'pytest --arraydiff {test_file}', shell=True)
229+
assert code != 0

0 commit comments

Comments
 (0)