Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #690 from ess-dmsc/689_fix_warning_when_deleting_c…
Browse files Browse the repository at this point in the history
…omponent_with_transform

Add unit test and fix for deleting component with transformation
  • Loading branch information
rerpha authored Mar 16, 2020
2 parents 75acd9d + 4b163d2 commit d1a5c9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
26 changes: 15 additions & 11 deletions nexus_constructor/component_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,22 @@ def _remove_transformation(self, index: QModelIndex):
def _remove_component(self, index: QModelIndex):
component = index.internalPointer()
transforms = component.transforms
if transforms and transforms[0].dependents():
reply = QMessageBox.question(
None,
"Delete component?",
"this component has transformations that are depended on. Are you sure you want to delete it?",
QMessageBox.Yes,
QMessageBox.No,
if transforms:
has_dependents_other_than_the_component_being_deleted = (
len(transforms[0].dependents) > 1
)
if reply == QMessageBox.Yes:
pass
elif reply == QMessageBox.No:
return
if has_dependents_other_than_the_component_being_deleted:
reply = QMessageBox.question(
None,
"Delete component?",
"this component has transformations that are depended on. Are you sure you want to delete it?",
QMessageBox.Yes,
QMessageBox.No,
)
if reply == QMessageBox.Yes:
pass
elif reply == QMessageBox.No:
return
remove_index = self.components.index(index.internalPointer())
self.beginRemoveRows(QModelIndex(), remove_index, remove_index)
for transform in transforms:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_component_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,20 @@ def test_remove_component(nexus_wrapper):
assert under_test.rowCount(QModelIndex()) == 0


def test_remove_component_with_transformation(nexus_wrapper):
instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
under_test = ComponentTreeModel(instrument)
instrument.create_component("Some name", "some class", "desc")
component_index = under_test.index(0, 0, QModelIndex())
under_test.add_rotation(component_index)
assert under_test.rowCount(QModelIndex()) == 1
under_test.remove_node(component_index)
assert under_test.rowCount(QModelIndex()) == 0, (
"Expected component to be successfully deleted because it has "
"a transformation that only has it as a dependent"
)


def test_remove_transformation(nexus_wrapper):
instrument = Instrument(nexus_wrapper, NX_CLASS_DEFINITIONS)
under_test = ComponentTreeModel(instrument)
Expand Down

0 comments on commit d1a5c9f

Please sign in to comment.