Skip to content

Commit

Permalink
Fix/error accessing attrribute file type (#705)
Browse files Browse the repository at this point in the history
* the fix for the issue is applied

* Added test case to check working of the new accessor methods and this fix

* moved is_read_only to Base()
  • Loading branch information
prmukherj authored Aug 11, 2022
1 parent 6de8f84 commit 98f12e8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def is_active(self) -> bool:
"""Whether the object is active."""
return self.get_attr("active?")

def is_read_only(self) -> bool:
"""Whether the object is read-only."""
return self.get_attr("read-only?")

def __setattr__(self, name, value):
raise AttributeError(name)

Expand All @@ -170,10 +174,6 @@ def default_value(self):
"""Gets the default value of the object."""
return self.get_attr("default")

def is_read_only(self) -> bool:
"""Whether the object is read-only."""
return self.get_attr("read-only?")


class Numerical(Property):
"""Exposes attribute accessor on settings object - specific to numerical objects."""
Expand Down Expand Up @@ -668,6 +668,14 @@ def _get_new_keywords(obj, kwds):
class Command(Base):
"""Command object."""

def __init__(self, name: str = None, parent=None):
"""__init__ of Command class."""
super().__init__(name, parent)
if hasattr(self, "argument_names"):
for argument in self.argument_names:
cls = getattr(self.__class__, argument)
self._setattr(argument, cls(None, self))

def __call__(self, **kwds):
"""Call a command with the specified keyword arguments."""
newkwds = _get_new_keywords(self, kwds)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,3 +631,13 @@ class a_2(Boolean):
fluent_name = "a-2"
'''
) # noqa: W293


def test_accessor_methods_on_settings_object(sample_solver_session):
existing = sample_solver_session.file.read.file_type.get_attr("allowed-values")
modified = sample_solver_session.file.read.file_type.allowed_values()
assert existing == modified

existing = sample_solver_session.file.read.file_type.get_attr("read-only?")
modified = sample_solver_session.file.read.file_type.is_read_only()
assert existing == modified
7 changes: 7 additions & 0 deletions tests/util/fixture_fluent.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,10 @@ def get_name_info(allnamesdict, namescheck):
if name in details.values() or name in details or name in names:
name_selected[name] = details
return name_selected


@pytest.fixture
def sample_solver_session(with_launching_container):
solver_session = pyfluent.launch_fluent(mode="solver")
yield solver_session
solver_session.exit()

0 comments on commit 98f12e8

Please sign in to comment.