Skip to content

Commit 59b8cb6

Browse files
authored
Merge pull request astropy#11 from mwcraig/make-tests-sensible
Move test files and add test
2 parents 60fe008 + 0ef6aa1 commit 59b8cb6

File tree

5 files changed

+95
-4
lines changed

5 files changed

+95
-4
lines changed

.github/workflows/run_tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
# Weekly Friday 5AM build
8+
# * is a special character in YAML so you have to quote this string
9+
- cron: '0 5 * * 5'
10+
11+
jobs:
12+
tests:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
os: [ubuntu-latest]
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
- name: Set up Python
22+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 # v5.5.0
23+
with:
24+
python-version: '3.13'
25+
- name: Install and build
26+
run: python -m pip install .[test]
27+
- name: Run tests
28+
run: pytest tests

pyproject.toml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,25 @@ classifiers = [
2020
"Programming Language :: Python :: 3.13",
2121
"Programming Language :: Python :: Implementation :: CPython",
2222
]
23-
dependencies = []
23+
dependencies = [
24+
"astropy",
25+
"numpy",
26+
]
27+
28+
[project.optional-dependencies]
29+
docs = [
30+
"sphinx",
31+
"sphinx-astropy[confv2]",
32+
"sphinx-design",
33+
"graphviz",
34+
]
35+
test = [
36+
"black",
37+
"pre-commit",
38+
"pytest-astropy",
39+
"ruff",
40+
"tox",
41+
]
2442

2543
[project.urls]
2644
Documentation = "https://github.com/astropy/astro-image-display-api#readme"

src/astro_image_display_api/interface_definition.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def save(self, filename: str | os.PathLike, overwrite: bool = False) -> None:
119119

120120
# Marker-related methods
121121
@abstractmethod
122-
def start_marking(self, marker_name: str | None = None) -> None:
122+
def start_marking(self, marker_name: str | None = None, marker: Any = None) -> None:
123123
"""
124124
Start interactive marking of points on the image.
125125
@@ -128,6 +128,10 @@ def start_marking(self, marker_name: str | None = None) -> None:
128128
marker_name : str, optional
129129
The name of the marker set to use. If not given, a unique
130130
name will be generated.
131+
132+
marker : Any, optional
133+
The marker to use. If not given, a default marker will be
134+
used.
131135
"""
132136
raise NotImplementedError
133137

@@ -258,13 +262,13 @@ def offset_by(self, dx: float | Quantity, dy: float | Quantity) -> None:
258262
raise NotImplementedError
259263

260264
@abstractmethod
261-
def zoom(self) -> None:
265+
def zoom(self, val: float) -> None:
262266
"""
263267
Zoom in or out by the given factor.
264268
265269
Parameters
266270
----------
267-
val : int
271+
val : float
268272
The zoom level to zoom the image.
269273
See `zoom_level`.
270274
"""

tests/widget_api_test.py renamed to src/astro_image_display_api/widget_api_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from astropy import units as u # noqa: E402
1313
from astropy.wcs import WCS # noqa: E402
1414

15+
__all__ = ['ImageWidgetAPITest']
16+
1517

1618
class ImageWidgetAPITest:
1719
cursor_error_classes = (ValueError)
@@ -52,6 +54,11 @@ def _check_marker_table_return_properties(self, table):
5254
assert len(table) == 0
5355
assert sorted(table.colnames) == sorted(['x', 'y', 'coord', 'marker name'])
5456

57+
def test_default_marker_names(self):
58+
# Check only that default names are set to a non-empty string
59+
assert self.image.DEFAULT_MARKER_NAME
60+
assert self.image.DEFAULT_INTERACTIVE_MARKER_NAME
61+
5562
def test_width_height(self):
5663
assert self.image.image_width == 250
5764
assert self.image.image_height == 100
@@ -314,6 +321,9 @@ def test_adding_markers_as_world(self, data, wcs):
314321
mark_coord_table['coord'].dec.deg)
315322

316323
def test_stretch(self):
324+
# Check that the stretch options is not an empty list
325+
assert len(self.image.stretch_options) > 0
326+
317327
original_stretch = self.image.stretch
318328

319329
with pytest.raises(ValueError, match='must be one of'):
@@ -403,12 +413,14 @@ def test_scroll_pan(self):
403413
def test_save(self, tmp_path):
404414
filename = tmp_path / 'woot.png'
405415
self.image.save(filename)
416+
assert filename.is_file()
406417

407418
def test_save_overwrite(self, tmp_path):
408419
filename = tmp_path / 'woot.png'
409420

410421
# First write should be fine
411422
self.image.save(filename)
423+
assert filename.is_file()
412424

413425
# Second write should raise an error because file exists
414426
with pytest.raises(FileExistsError):
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from astropy.utils.data import get_pkg_data_contents
2+
3+
from astro_image_display_api.interface_definition import ImageViewerInterface
4+
5+
6+
def test_api_test_class_completeness():
7+
"""
8+
Test that the ImageWidgetAPITest class is complete and has tests
9+
for all of the required methods and attributes.
10+
"""
11+
# Get the attributes on the protocol
12+
required_attributes = ImageViewerInterface.__protocol_attrs__
13+
14+
# Get the text of the api tests
15+
widget_api_test_content = get_pkg_data_contents("widget_api_test.py", package="astro_image_display_api")
16+
# Loop over the attributes and check that the test class has a method
17+
# for each one whose name starts with test_ and ends with the attribute
18+
# name.
19+
attr_present = []
20+
image_viewer_name = "self.image"
21+
for attr in required_attributes:
22+
attr_present.append(f"{image_viewer_name}.{attr}" in widget_api_test_content)
23+
24+
25+
26+
assert all(attr_present), (
27+
"ImageWidgetAPITest does not access these attributes/methods:\n "
28+
f"{"\n".join(attr for attr, present in zip(required_attributes, attr_present) if not present)}. "
29+
)

0 commit comments

Comments
 (0)