Fix broken diameter-range validation in getLineProps#67
Merged
Conversation
Two bugs prevented getLineProps from validating the nominal diameter against a material's d_min / d_max bounds: 1. The range checks referenced the diameter `d` before it was assigned (`d = dnommm*0.001` came after the checks), so any material with d_min >= 0 or d_max >= 0 raised UnboundLocalError instead of the intended out-of-range Exception. Move the conversion above the checks. 2. loadLineProps read d_max from the key 'd_dmax' (a typo), so a user-specified d_max was silently dropped to the -1 'disabled' default and the upper-bound check never fired. Read 'd_max'. Adds a regression test covering in-range success and both the d_min and d_max out-of-range Exceptions.
Collaborator
|
These are helpful bug fixes that were not addressed when these pieces of code were first implemented, and, as stated, do not come up during normal MoorPy operations. |
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.
Two bugs prevent
getLinePropsfrom validating the nominal diameter against a material'sd_min/d_maxbounds.Bug 1 —
dreferenced before assignmentIn
getLineProps(helpers.py) the diameter-range checks usedbefore it is defined:So for any material whose
d_min >= 0ord_max >= 0, the call raisesUnboundLocalError: cannot access local variable 'd'instead of the intended out-of-rangeException. Fixed by moving thed = dnommm*0.001conversion above the checks.Bug 2 —
d_maxtypo inloadLinePropsThe key
'd_dmax'never exists, so a user-specifiedd_maxis silently dropped to the-1"disabled" default and the upper-bound check never fires. Fixed by reading'd_max'.The two bugs masked each other: because
d_maxalways fell back to-1, thed > mat['d_max']branch of Bug 1 never executed with the default database, so the crash only surfaced viad_min.Reproduction (before this PR)
After this PR
d_maxfrom the source is honoured.Exception("… less than the min valid value …" / "… greater than the max valid value …") for both bounds.d_min/d_maxset) are unaffected.Verification
tests/test_line.py::test_getLineProps_diameter_limitscovers the in-range success path and both thed_minandd_maxout-of-range Exceptions. It fails ondev(UnboundLocalError) and passes with this fix.29 passed.