Skip to content

Commit ede4b3c

Browse files
chore: Extract allowed values (#4342)
This pull request focuses on improving maintainability by extracting and explicitly defining allowed values for settings classes. The main change ensures that allowed values are clearly listed and type-annotated, which will help with code clarity and future maintenance. Settings class allowed values extraction: * Added the `_allowed_values` attribute to settings classes in both implementation and stub files, making allowed values explicit and type-annotated (`src/ansys/fluent/core/codegen/settingsgen.py`). * Documented the extraction of allowed values in the changelog (`doc/changelog.d/4342.maintenance.md`). --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent df04625 commit ede4b3c

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Extract allowed values

src/ansys/fluent/core/codegen/settingsgen.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ def _write_data(cls_name: str, python_name: str, data: dict, f: IO, f_stub: IO |
316316
s_stub.write(
317317
f" {to_constant_name(allowed_value)}: Final[str] = {allowed_value!r}\n"
318318
)
319+
if data["allowed_values"]:
320+
s.write(f" _allowed_values = {data['allowed_values']!r}\n")
321+
s_stub.write(" _allowed_values: list[str]\n")
319322
s.write("\n")
320323
s_stub.write("\n")
321324
for name, (python_name, data, hash_, should_write_stub) in classes_to_write.items():

tests/test_codegen.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ def test_allapigen_files(new_solver_session):
5656
importlib.import_module(f"ansys.fluent.core.generated.solver.settings_{version}")
5757

5858

59+
@pytest.mark.fluent_version(">=26.1")
60+
@pytest.mark.codegen_required
61+
def test_settings_allowed_values(new_solver_session):
62+
version = get_version_for_file_name(session=new_solver_session)
63+
module = importlib.import_module(
64+
f"ansys.fluent.core.generated.solver.settings_{version}"
65+
)
66+
67+
file_type_1 = getattr(module, "file_type_1")
68+
assert set(file_type_1._allowed_values) == set(
69+
["case", "case-data", "data", "mesh"]
70+
)
71+
72+
unit = getattr(module, "unit")
73+
assert set(unit._allowed_values) == set(["m", "cm", "mm", "in", "ft"])
74+
75+
5976
def test_codegen_with_no_static_info(monkeypatch):
6077
codegen_outdir = Path(tempfile.mkdtemp())
6178
monkeypatch.setattr(pyfluent.config, "codegen_outdir", codegen_outdir)

0 commit comments

Comments
 (0)