diff --git a/doc/changelog.d/4551.fixed.md b/doc/changelog.d/4551.fixed.md new file mode 100644 index 00000000000..cda93f7ed6a --- /dev/null +++ b/doc/changelog.d/4551.fixed.md @@ -0,0 +1 @@ +SettingsBase.__call__ should also set state if any argument is passed. diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 2661366eaee..3495fde77df 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -819,9 +819,14 @@ def to_python_keys(cls, value: StateT) -> StateT: """ return value - def __call__(self) -> StateT: - """Alias for self.get_state.""" - return self.get_state() + def __call__(self, *args, **kwargs): + """Get or set the state of the object.""" + if kwargs: + self.set_state(kwargs) + elif args: + self.set_state(args) + else: + return self.get_state() def get_state(self) -> StateT: """Get the state of the object.""" @@ -1065,14 +1070,6 @@ def __init__(self, name: str | None = None, parent=None): cls = self.__class__._child_classes[query] self._setattr(query, _create_child(cls, None, self)) - def __call__(self, *args, **kwargs): - if kwargs: - self.set_state(kwargs) - elif args: - self.set_state(args) - else: - return self.get_state() - @classmethod def to_scheme_keys(cls, value, root_cls, path: list[str]): """Convert value to have keys with scheme names. @@ -1503,7 +1500,10 @@ def __add__(self, other): def list(self): """Print the object names.""" - return self._root.list(object_path=self.path) + if FluentVersion(self._version) >= FluentVersion.v261: + return self._root.list(object_path=self.path) + else: + return self.list_1() def list_properties(self, object_name): """Print the properties of the given object name. @@ -1513,8 +1513,11 @@ def list_properties(self, object_name): object_name : str Name of the object whose properties are to be listed. """ - # The generated parameter name is path_1 as the name path clashes with existing property. - return self._root.list_properties(path_1=self.path, name=object_name) + if FluentVersion(self._version) >= FluentVersion.v261: + # The generated parameter name is path_1 as the name path clashes with existing property. + return self._root.list_properties(path_1=self.path, name=object_name) + else: + return self.list_properties_1(object_name=object_name) class CombinedNamedObject: diff --git a/tests/test_flobject.py b/tests/test_flobject.py index ff513b2d5bb..24e60bbd830 100644 --- a/tests/test_flobject.py +++ b/tests/test_flobject.py @@ -1223,34 +1223,35 @@ def test_default_argument_names_for_commands(static_mixer_settings_session): solver = static_mixer_settings_session if solver.get_fluent_version() >= FluentVersion.v251: - assert set(solver.results.graphics.contour.command_names) == { - "create", - "delete", - "rename", - "list", - "list_properties", - "make_a_copy", - "display", - "add_to_graphics", - "clear_history", - } + assert set(solver.results.graphics.contour.command_names).issuperset( + { + "create", + "delete", + "rename", + "make_a_copy", + "display", + "add_to_graphics", + "clear_history", + } + ) else: - assert set(solver.results.graphics.contour.command_names) == { - "delete", - "rename", - "list", - "list_properties", - "make_a_copy", - "display", - "copy", - "add_to_graphics", - "clear_history", - } + assert set(solver.results.graphics.contour.command_names).issuperset( + { + "delete", + "rename", + "make_a_copy", + "display", + "copy", + "add_to_graphics", + "clear_history", + } + ) - assert solver.results.graphics.contour.rename.argument_names == ["new", "old"] + assert set(solver.results.graphics.contour.rename.argument_names) == {"new", "old"} 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 == [] + if solver.get_fluent_version() < FluentVersion.v261: + # The following is the default behavior when no arguments are associated with the command. + assert solver.results.graphics.contour.list_1.argument_names == [] @pytest.mark.fluent_version(">=25.1")