Skip to content

Commit 28f6bdf

Browse files
authored
Merge pull request #1386
* Methods deletion simplification and fix * Action refactor * Test updates
1 parent 901f39c commit 28f6bdf

4 files changed

Lines changed: 18 additions & 26 deletions

File tree

activity_browser/actions/method/method_delete.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,20 @@ class MethodDelete(ABAction):
2323

2424
@staticmethod
2525
@exception_dialogs
26-
def run(methods: List[tuple], level: str):
27-
# this action can handle only one selected method for now
28-
selected_method = methods[0]
29-
26+
def run(methods: List[tuple]):
3027
# check whether we're dealing with a leaf or node. If it's a node, select all underlying methods for deletion
31-
if level is not None and level != "leaf":
32-
all_methods = [
33-
bd.Method(method)
34-
for method in bd.methods
35-
if set(selected_method).issubset(method)
36-
]
28+
all_methods = [bd.Method(method) for method in methods]
29+
30+
if len(all_methods) == 1:
31+
warning_text = f"Are you sure you want to delete this method?\n\n{methods[0]}"
3732
else:
38-
all_methods = [bd.Method(selected_method)]
33+
warning_text = f"Are you sure you want to delete {len(all_methods)} methods?"
3934

4035
# warn the user about the pending deletion
4136
warning = QtWidgets.QMessageBox.warning(
4237
application.main_window,
4338
"Deleting Method",
44-
f"Are you sure you want to delete this method and possible underlying "
45-
f"methods?\n\n{selected_method}",
39+
warning_text,
4640
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
4741
QtWidgets.QMessageBox.No,
4842
)

activity_browser/ui/tables/impact_categories.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def __init__(self, parent=None):
3333
self.duplicate_method_action = actions.MethodDuplicate.get_QAction(
3434
self.selected_methods, None
3535
)
36-
self.delete_method_action = actions.MethodDelete.get_QAction(
37-
self.selected_methods, None
38-
)
36+
self.delete_method_action = actions.MethodDelete.get_QAction(self.selected_methods)
3937

4038
self.connect_signals()
4139

@@ -113,9 +111,7 @@ def __init__(self, parent=None):
113111
self.duplicate_method_action = actions.MethodDuplicate.get_QAction(
114112
self.selected_methods, self.tree_level
115113
)
116-
self.delete_method_action = actions.MethodDelete.get_QAction(
117-
self.selected_methods, self.tree_level
118-
)
114+
self.delete_method_action = actions.MethodDelete.get_QAction(self.selected_methods)
119115

120116
self._connect_signals()
121117

@@ -202,7 +198,7 @@ def selected_methods(self) -> Iterable:
202198
filter_on = ", ".join(tree_level[1]) + ", "
203199

204200
methods = self.model.get_methods(filter_on)
205-
return methods
201+
return list(methods)
206202

207203
def tree_level(self) -> tuple:
208204
"""Return list of (tree level, content).

tests/actions/test_method_actions.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def test_cf_uncertainty_remove(ab_app):
116116

117117
def test_method_delete(ab_app, monkeypatch):
118118
method = ("A_methods", "methods", "method_to_delete")
119-
branch = ("A_methods", "methods_to_delete")
120-
branched_method = ("A_methods", "methods_to_delete", "method_to_delete")
119+
dual_method_1 = ("A_methods", "methods_to_delete", "method_to_delete_one")
120+
dual_method_2 = ("A_methods", "methods_to_delete", "method_to_delete_two")
121121

122122
monkeypatch.setattr(
123123
QtWidgets.QMessageBox,
@@ -127,13 +127,15 @@ def test_method_delete(ab_app, monkeypatch):
127127

128128
assert bd.projects.current == "default"
129129
assert method in bd.methods
130-
assert branched_method in bd.methods
130+
assert dual_method_1 in bd.methods
131+
assert dual_method_2 in bd.methods
131132

132-
actions.MethodDelete.run([method], "leaf")
133-
actions.MethodDelete.run([branch], "branch")
133+
actions.MethodDelete.run([method])
134+
actions.MethodDelete.run([dual_method_1, dual_method_2])
134135

135136
assert method not in bd.methods
136-
assert branched_method not in bd.methods
137+
assert dual_method_1 not in bd.methods
138+
assert dual_method_2 not in bd.methods
137139

138140

139141
def test_method_duplicate(ab_app, monkeypatch):

tests/pytest_base.gz

3.08 KB
Binary file not shown.

0 commit comments

Comments
 (0)