Repository navigation
schemaview.py: make permissible_value_* act consistently with other such methods - #467
Conversation
…ble value pairing is incorrect.
| # Test for ValueError when passing incorrect parameters | ||
| with pytest.raises(ValueError, match='No such enum: "not_an_enum"'): | ||
| view.permissible_value_parent("not_a_pv", "not_an_enum") | ||
|
|
There was a problem hiding this comment.
moved into their own test, below
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #467 +/- ##
==========================================
+ Coverage 77.37% 77.48% +0.11%
==========================================
Files 52 52
Lines 4473 4464 -9
Branches 975 970 -5
==========================================
- Hits 3461 3459 -2
+ Misses 785 781 -4
+ Partials 227 224 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| pv_cat = animal_enum.permissible_values["CAT"] | ||
| assert pv_cat.text == "CAT" | ||
| assert pv_cat.is_a is None | ||
| assert view.permissible_value_parent("CAT", animals) is None |
There was a problem hiding this comment.
All other *_parents functions return an empty list, so edit this to do the same thing.
| pv = enum.permissible_values.get(permissible_value) | ||
| if not pv: | ||
| err_msg = f'"{permissible_value}" is not a permissible value of the enum "{enum_name}".' | ||
| raise ValueError(err_msg) |
There was a problem hiding this comment.
raise error if the enum/PV combo is invalid, which is more informative than returning an empty list or None, and in line with the error checking when retrieving the enum.
| :return: all direct parent enum names (is_a) | ||
| """ | ||
| enum = self.get_enum(enum_name, strict=True) | ||
| if enum: |
There was a problem hiding this comment.
get_enum(enum_name, strict=True) throws an error if enum is not found, so checking for enum is unnecessary
| isa_pv | ||
| for isa_pv, isa_pv_entity in enum.permissible_values.items() | ||
| if isa_pv_entity.is_a and pv.text == isa_pv_entity.is_a |
There was a problem hiding this comment.
list comprehension does the same thing as the for loop in the original
| msg = f'No such enum as "{enum_name}"' | ||
| raise ValueError(msg) |
There was a problem hiding this comment.
will never be called -- made redundant by get_enum(enum_name, strict=True)
Two changes:
Throw an error if the permissible value supplied in the query is not a PV of the enum.
Change the functioning of the
permissible_value_parentmethod to return an empty list if the PV has no parents, which is what other*_parents(class_parents,type_parents,slot_parents, etc.) do. It was previously returningNone.Note: the naming of this method is inconsistent with the other parent terms and should be fixed at some point.