Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a method to delete sets #8

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we delete the entry in model.groups?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry for the quick-merge! I think we're okay here though as the dict returned by the model.groups property is generated on-the-fly, so the next time it's accessed the groups should reflect those currently in the model.

Previous dict's generated by this property will become stale after a group is deleted, but that will have to be up to the user to track I'm afraid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quick-merge is only enabled by my too superficial review :) - no worries here, then.

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


Loading