Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions doc/changelog.d/4342.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extract allowed values
2 changes: 2 additions & 0 deletions src/ansys/fluent/core/codegen/settingsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO |
s_stub.write(
f" {to_constant_name(allowed_value)}: Final[str] = {allowed_value!r}\n"
)
s.write(f" _allowed_values = {data['allowed_values']!r}\n")
s_stub.write(" _allowed_values: list\n")
s.write("\n")
s_stub.write("\n")
for name, (python_name, data, hash_, should_write_stub) in classes_to_write.items():
Expand Down
33 changes: 32 additions & 1 deletion tests/test_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ def test_allapigen_files(new_solver_session):
importlib.import_module(f"ansys.fluent.core.generated.solver.settings_{version}")


@pytest.mark.codegen_required
def test_settings_allowed_values(new_solver_session):
version = get_version_for_file_name(session=new_solver_session)
module = importlib.import_module(
f"ansys.fluent.core.generated.solver.settings_{version}"
)

file_type_1 = getattr(module, "file_type_1")
assert set(file_type_1._allowed_values) == set(
["case", "case-data", "data", "mesh"]
)

unit = getattr(module, "unit")
assert set(unit._allowed_values) == set(["m", "cm", "mm", "in", "ft"])


def test_codegen_with_no_static_info(monkeypatch):
codegen_outdir = Path(tempfile.mkdtemp())
monkeypatch.setattr(pyfluent.config, "codegen_outdir", codegen_outdir)
Expand Down Expand Up @@ -516,6 +532,7 @@ class P3(Integer):
_version = '251'
fluent_name = 'P3'
_python_name = 'P3'
_allowed_values = []

class G2(Group):
"""
Expand All @@ -528,6 +545,7 @@ class G2(Group):
_child_classes = dict(
P3=P3,
)
_allowed_values = []

class P2(Real):
"""
Expand All @@ -536,6 +554,7 @@ class P2(Real):
_version = '251'
fluent_name = 'P2'
_python_name = 'P2'
_allowed_values = []

class A2(Real):
"""
Expand All @@ -544,6 +563,7 @@ class A2(Real):
_version = '251'
fluent_name = 'A2'
_python_name = 'A2'
_allowed_values = []

class C2(Command):
"""
Expand All @@ -561,6 +581,7 @@ class C2(Command):
_child_classes = dict(
A2=A2,
)
_allowed_values = []

class Q2(Query):
"""
Expand All @@ -578,6 +599,7 @@ class Q2(Query):
_child_classes = dict(
A2=A2,
)
_allowed_values = []

class G1(Group):
"""
Expand All @@ -595,6 +617,7 @@ class G1(Group):
C2=C2,
Q2=Q2,
)
_allowed_values = []

class P1(String):
"""
Expand All @@ -603,6 +626,7 @@ class P1(String):
_version = '251'
fluent_name = 'P1'
_python_name = 'P1'
_allowed_values = []

class P4(String):
"""
Expand All @@ -611,6 +635,7 @@ class P4(String):
_version = '251'
fluent_name = 'P4'
_python_name = 'P4'
_allowed_values = []

class N1_child(Group):
"""
Expand All @@ -619,6 +644,7 @@ class N1_child(Group):
_version = '251'
fluent_name = 'child-object-type'
_python_name = 'N1_child'
_allowed_values = []

class N1(NamedObject[N1_child], _NonCreatableNamedObjectMixin[N1_child]):
"""
Expand All @@ -632,6 +658,7 @@ class N1(NamedObject[N1_child], _NonCreatableNamedObjectMixin[N1_child]):
P4=P4,
)
child_object_type = N1_child
_allowed_values = []

class A1(String):
"""
Expand All @@ -640,6 +667,7 @@ class A1(String):
_version = '251'
fluent_name = 'A1'
_python_name = 'A1'
_allowed_values = []

class C1(Command):
"""
Expand All @@ -657,6 +685,7 @@ class C1(Command):
_child_classes = dict(
A1=A1,
)
_allowed_values = []

class Q1(Query):
"""
Expand All @@ -674,6 +703,7 @@ class Q1(Query):
_child_classes = dict(
A1=A1,
)
_allowed_values = []

class root(Group):
"""
Expand All @@ -691,7 +721,8 @@ class root(Group):
N1=N1,
C1=C1,
Q1=Q1,
)''' # noqa: W293
)
_allowed_values = []''' # noqa: W293


def test_codegen_with_settings_static_info(monkeypatch):
Expand Down