Skip to content

Commit

Permalink
Merge branch 'main' into fix/random_pytest_failures_in_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
prmukherj authored Feb 10, 2024
2 parents d85f7d7 + 72493e9 commit 5f522d5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
12 changes: 5 additions & 7 deletions src/ansys/fluent/core/filereader/case_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,9 @@ def _get_case_file_name_from_flprj(flprj_file):
# If the project file name begins with a digit then the node to find will be prepended
# with "_". Rather than making any assumptions that this is a hard rule, or what
# the scope of the rule is, simply retry with the name prepended:
find_folder = lambda retry=False: root.find(("_" if retry else "") + folder_name)
return (
(find_folder() or find_folder(retry=True))
.find("Input")
.find("Case")
.find("Target")
.get("value")
folder_obj = (
root.find(folder_name)
if len(root.find(folder_name)) > 0
else root.find("_" + folder_name)
)
return folder_obj.find("Input").find("Case").find("Target").get("value")
18 changes: 1 addition & 17 deletions src/ansys/fluent/core/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,6 @@ def wrapper(self):

return wrapper

@classmethod
def __create_get_session_handle(cls):
def wrapper(self, obj=None):
root = self.get_root(obj)
return root.session_handle

return wrapper

def __new__(cls, name, bases, attrs):
attrs["get_ancestors_by_type"] = cls.__create_get_ancestors_by_type()
attrs["get_ancestors_by_name"] = cls.__create_get_ancestors_by_name()
Expand Down Expand Up @@ -829,7 +821,7 @@ def session(self):
def get_session_handle(self, obj=None):
"""Returns the session-handle object."""
root = self.get_root(obj)
return root.session_handle
return getattr(root, "session_handle", None)

@property
def session_handle(self):
Expand Down Expand Up @@ -860,14 +852,6 @@ def path(self):
def session(self):
return self.get_session()

def get_session_handle(self, obj=None):
root = self.get_root(obj)
return root.session_handle

@property
def session_handle(self):
return self.get_session_handle()

def __iter__(self):
return iter(self.__collection)

Expand Down
18 changes: 15 additions & 3 deletions src/ansys/fluent/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,11 @@ def __init__(self, task: BaseTask) -> None:
task : BaseTask
The task holding these arguments.
"""
self._task = task
self.__dict__.update(
dict(
_task=task,
)
)

def set_state(self, args: dict) -> None:
"""Overwrite arguments.
Expand Down Expand Up @@ -441,6 +445,14 @@ def get_state(self, explicit_only=False) -> dict:
def __getattr__(self, attr):
return getattr(self._task._command_arguments, attr)

def __setattr__(self, key, value):
try:
getattr(self, key).set_state(value)
except AttributeError:
raise AttributeError(
f"No attribute named '{key}' in '{self._task.name()}'."
)

def __setitem__(self, key, value):
self._task._command_arguments.__setitem__(key, value)

Expand Down Expand Up @@ -540,15 +552,15 @@ def _refreshed_command(self) -> ReadOnlyObject:
cmd = self._command()
if task_arg_state:
cmd.set_state(task_arg_state)
return ReadOnlyObject(self._cmd_sub_items_read_only(cmd, cmd()))
return self._cmd_sub_items_read_only(cmd, cmd())

def _cmd_sub_items_read_only(self, cmd, cmd_state):
for key, value in cmd_state.items():
if type(value) == dict:
setattr(
cmd, key, self._cmd_sub_items_read_only(getattr(cmd, key), value)
)
setattr(cmd, key, ReadOnlyObject(getattr(cmd, key)))
setattr(cmd, key, getattr(cmd, key))
return cmd

def _command(self):
Expand Down
34 changes: 30 additions & 4 deletions tests/test_meshing_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_attribute_query_list_types(new_mesh_session):
assert ["CAD", "Mesh"] == igt.arguments.FileFormat.getAttribValue("allowedValues")


@pytest.mark.fluent_version(">=23.1")
@pytest.mark.fluent_version(">=23.2")
@pytest.mark.codegen_required
def test_accessors_for_argument_sub_items(new_mesh_session):
session_new = new_mesh_session
Expand All @@ -234,10 +234,35 @@ def test_accessors_for_argument_sub_items(new_mesh_session):
w.InitializeWorkflow(WorkflowType="Watertight Geometry")
import_geom = w.task("Import Geometry")
assert import_geom.arguments.LengthUnit.default_value() == "mm"
assert import_geom.arguments.MeshUnit.is_read_only()
assert import_geom.arguments.LengthUnit.allowed_values() == [
"m",
"cm",
"mm",
"in",
"ft",
"um",
"nm",
]
assert import_geom.arguments.LengthUnit() == "mm"
import_geom.arguments.LengthUnit.set_state("cm")
assert import_geom.arguments.LengthUnit.get_state() == "cm"
import_geom.arguments.LengthUnit = "in"
assert import_geom.arguments.LengthUnit() == "in"

assert not import_geom.arguments.MeshUnit.is_read_only()
assert import_geom.arguments.LengthUnit.is_active()
assert import_geom.arguments.FileName.is_read_only()
assert import_geom.arguments.CadImportOptions.OneZonePer.is_read_only()
assert not import_geom.arguments.FileName.is_read_only()
assert not import_geom.arguments.FileName()
import_geom.arguments.FileName = "xyz.txt"
assert import_geom.arguments.FileName() == "xyz.txt"
with pytest.raises(AttributeError) as msg:
import_geom.arguments.File = "sample.txt"
assert msg.value.args[0] == "No attribute named 'File' in 'Import Geometry'."
assert not import_geom.arguments.CadImportOptions.OneZonePer.is_read_only()

assert import_geom.arguments.CadImportOptions.OneZonePer() == "body"
import_geom.arguments.CadImportOptions.OneZonePer.set_state("face")
assert import_geom.arguments.CadImportOptions.OneZonePer() == "face"

volume_mesh_gen = w.task("Generate the Volume Mesh")
assert (
Expand Down Expand Up @@ -280,6 +305,7 @@ def test_accessors_for_argument_sub_items(new_mesh_session):
)


@pytest.mark.skip("Wait for later implementation.")
@pytest.mark.fluent_version(">=23.1")
@pytest.mark.codegen_required
def test_read_only_behaviour_of_command_arguments(new_mesh_session):
Expand Down

0 comments on commit 5f522d5

Please sign in to comment.