Repository navigation
fix: raise clear ValueError for unsupported MemoryUnit - #1336
Merged
Merged
Conversation
Contributor
Co-authored-by: Revathy Venugopal <[email protected]>
koubaa
approved these changes
Sep 18, 2026
Revathyvenugopal162
approved these changes
Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a mirror pull request created from fix: raise clear ValueError for unsupported MemoryUnit to allow the code to access PyDyna CICD secrets.
Check the original PR made by @guhou-hvi for more details.
Closes #1334
Original pull request
fix: raise clear ValueError for unsupported MemoryUnit
Summary
BaseRunner.get_memory_string()raises a bareKeyErrorfor anyMemoryUnitother thanMB/GB. This PR replaces that with a clearValueErrormatching what the enum docstring already promises.Root cause
MemoryUnitinsrc/ansys/dyna/core/run/options.pydefines five values:But
get_memory_string()only maps two of them:Passing
MemoryUnit.BYTE,KB, orTB(or any other value) raises:MemoryUnitis a plain class of ints, so the message is just the raw integer — it doesn't mention which enum member was used, doesn't list what's supported, and doesn't align with the docstring's "Only MB and GB are currently supported" promise. All three concrete runners (LinuxRunner,WindowsRunner,DockerRunner) callself.get_memory_string()while building the command line, so the failure surfaces late and looks like an internal lookup error.Changes
src/ansys/dyna/core/run/base_runner.py:Hoist the supported units map into a local
unitsdict.Check membership explicitly and raise
ValueErrorwith the offending value and the supported names:Return
f"{self.memory}{units[self.memory_unit]}"unchanged for supported units.tests/test_base_runner.py(new):test_memory_string_supported– parameterised overMB→"20m"andGB→"20G".test_memory_string_unsupported_raises_value_error– parameterised overBYTE,KB,TB; assertsValueErrorwith the supported-units message.test_memory_string_error_mentions_offending_value– checks the message includes the value the caller passed.test_memory_string_default_is_mb– pins the default fromBaseRunner.__init__.The new tests are pure mocks (no solver, no Docker, no filesystem) and deliberately do not carry
pytest.mark.run, so they execute in the default unit test matrix (pytest -m "not codegen and not run"in CI) rather than only in the solver-backed job.Testing
pytest tests/test_base_runner.py -vpytest tests/test_localrun.py tests/test_windows_runner.py -m runruff check src testsruff format --checkThe two
test_localrun.pyfailures are pre-existing environmental issues on this machine, unrelated to this change:test_find_solver_with_version– expects Ansys 231, host has 221.test_find_solver_latest_install– Linux-style path separator (/) asserted against Windowsos.path.joinoutput (\).Impact
Callers that today pass
MemoryUnit.BYTE/KB/TBwill receive aValueErrorinstead of aKeyError.ValueErroris a subclass ofException, so any code catching the generalExceptionstill works; code specifically catchingKeyError(unlikely — the raw message gives no hint that this is a supported-units issue) would need to update. Default (MemoryUnit.MB) andMemoryUnit.GBbehaviour is unchanged.Scope
Only
BaseRunner.get_memory_string()changes. No modification toMemoryUnititself, the three concrete runners, or any docstring in this PR. Relatedlocal_solver.pyfollow-up (env var robustness) is being tracked separately and does not conflict.