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

test: Add test for _combine_set_states #3303

Merged
merged 1 commit into from
Sep 16, 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
13 changes: 9 additions & 4 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,15 @@ def _combine_set_states(states: List[Tuple[str, StateT]]) -> Tuple[str, StateT]:
for path, state in states:
comps = path.split("/")
comps = comps[len(common_path) :]
obj = combined_state
for comp in comps[:-1]:
obj = obj.setdefault(comp, {})
obj[comps[-1]] = state
if comps:
if not isinstance(combined_state, dict):
combined_state = {}
obj = combined_state
for comp in comps[:-1]:
obj = obj.setdefault(comp, {})
obj[comps[-1]] = state
else:
combined_state = state
return "/".join(common_path), combined_state


Expand Down
37 changes: 37 additions & 0 deletions tests/test_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ansys.fluent.core.solver import flobject
from ansys.fluent.core.solver.flobject import (
InactiveObjectError,
_combine_set_states,
_gethash,
find_children,
)
Expand Down Expand Up @@ -1238,3 +1239,39 @@ def test_default_argument_names_for_commands(static_mixer_settings_session):
assert solver.results.graphics.contour.delete.argument_names == ["name_list"]
# The following is the default behavior when no arguments are associated with the command.
assert solver.results.graphics.contour.list.argument_names == []


def test_combine_set_states():
assert _combine_set_states(
[
("A/B/C", 1),
]
) == ("A/B/C", 1)

assert _combine_set_states(
[
("A/B/C", 1),
("A/B/C", 2),
]
) == ("A/B/C", 2)

assert _combine_set_states(
[
("A/B/C", 1),
("A/B/C", {"X": 2}),
]
) == ("A/B/C", {"X": 2})

assert _combine_set_states(
[
("A/B/C", 1),
("A/B/D", 2),
]
) == ("A/B", {"C": 1, "D": 2})

assert _combine_set_states(
[
("A/B/C", {"X": 1}),
("A/B/D/E", 2),
]
) == ("A/B", {"C": {"X": 1}, "D": {"E": 2}})