From e2e463d8f16db7eacabf39aa016a2068d5574c04 Mon Sep 17 00:00:00 2001 From: Duy Nguyen Date: Fri, 2 Aug 2024 10:17:03 -0400 Subject: [PATCH] Test organization, codestyle --- .../tests/test_vo_imviz.py | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/jdaviz/configs/default/plugins/virtual_observatory/tests/test_vo_imviz.py b/jdaviz/configs/default/plugins/virtual_observatory/tests/test_vo_imviz.py index c9e09369c4..84cc504bfc 100644 --- a/jdaviz/configs/default/plugins/virtual_observatory/tests/test_vo_imviz.py +++ b/jdaviz/configs/default/plugins/virtual_observatory/tests/test_vo_imviz.py @@ -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): @@ -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( @@ -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 - )