Skip to content

Commit

Permalink
Merge pull request #8 from svalinn/add-delete
Browse files Browse the repository at this point in the history
Adding a method to delete sets
  • Loading branch information
pshriwise authored Feb 12, 2024
2 parents 38aeb4a + 0790f9d commit 79dcc62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions dagmc/dagnav.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
22 changes: 19 additions & 3 deletions test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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


0 comments on commit 79dcc62

Please sign in to comment.