From 1e4a02144afa1c59bc6b318a02407a4dd1f4e49a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:20:39 +0000 Subject: [PATCH 1/4] Initial plan From 4ece1ef9e2ef5b58f80c21ac00b7a725fa91fef2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:25:13 +0000 Subject: [PATCH 2/4] Fix _AllowedDomainNames.valid_name: eliminate state inconsistency and fix ZoneError call Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/a493dbab-5525-4799-8b10-b99c18923d8d Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com> --- .../core/services/solution_variables.py | 13 +++-- tests/test_solution_variables.py | 55 +++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/ansys/fluent/core/services/solution_variables.py b/src/ansys/fluent/core/services/solution_variables.py index 655bef2f5b8..1f08f0e4e19 100644 --- a/src/ansys/fluent/core/services/solution_variables.py +++ b/src/ansys/fluent/core/services/solution_variables.py @@ -425,12 +425,13 @@ def valid_name(self, domain_name): ZoneError If the given domain name is invalid. """ - if not self.is_valid(domain_name): - raise ZoneError( - domain_name=domain_name, - allowed_values=self(), - ) - return self._zones_info.domain_id(domain_name) + domain_id = self._zones_info.domain_id(domain_name) + if domain_id is not None: + return domain_id + raise ZoneError( + zone_name=domain_name, + allowed_values=self(), + ) class _SvarMethod: diff --git a/tests/test_solution_variables.py b/tests/test_solution_variables.py index 37ca9c588c4..e2dbabdeae5 100644 --- a/tests/test_solution_variables.py +++ b/tests/test_solution_variables.py @@ -25,9 +25,64 @@ from ansys.fluent.core import examples from ansys.fluent.core.examples.downloads import download_file +from ansys.fluent.core.services.solution_variables import ( + ZoneError, + _AllowedDomainNames, +) from ansys.units.variable_descriptor import VariableCatalog +class _DummyZonesInfo: + """Mock ZonesInfo for unit testing _AllowedDomainNames.""" + + def __init__(self, domains, domain_id_map): + self._domains = domains + self._domain_id_map = domain_id_map + + @property + def domains(self): + return self._domains + + def domain_id(self, name): + return self._domain_id_map.get(name, None) + + +class _DummySVInfo: + """Mock SolutionVariableInfo for unit testing _AllowedDomainNames.""" + + def __init__(self, zones_info): + self._zones_info = zones_info + + def get_zones_info(self): + return self._zones_info + + +def test_allowed_domain_names_valid_name_returns_domain_id(): + zones_info = _DummyZonesInfo(domains=["mixture"], domain_id_map={"mixture": 1}) + allowed = _AllowedDomainNames(_DummySVInfo(zones_info)) + assert allowed.valid_name("mixture") == 1 + + +def test_allowed_domain_names_valid_name_domain_id_zero(): + zones_info = _DummyZonesInfo(domains=["mixture"], domain_id_map={"mixture": 0}) + allowed = _AllowedDomainNames(_DummySVInfo(zones_info)) + assert allowed.valid_name("mixture") == 0 + + +def test_allowed_domain_names_valid_name_raises_on_missing_domain_id(): + zones_info = _DummyZonesInfo(domains=["mixture"], domain_id_map={}) + allowed = _AllowedDomainNames(_DummySVInfo(zones_info)) + with pytest.raises(ZoneError): + allowed.valid_name("mixture") + + +def test_allowed_domain_names_valid_name_raises_on_invalid_domain(): + zones_info = _DummyZonesInfo(domains=["mixture"], domain_id_map={"mixture": 1}) + allowed = _AllowedDomainNames(_DummySVInfo(zones_info)) + with pytest.raises(ZoneError): + allowed.valid_name("nonexistent") + + @pytest.mark.fluent_version(">=23.2") def test_solution_variables(new_solver_session): solver = new_solver_session From 0ade6a8b3dd4e09461e3b27e589b5dcc70a1f136 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:44:06 +0000 Subject: [PATCH 3/4] Add DomainError class and use it in _AllowedDomainNames.valid_name (per PR #5048) Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/7cf80380-e40d-4804-b766-bab5a89d01f4 Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com> --- .../core/services/solution_variables.py | 19 ++++++++++++++++--- tests/test_solution_variables.py | 6 +++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ansys/fluent/core/services/solution_variables.py b/src/ansys/fluent/core/services/solution_variables.py index 1f08f0e4e19..68c544376e9 100644 --- a/src/ansys/fluent/core/services/solution_variables.py +++ b/src/ansys/fluent/core/services/solution_variables.py @@ -327,6 +327,19 @@ def __init__(self, zone_name: str, allowed_values: List[str]): ) +class DomainError(ValueError): + """Exception class for errors in domain name.""" + + def __init__(self, domain_name: str, allowed_values: List[str]): + """Initialize DomainError.""" + self.domain_name = domain_name + super().__init__( + allowed_name_error_message( + context="domain", trial_name=domain_name, allowed_values=allowed_values + ) + ) + + class _AllowedNames: def is_valid(self, name): """Check whether a given name is valid or not.""" @@ -422,14 +435,14 @@ def valid_name(self, domain_name): Raises ------ - ZoneError + DomainError If the given domain name is invalid. """ domain_id = self._zones_info.domain_id(domain_name) if domain_id is not None: return domain_id - raise ZoneError( - zone_name=domain_name, + raise DomainError( + domain_name=domain_name, allowed_values=self(), ) diff --git a/tests/test_solution_variables.py b/tests/test_solution_variables.py index e2dbabdeae5..7a87952c7f0 100644 --- a/tests/test_solution_variables.py +++ b/tests/test_solution_variables.py @@ -26,7 +26,7 @@ from ansys.fluent.core import examples from ansys.fluent.core.examples.downloads import download_file from ansys.fluent.core.services.solution_variables import ( - ZoneError, + DomainError, _AllowedDomainNames, ) from ansys.units.variable_descriptor import VariableCatalog @@ -72,14 +72,14 @@ def test_allowed_domain_names_valid_name_domain_id_zero(): def test_allowed_domain_names_valid_name_raises_on_missing_domain_id(): zones_info = _DummyZonesInfo(domains=["mixture"], domain_id_map={}) allowed = _AllowedDomainNames(_DummySVInfo(zones_info)) - with pytest.raises(ZoneError): + with pytest.raises(DomainError): allowed.valid_name("mixture") def test_allowed_domain_names_valid_name_raises_on_invalid_domain(): zones_info = _DummyZonesInfo(domains=["mixture"], domain_id_map={"mixture": 1}) allowed = _AllowedDomainNames(_DummySVInfo(zones_info)) - with pytest.raises(ZoneError): + with pytest.raises(DomainError): allowed.valid_name("nonexistent") From 32fd4cd65ebd403e6d05490420b1384d0d54db7c Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Wed, 8 Apr 2026 10:37:48 +0000 Subject: [PATCH 4/4] chore: adding changelog file 5050.fixed.md [dependabot-skip] --- doc/changelog.d/5050.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/5050.fixed.md diff --git a/doc/changelog.d/5050.fixed.md b/doc/changelog.d/5050.fixed.md new file mode 100644 index 00000000000..302054a5d53 --- /dev/null +++ b/doc/changelog.d/5050.fixed.md @@ -0,0 +1 @@ +Invalid state and TypeError bug in \`_AllowedDomainNames.valid_name\`