Skip to content

Commit

Permalink
Add missing callback setter to LinkedSelectionRule and TaperEdge
Browse files Browse the repository at this point in the history
The '_set_callback_apply_changes' function implementation was
missing from the LinkedSelectionRule and TaperEdge classes.

To detect such issues in future, set the 'mypy-tests' pre-commit
run to use the '--strict' flag, but explicitly ignoring the
'no-untyped-def' and 'no-untyped-call' error codes.

Add an explicit test for the linked selection rule properties.

General note: The 'GenericEdgePropertyType' classes have too much
duplication for my taste, and could use some cleanup / creation
of helper functions similar to the other tree other types.
  • Loading branch information
greschd committed Feb 7, 2024
1 parent 1a5c7a2 commit b54cb9c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,10 @@ repos:
types: [python]
require_serial: true
files: "^(tests/)|^(examples/)"
args: ["--namespace-packages", "--explicit-package-bases"]
args: [
"--strict",
"--namespace-packages",
"--explicit-package-bases",
"--disable-error-code", "no-untyped-def",
"--disable-error-code", "no-untyped-call"
]
3 changes: 3 additions & 0 deletions src/ansys/acp/core/_tree_objects/linked_selection_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ def parameter_2(self, value: float) -> None:
if self._callback_apply_changes is not None:
self._callback_apply_changes()

def _set_callback_apply_changes(self, callback_apply_changes: Callable[[], None]) -> None:
self._callback_apply_changes = callback_apply_changes

@classmethod
def _from_pb_object(
cls,
Expand Down
3 changes: 3 additions & 0 deletions src/ansys/acp/core/_tree_objects/modeling_ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def offset(self, offset: float) -> None:
if self._callback_apply_changes is not None:
self._callback_apply_changes()

def _set_callback_apply_changes(self, callback_apply_changes: Callable[[], None]) -> None:
self._callback_apply_changes = callback_apply_changes

@classmethod
def _from_pb_object(
cls,
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/common/tree_object_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_collection_delitem(collection_test_data):
object_collection[ref_id]


class NoLockedMixin:
class NoLockedMixin(TreeObjectTester):
@pytest.fixture
def collection_test_data(self, parent_object):
object_collection = getattr(parent_object, self.COLLECTION_NAME)
Expand All @@ -147,7 +147,7 @@ def test_collection_clear(collection_test_data):
assert len(object_collection) == 0


class WithLockedMixin:
class WithLockedMixin(TreeObjectTester):
INITIAL_OBJECT_NAMES: tuple[str, ...]

@pytest.fixture
Expand Down
17 changes: 17 additions & 0 deletions tests/unittests/test_modeling_ply.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,20 @@ def test_nodal_data_to_pyvista_with_component(
), f"Created wrong mesh type UnstructuredGrid for component '{component}'"
assert pv_mesh.n_points == 4
assert pv_mesh.n_cells == 1


def test_linked_selection_rule_parameters(simple_modeling_ply, minimal_complete_model):
parallel_selection_rule = minimal_complete_model.create_parallel_selection_rule(
origin=(0.0, 0.0, 0.0), direction=(1.0, 0.0, 0.0), lower_limit=0.005, upper_limit=1.0
)
linked_parallel_rule = LinkedSelectionRule(parallel_selection_rule, template_rule=True)
simple_modeling_ply.selection_rules = [linked_parallel_rule]

linked_parallel_rule.parameter_1 = 1.0
minimal_complete_model.update()

assert linked_parallel_rule.parameter_1 == simple_modeling_ply.selection_rules[0].parameter_1

linked_rule_in_ply = simple_modeling_ply.selection_rules[0]
linked_rule_in_ply.parameter_1 = 1
assert linked_parallel_rule.parameter_1 == simple_modeling_ply.selection_rules[0].parameter_1

0 comments on commit b54cb9c

Please sign in to comment.