Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

schemaview.py: make permissible_value_* act consistently with other such methods - #467

Merged
kevinschaper merged 2 commits into
mainfrom
schemaview_pv_fn_edits
Oct 7, 2025
Merged

kevinschaper merged 2 commits into
mainfrom
schemaview_pv_fn_edits

Conversation

@ialarmedalien

Copy link
Copy Markdown
Collaborator

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_parent method 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 returning None.

Note: the naming of this method is inconsistent with the other parent terms and should be fixed at some point.

Comment on lines -1067 to -1070
# 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")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved into their own test, below

@codecov

codecov Bot commented Oct 7, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.48%. Comparing base (89e17c7) to head (881a0ad).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other *_parents functions return an empty list, so edit this to do the same thing.

Comment on lines +829 to +832
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)

@ialarmedalien ialarmedalien Oct 7, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_enum(enum_name, strict=True) throws an error if enum is not found, so checking for enum is unnecessary

Comment on lines +850 to +852
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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list comprehension does the same thing as the for loop in the original

Comment on lines -856 to -857
msg = f'No such enum as "{enum_name}"'
raise ValueError(msg)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will never be called -- made redundant by get_enum(enum_name, strict=True)

@ialarmedalien ialarmedalien added bug Something isn't working enhancement New feature or request testing labels Oct 7, 2025
@kevinschaper
kevinschaper merged commit 878d01e into main Oct 7, 2025
17 checks passed
@kevinschaper
kevinschaper deleted the schemaview_pv_fn_edits branch October 7, 2025 21:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working enhancement New feature or request testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants