Skip to content

Commit 39e7009

Browse files
feat: Use 'deprecated-version' flag for settings-api classes (#3802)
* feat: Added test for the feature. * chore: adding changelog file 3802.added.md [dependabot-skip] * Update client side behaviour. * Correct test. * Optimize. * Updated the 'is_active' check. * Update __dir__ * Optimize and update test. * Update tests. * chore: adding changelog file 3802.added.md [dependabot-skip] * Update tests. * Update __dir__ behaviour. * Update for arguments. * Add test. * Skip test. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 1554163 commit 39e7009

File tree

4 files changed

+120
-1
lines changed

4 files changed

+120
-1
lines changed

doc/changelog.d/3802.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use 'deprecated-version' flag for settings-api classes

src/ansys/fluent/core/solver/flobject.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,19 @@ def get_attr(
407407
return None
408408
return val
409409

410+
def _is_deprecated(self) -> bool:
411+
"""Whether the object is deprecated in a specific Fluent version.'"""
412+
deprecated_version = self.get_attrs(["deprecated-version"])
413+
deprecated_version = (
414+
deprecated_version.get("deprecated-version") if deprecated_version else None
415+
)
416+
return deprecated_version and FluentVersion(self.version) >= FluentVersion(
417+
deprecated_version
418+
)
419+
410420
def is_active(self) -> bool:
411421
"""Whether the object is active."""
412-
attr = self.get_attr(_InlineConstants.is_active)
422+
attr = self.get_attr(_InlineConstants.is_active) and not self._is_deprecated()
413423
return False if attr is False else True
414424

415425
def _check_stable(self) -> None:
@@ -1078,6 +1088,16 @@ def get_active_query_names(self):
10781088
ret.append(query)
10791089
return ret
10801090

1091+
def __dir__(self):
1092+
dir_list = set(list(self.__dict__.keys()) + dir(type(self)))
1093+
return dir_list - set(
1094+
[
1095+
child
1096+
for child in self.child_names + self.command_names + self.query_names
1097+
if getattr(self, child)._is_deprecated()
1098+
]
1099+
)
1100+
10811101
def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
10821102
"""Get completer info of all children.
10831103
@@ -1624,6 +1644,16 @@ def __init__(self, name: str | None = None, parent=None):
16241644
cls = self.__class__._child_classes[argument]
16251645
self._setattr(argument, _create_child(cls, None, self))
16261646

1647+
def __dir__(self):
1648+
dir_list = set(list(self.__dict__.keys()) + dir(type(self)))
1649+
return dir_list - set(
1650+
[
1651+
child
1652+
for child in self.argument_names
1653+
if getattr(self, child)._is_deprecated()
1654+
]
1655+
)
1656+
16271657
def get_completer_info(self, prefix="", excluded=None) -> List[List[str]]:
16281658
"""Get completer info of all arguments.
16291659

tests/test_flobject.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def get_attrs(self, attrs):
6363
attrs = {
6464
"active?": lambda self: True,
6565
"webui-release-active?": lambda self: True,
66+
"deprecated-version": lambda self: None,
6667
}
6768

6869

@@ -324,6 +325,7 @@ class S1(String):
324325
"active?": lambda self: not self.parent.objs["b-3"].get_state(),
325326
"allowed-values": lambda self: ["foo", "bar"],
326327
"webui-release-active?": lambda self: True,
328+
"deprecated-version": lambda self: None,
327329
}
328330

329331
children = {

tests/test_settings_api.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,92 @@ def test_return_types_of_operations_on_named_objects(mixing_elbow_settings_sessi
641641
assert var3.obj_name == "air-copied"
642642

643643

644+
@pytest.mark.skip("https://github.com/ansys/pyfluent/issues/3813")
645+
@pytest.mark.fluent_version(">=25.1")
646+
def test_settings_with_deprecated_flag(mixing_elbow_settings_session):
647+
solver = mixing_elbow_settings_session
648+
solver.settings.solution.initialization.hybrid_initialize()
649+
graphics = solver.settings.results.graphics
650+
graphics.contour["contour-velocity"] = {
651+
"field": "velocity-magnitude",
652+
"surfaces_list": ["wall-elbow"],
653+
}
654+
# In the line below, "range_option" and "coloring" are deprecated.
655+
if solver.get_fluent_version() <= FluentVersion.v251:
656+
# From v252 'get_state' behaviour is to be corrected in Fluent.
657+
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
658+
set(graphics.contour["contour-velocity"]())
659+
)
660+
assert (
661+
graphics.contour["contour-velocity"].range_option.get_attr("deprecated-version")
662+
== "25.1"
663+
)
664+
assert (
665+
graphics.contour["contour-velocity"].coloring.get_attr("deprecated-version")
666+
== "25.1"
667+
)
668+
669+
# Deprecated objects should not be active
670+
assert not graphics.contour["contour-velocity"].range_option.is_active()
671+
assert graphics.contour["contour-velocity"].range_options.is_active()
672+
673+
# in 'get_state'
674+
if solver.get_fluent_version() >= FluentVersion.v252:
675+
# From v252 'get_state' behaviour is to be corrected in Fluent.
676+
assert not {"range_option", "coloring"}.issubset(
677+
set(graphics.contour["contour-velocity"].get_state())
678+
)
679+
assert {"range_options", "colorings"}.issubset(
680+
set(graphics.contour["contour-velocity"].get_state())
681+
)
682+
else:
683+
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
684+
set(graphics.contour["contour-velocity"].get_state())
685+
)
686+
687+
# in 'child_names'
688+
# 'child_names', 'command_names' and 'query_names' will remain unchanged.
689+
assert {"range_option", "range_options", "coloring", "colorings"}.issubset(
690+
set(graphics.contour["contour-velocity"].child_names)
691+
)
692+
693+
# in 'get_active_child_names'
694+
assert not {"range_option", "coloring"}.issubset(
695+
set(graphics.contour["contour-velocity"].get_active_child_names())
696+
)
697+
assert {"range_options", "colorings"}.issubset(
698+
set(graphics.contour["contour-velocity"].get_active_child_names())
699+
)
700+
701+
# in 'dir'
702+
assert not {"range_option", "coloring"}.issubset(
703+
set(dir(graphics.contour["contour-velocity"]))
704+
)
705+
assert {"range_options", "colorings"}.issubset(
706+
set(dir(graphics.contour["contour-velocity"]))
707+
)
708+
709+
# This should be True, as attribute is present, just not exposed.
710+
for item in ["range_option", "range_options", "coloring", "colorings"]:
711+
assert hasattr(graphics.contour["contour-velocity"], item)
712+
713+
# Named-object
714+
solver.settings.solution.report_definitions.surface["report-def-1"] = {}
715+
solver.settings.solution.report_definitions.surface["report-def-1"].report_type = (
716+
"surface-area"
717+
)
718+
solver.settings.solution.report_definitions.surface[
719+
"report-def-1"
720+
].surface_names = ["cold-inlet", "hot-inlet"]
721+
assert "create_output_parameter" not in dir(
722+
solver.settings.solution.report_definitions.surface["report-def-1"]
723+
)
724+
assert hasattr(
725+
solver.settings.solution.report_definitions.surface["report-def-1"],
726+
"create_output_parameter",
727+
)
728+
729+
644730
@pytest.fixture
645731
def use_runtime_python_classes(monkeypatch: pytest.MonkeyPatch):
646732
monkeypatch.setenv("PYFLUENT_USE_RUNTIME_PYTHON_CLASSES", "1")

0 commit comments

Comments
 (0)