From ccb6eea3e27b761535236d9321f9f1a93042ac20 Mon Sep 17 00:00:00 2001 From: chrishavlin Date: Thu, 30 Nov 2023 14:12:01 -0600 Subject: [PATCH] fix coverage, use tmp_path fixture --- src/yt_napari/_tests/test_widget_reader.py | 18 ++++++++---------- src/yt_napari/_widget_reader.py | 4 +++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/yt_napari/_tests/test_widget_reader.py b/src/yt_napari/_tests/test_widget_reader.py index 8b51597..2f2c6a8 100644 --- a/src/yt_napari/_tests/test_widget_reader.py +++ b/src/yt_napari/_tests/test_widget_reader.py @@ -10,6 +10,7 @@ import numpy as np from yt_napari import _widget_reader as _wr +from yt_napari._data_model import InputModel from yt_napari._ds_cache import dataset_cache # import ReaderWidget, SelectionEntry, TimeSeriesReader @@ -48,7 +49,7 @@ def _rebuild_data(final_shape, data): return np.random.random(final_shape) * data.mean() -def test_save_widget_reader(make_napari_viewer, yt_ugrid_ds_fn): +def test_save_widget_reader(make_napari_viewer, yt_ugrid_ds_fn, tmp_path): viewer = make_napari_viewer() r = _wr.ReaderWidget(napari_viewer=viewer) r.ds_container.filename.value = yt_ugrid_ds_fn @@ -65,7 +66,7 @@ def test_save_widget_reader(make_napari_viewer, yt_ugrid_ds_fn): rebuild = partial(_rebuild_data, mgui_region.resolution.value) r._post_load_function = rebuild - temp_file = "test.json" + temp_file = tmp_path / "test.json" with patch("PyQt5.QtWidgets.QFileDialog.exec_") as mock_exec, patch( "PyQt5.QtWidgets.QFileDialog.selectedFiles" @@ -94,15 +95,11 @@ def test_save_widget_reader(make_napari_viewer, yt_ugrid_ds_fn): 400, ] - os.remove(temp_file) + # ensure that the saved json is a valid model + _ = InputModel.parse_obj(saved_data) r.deleteLater() -def simulate_file_selection(args, **kwargs): - # Simulate filling in a file name, selecting a file type, and closing the dialog - return ("selected_file.json", "JSON Files (.json)") - - def test_widget_reader(make_napari_viewer, yt_ugrid_ds_fn): viewer = make_napari_viewer() r = _wr.ReaderWidget(napari_viewer=viewer) @@ -196,7 +193,7 @@ def test_timeseries_widget_reader(make_napari_viewer, tmp_path): tsr.load_data() assert len(viewer.layers) == 2 - temp_file = "test.json" + temp_file = tmp_path / "test.json" # Use patch to replace the actual QFileDialog functions with mock functions with patch("PyQt5.QtWidgets.QFileDialog.exec_") as mock_exec, patch( @@ -231,6 +228,7 @@ def test_timeseries_widget_reader(make_napari_viewer, tmp_path): 10, ] - os.remove(temp_file) + # ensure that the saved json is a valid model + _ = InputModel.parse_obj(saved_data) tsr.deleteLater() diff --git a/src/yt_napari/_widget_reader.py b/src/yt_napari/_widget_reader.py index 2f62d90..d675b21 100644 --- a/src/yt_napari/_widget_reader.py +++ b/src/yt_napari/_widget_reader.py @@ -77,7 +77,9 @@ def add_spatial_selection_widgets(self): self.layout().addLayout(removal_group_layout) def add_load_group_widgets(self): - pass + """ + add the widgets related to the Load button + """ def add_a_selection(self): selection_type = self.new_selection_type.currentText()