Skip to content

Commit

Permalink
Exit nicely when invalid survey is requested for SkyView contour plot (
Browse files Browse the repository at this point in the history
…#497)

* Initial fix

* Add exception test

* Updated changelog

* PEP8

* PEP8
  • Loading branch information
ddobie authored Sep 23, 2023
1 parent e54a09c commit 4c2564d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

#### Changed

- Exit nicely when invalid survey is requested for SkyView contour plot [#497](https://github.com/askap-vast/vast-tools/pull/497)
#### Fixed

#### Removed

#### List of PRs

- [#497](https://github.com/askap-vast/vast-tools/pull/497): feat: Exit nicely when invalid survey is requested for SkyView contour plot

## [3.0.0](https://github.com/askap-vast/vast-tools/releases/v3.0.0) (2023-09-02)

Expand Down
36 changes: 35 additions & 1 deletion tests/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,11 +892,45 @@ def test_skyview_contour_plot(
return_value=[dummy_fits]
)

result = source.skyview_contour_plot(0, 'suveycode')
result = source.skyview_contour_plot(0, 'DSS2 Blue')

assert isinstance(result, Figure)
plt.close(result)

@pytest.mark.parametrize("pipeline", [False, True])
def test_skyview_contour_plot_survey_fail(
self,
pipeline: bool,
source_instance: vts.Source,
dummy_fits: fits.HDUList,
mocker: MockerFixture
) -> None:
"""
Tests the skyview_contour_plot method.
Parametrized for pipeline and query source.
Args:
pipeline: If 'True' then the Source is initialised as a
pipeline source.
source_instance: The pytest source_instance fixture.
dummy_fits: The pytest fixture dummy fits.
mocker: The pytest-mock mocker object.
Returns:
None
"""
source = source_instance(pipeline=pipeline, add_cutout_data=True)

mocker_skyview = mocker.patch(
'vasttools.source.SkyView.get_images',
return_value=[dummy_fits]
)
with pytest.raises(ValueError) as excinfo:
source.skyview_contour_plot(0, 'this-is-not-a-survey')

assert str(excinfo.value).endswith('not a valid SkyView survey name')

@pytest.mark.parametrize("pipeline", [False, True])
def test_write_ann(
self,
Expand Down
7 changes: 7 additions & 0 deletions vasttools/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,13 +1651,20 @@ def skyview_contour_plot(
Raises:
ValueError: If the index is out of range.
ValueError: If the requested survey is not valid.
"""

if (self._cutouts_got is False) or (force):
self.get_cutout_data(size)

size = self._size

surveys = list(SkyView.survey_dict.values())
survey_list = [item for sublist in surveys for item in sublist]

if survey not in survey_list:
raise ValueError(f"{survey} is not a valid SkyView survey name")

if index > len(self.measurements):
raise ValueError(f"Cannot access {index}th measurement.")
return
Expand Down

0 comments on commit 4c2564d

Please sign in to comment.