diff --git a/dagmc/dagnav.py b/dagmc/dagnav.py index 1bcf218..e6b92ed 100644 --- a/dagmc/dagnav.py +++ b/dagmc/dagnav.py @@ -279,6 +279,11 @@ def get_triangle_coordinate_mapping(self, compress=False): tri_map = {eh: c for eh, c in zip(triangle_handles, conn)} return tri_map, coords + def delete(self): + """Delete this group from the DAGMC file.""" + self.model.mb.delete_entity(self.handle) + self.handle = None + self.model = None class Surface(DAGSet): diff --git a/test/test_basic.py b/test/test_basic.py index ffced56..cffaa36 100644 --- a/test/test_basic.py +++ b/test/test_basic.py @@ -28,9 +28,10 @@ def download(url, filename="dagmc.h5m"): @pytest.fixture(autouse=True, scope='module') def fuel_pin_model(request): - if Path("fuel_pin.h5m").exists(): - return - download(FUEL_PIN_URL, request.path.parent / "fuel_pin.h5m") + fuel_pin_path = request.path.parent / "fuel_pin.h5m" + if not Path(fuel_pin_path).exists(): + download(FUEL_PIN_URL, fuel_pin_path) + return str(fuel_pin_path) def test_basic_functionality(request, capfd): @@ -254,3 +255,18 @@ def test_eq(request): assert model1_v0.handle == model2_v0.handle assert model1_v0 != model2_v0 + +def test_delete(fuel_pin_model): + model = dagmc.DAGModel(fuel_pin_model) + + fuel_group = model.groups['mat:fuel'] + fuel_group.delete() + + # attempt an operation on the group + with pytest.raises(AttributeError, match="has no attribute 'mb'"): + fuel_group.get_volumes() + + # ensure the group is no longer returned by the model + assert 'mat:fuel' not in model.groups + +