Skip to content

Commit

Permalink
fix coverage, use tmp_path fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Nov 30, 2023
1 parent 4cb0fa7 commit ccb6eea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/yt_napari/_tests/test_widget_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
4 changes: 3 additions & 1 deletion src/yt_napari/_widget_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ccb6eea

Please sign in to comment.