Skip to content

Commit

Permalink
Test organization, codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
duytnguyendtn committed Aug 2, 2024
1 parent d4f152a commit e2e463d
Showing 1 changed file with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,48 @@ def test_coverage_toggle(self, imviz_helper):
# Nonfiltered resources should be more than filtered resources
assert len(nonfiltered_resources) > len(filtered_resources)

def test_target_lookup_warnings(self, imviz_helper):
"""
Tests that appropriate errors and guardrails protect the user
when a provided source is irresolvable
"""
expected_error_msg = "Unable to resolve source coordinates"
vo_plugin = imviz_helper.plugins[vo_plugin_label]._obj

# Manually set the source to a fake target
vo_plugin.viewer_selected = "Manual"
vo_plugin.source = "ThisIsAFakeTargetThatWontResolveToAnything"
vo_plugin.radius = 1

# If we have coverage filtering on, we should get an error
vo_plugin.resource_filter_coverage = True
with pytest.raises(LookupError, match=expected_error_msg):
vo_plugin.waveband_selected = "optical"
vo_plugin.vue_query_registry_resources()
assert any(
expected_error_msg in d["text"]
for d in imviz_helper.app.state.snackbar_history
)
assert len(vo_plugin.resources) == 0

# By clearing coverage filtering, we should now be able to query the registry
# and return the full list of available resources:
vo_plugin.resource_filter_coverage = False
vo_plugin.vue_query_registry_resources()
assert len(vo_plugin.resources) > 0

# However, if we try to query a resource, we should be prevented
# since the source still isn't resolvable.
# Clear existing messages
imviz_helper.app.state.snackbar_history = []
vo_plugin.resource_selected = "HST.M51"
with pytest.raises(LookupError, match=expected_error_msg):
vo_plugin.vue_query_resource()
assert any(
expected_error_msg in d["text"]
for d in imviz_helper.app.state.snackbar_history
)

@pytest.mark.filterwarnings("ignore::astropy.wcs.wcs.FITSFixedWarning")
@pytest.mark.filterwarnings("ignore:Some non-standard WCS keywords were excluded")
def test_HSTM51_load_data(self, imviz_helper):
Expand Down Expand Up @@ -249,10 +291,10 @@ def test_HSTM51_load_data(self, imviz_helper):
vo_plugin._populate_table([fake_result])

# Put the fake result first to make sure we hit the fake result before the real one
vo_plugin.table.selected_rows = [vo_plugin.table.items[-1], vo_plugin.table.items[0]] # Select first entry
vo_plugin.table.selected_rows = [vo_plugin.table.items[-1], vo_plugin.table.items[0]]
assert vo_plugin.table.selected_rows[0]['URL'] == fake_result.getdataurl()

# Load first data product and fake result
# Load first data product and fake result
vo_plugin.vue_load_selected_data()
# Test that user was warned about failed file loading on fake result
assert any(
Expand Down Expand Up @@ -289,45 +331,3 @@ def test_HSTM51_load_data(self, imviz_helper):
"WCS linking is not enabled; data layers may not be aligned" not in d["text"]
for d in imviz_helper.app.state.snackbar_history
)

def test_target_lookup_warnings(self, imviz_helper):
"""
Tests that appropriate errors and guardrails protect the user
when a provided source is inresolvable
"""
expected_error_msg = "Unable to resolve source coordinates"
vo_plugin = imviz_helper.plugins[vo_plugin_label]._obj

# Manually set the source to a fake target
vo_plugin.viewer_selected = "Manual"
vo_plugin.source = "ThisIsAFakeTargetThatWontResolveToAnything"
vo_plugin.radius = 1

# If we have coverage filtering on, we should get an error
vo_plugin.resource_filter_coverage = True
with pytest.raises(LookupError, match=expected_error_msg):
vo_plugin.waveband_selected = "optical"
vo_plugin.vue_query_registry_resources()
assert any(
expected_error_msg in d["text"]
for d in imviz_helper.app.state.snackbar_history
)
assert len(vo_plugin.resources) == 0

# By clearing coverage filtering, we should now be able to query the registry
# and return the full list of available resources:
vo_plugin.resource_filter_coverage = False
vo_plugin.vue_query_registry_resources()
assert len(vo_plugin.resources) > 0

# However, if we try to query a resource, we should be prevented
# since the source still isn't resolvable.
# Clear existing messages
imviz_helper.app.state.snackbar_history = []
vo_plugin.resource_selected = "HST.M51"
with pytest.raises(LookupError, match=expected_error_msg):
vo_plugin.vue_query_resource()
assert any(
expected_error_msg in d["text"]
for d in imviz_helper.app.state.snackbar_history
)

0 comments on commit e2e463d

Please sign in to comment.