Skip to content

Commit

Permalink
add a test for covering grid via GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Apr 2, 2024
1 parent 8158c38 commit 93aa66e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/yt_napari/_gui_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ def get_magicguidefault(field_name: str, field_def: pydantic.fields.Field):
options=opts_dict,
raise_on_unknown=False,
)

if new_widget_cls == widgets.TupleEdit:
ops["options"] = {"min": -1e12, "max": 1e12}

return new_widget_cls(**ops)


Expand Down
27 changes: 26 additions & 1 deletion src/yt_napari/_tests/test_widget_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _rebuild_data(final_shape, data):
# the yt file thats being loaded from the pytest fixture is a saved
# dataset created from an in-memory uniform grid, and the re-loaded
# dataset will not have the full functionality of a ds. so here, we
# inject a correctly shaped random array here. If we start using full
# inject a correctly shaped random array. If we start using full
# test datasets from yt in testing, this should be changed.
return np.random.random(final_shape) * data.mean()

Expand Down Expand Up @@ -236,3 +236,28 @@ def test_timeseries_widget_reader(make_napari_viewer, tmp_path):
_ = InputModel.model_validate(saved_data)

tsr.deleteLater()


def test_covering_grid_selection(make_napari_viewer, yt_ugrid_ds_fn):
viewer = make_napari_viewer()
r = _wr.ReaderWidget(napari_viewer=viewer)
r.ds_container.filename.value = yt_ugrid_ds_fn
r.ds_container.store_in_cache.value = False
r.new_selection_type.setCurrentIndex(2)
r.add_new_button.click()
assert len(r.active_selections) == 1
sel = list(r.active_selections.values())[0]
assert isinstance(sel, _wr.SelectionEntry)
assert sel.selection_type == "CoveringGrid"

mgui_region = sel.selection_container_raw
mgui_region.fields.field_type.value = "gas"
mgui_region.fields.field_name.value = "density"
mgui_region.level.value = 0

mgui_region.left_edge.value.value = (-1.5,) * 3
mgui_region.right_edge.value.value = (1.5,) * 3
rebuild = partial(_rebuild_data, (64, 64, 64))
r._post_load_function = rebuild
r.load_data()
r.deleteLater()

0 comments on commit 93aa66e

Please sign in to comment.