-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Papercut: enumify text based choices #3021
Papercut: enumify text based choices #3021
Conversation
@oliverfunk Could you please review the papercut PR? |
|
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #3021 +/- ##
===========================================
- Coverage 79.79% 79.43% -0.37%
===========================================
Files 226 226
Lines 25120 25273 +153
===========================================
+ Hits 20045 20076 +31
- Misses 5075 5197 +122 ☔ View full report in Codecov by Sentry. |
Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com>
Quality Gate passedIssues Measures |
519f50f
into
Fusion-Power-Plant-Framework:develop
* ✅ Enumification of text based choices in bluemira.fuel_cycle * ✅ enumified text choices in bluemira.geometry * fied pf_coil.py * ✅ enumify text based choices in bluemira.equilibria * ✅ enumify text based choices in bluemira.structural * ✅ enumify some text based choics in eudemo.eudemo * 🐛 fix circular import * 🐛 Fix Failing test_coordinates.py * 🐛 Fix failing test_tools.py * 🐛 fix failing test_pyclipper_offset.py * 🐛 remove plane=None test from test_KeyError_if_invalid_plane * 🚨 Fix test function name * Update bluemira/builders/pf_coil.py Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com> * ✅ Modify codes to resolve reviewer's comments * ✅ remove unnecessary .upper(), and a few name changes * 🐛 fix failing test_model.py * 🐛 further cleanup * 🐛 fix circular import error and duplication of CoilType * updated docstrings --------- Co-authored-by: Athoy Nilima <athoy.nilima@ukaea.uk> Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com> Co-authored-by: Oliver Funk <oli.funk@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few problems here.
Add them to #3036 for the fixes also all of the docstrings that start with 'Enumeration of ....' should be changed
except KeyError: | ||
raise ValueError( | ||
"Please select a numerical stabilisation strategy" | ||
' from: 1) "virtual" \n 2) "feedback" 3) None.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please autofill the options with the cls._member_names_
attribute eg
f"{*cls._member_names_,}"
also the error message sounds like the user can input something (which they can't). Maybe something like:
f"{cls.__name__} has no strategy {value} please select from {*cls._member_names_,}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FEEDBACK = auto() | ||
|
||
@classmethod | ||
def _missing_(cls, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typing of value is missing def _missing_(cls, value: str):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.controller = VirtualController(self, gz=2.2) | ||
elif vcontrol_type is VerticalPositionControlType.FEEDBACK: | ||
raise NotImplementedError | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this error message will never be hit as it will error on L1073 on the initialisation of the enum, please remove the else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try: | ||
return cls[value.upper()] | ||
except KeyError: | ||
raise ValueError(f"{value} is a wrong ReactorType. Choose from: ST or Normal") from None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as previous enum comments, no typing on value and error message:
f"{cls.__name__} has no entry {value} please select from {*cls._member_names_,}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return cls[value.upper()] | ||
except KeyError: | ||
raise StructuralError( | ||
f"Unknown SubLoad type {value}. Choose from: force, moment or all" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typing and error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from bluemira.structural.error import StructuralError | ||
from bluemira.structural.geometry import Geometry | ||
from bluemira.structural.loads import LoadCase | ||
from bluemira.structural.result import Result | ||
from bluemira.structural.symmetry import CyclicSymmetry | ||
|
||
|
||
class BoundaryConditionMethodType(Enum): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename BoundaryConditionMethod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -524,8 +547,8 @@ def _apply_boundary_conditions( | |||
k = np.delete(k, i, axis=0) | |||
k = np.delete(k, i, axis=1) | |||
p = np.delete(p, i) | |||
else: | |||
raise StructuralError(f"Unrecognised method: {method}.") | |||
# else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this commented out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blanket_pump_strat = H2OPumping( | ||
0.005, | ||
eta_isentropic=params.bb_pump_eta_isen.value, | ||
eta_electric=params.bb_pump_eta_el.value, | ||
) | ||
bop_cycle = PredeterminedEfficiency(0.33) | ||
else: | ||
raise ValueError(f"Unrecognised blanket type {params.blanket_type.value}") | ||
# else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this commented out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -456,12 +456,13 @@ def test_hull_around_two_circles_xy_plane(self): | |||
bounding_box = hull.bounding_box | |||
assert bounding_box.z_min == bounding_box.z_max == 0 | |||
|
|||
@pytest.mark.parametrize("bad_plane", ["ab", "", None, ["x", "y"]]) | |||
@pytest.mark.parametrize("bad_plane", ["ab", "", ["x", "y"]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test case shouldnt be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* ✅ Enumification of text based choices in bluemira.fuel_cycle * ✅ enumified text choices in bluemira.geometry * fied pf_coil.py * ✅ enumify text based choices in bluemira.equilibria * ✅ enumify text based choices in bluemira.structural * ✅ enumify some text based choics in eudemo.eudemo * 🐛 fix circular import * 🐛 Fix Failing test_coordinates.py * 🐛 Fix failing test_tools.py * 🐛 fix failing test_pyclipper_offset.py * 🐛 remove plane=None test from test_KeyError_if_invalid_plane * 🚨 Fix test function name * Update bluemira/builders/pf_coil.py Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com> * ✅ Modify codes to resolve reviewer's comments * ✅ remove unnecessary .upper(), and a few name changes * 🐛 fix failing test_model.py * 🐛 further cleanup * 🐛 fix circular import error and duplication of CoilType * updated docstrings --------- Co-authored-by: Athoy Nilima <athoy.nilima@ukaea.uk> Co-authored-by: Oliver Funk <oliverfunk@users.noreply.github.com> Co-authored-by: Oliver Funk <oli.funk@gmail.com>
Linked Issues
Text based choices should be verified for spelling etc, enums will provide that functionality or possibly class attributes
Closes #{1044}
Description
Emunified a number of text based choices in several modules.
Interface Changes
Checklist
I confirm that I have completed the following checks:
pytest tests --reactor
pre-commit run --from-ref develop --to-ref HEAD
sphinx-build -W documentation/source documentation/build