@@ -1106,8 +1106,12 @@ def test_alias_slot(schema_view_no_imports: SchemaView) -> None:
11061106 assert postal_code_slot .alias == "zip" # Assert alias is 'zip'
11071107
11081108
1109- def test_enums_and_enum_relationships (schema_view_no_imports : SchemaView ) -> None :
1110- """Test various aspects of Enum representation.
1109+ def test_permissible_value_relationships (schema_view_no_imports : SchemaView ) -> None :
1110+ """Test relationships between permissible values.
1111+
1112+ These tests use valid permissible_value / enum combinations.
1113+
1114+ See test_permissible_value_relationships_fail for invalid enum-PV pairings.
11111115
11121116 CAT:
11131117 LION:
@@ -1122,18 +1126,14 @@ def test_enums_and_enum_relationships(schema_view_no_imports: SchemaView) -> Non
11221126 """
11231127 view = schema_view_no_imports
11241128
1125- # Test for ValueError when passing incorrect parameters
1126- with pytest .raises (ValueError , match = 'No such enum: "not_an_enum"' ):
1127- view .permissible_value_parent ("not_a_pv" , "not_an_enum" )
1128-
11291129 animals = "Animals"
11301130 animal_enum = view .get_enum (animals )
11311131 assert animal_enum .name == animals
11321132
11331133 pv_cat = animal_enum .permissible_values ["CAT" ]
11341134 assert pv_cat .text == "CAT"
11351135 assert pv_cat .is_a is None
1136- assert view .permissible_value_parent ("CAT" , animals ) is None
1136+ assert view .permissible_value_parent ("CAT" , animals ) == []
11371137 assert view .permissible_value_ancestors ("CAT" , animals ) == ["CAT" ]
11381138 assert set (view .permissible_value_children ("CAT" , animals )) == {"LION" , "TABBY" }
11391139 assert set (view .permissible_value_descendants ("CAT" , animals )) == {"CAT" , "LION" , "ANGRY_LION" , "TABBY" }
@@ -1160,6 +1160,19 @@ def test_enums_and_enum_relationships(schema_view_no_imports: SchemaView) -> Non
11601160 assert view .permissible_value_descendants ("ANGRY_LION" , animals ) == ["ANGRY_LION" ]
11611161
11621162
1163+ @pytest .mark .parametrize ("fn" , ["parent" , "children" , "ancestors" , "descendants" ])
1164+ def test_permissible_value_relationships_fail (schema_view_no_imports : SchemaView , fn : str ) -> None :
1165+ """Test permissible_value relationships with incorrect enum/PV pairs."""
1166+ method_name = f"permissible_value_{ fn } "
1167+ # invalid enum
1168+ with pytest .raises (ValueError , match = 'No such enum: "invalid_enum"' ):
1169+ getattr (schema_view_no_imports , method_name )("invalid_pv" , "invalid_enum" )
1170+
1171+ # invalid pv, valid enum
1172+ with pytest .raises (ValueError , match = '"invalid_pv" is not a permissible value of the enum "Animals"' ):
1173+ getattr (schema_view_no_imports , method_name )("invalid_pv" , "Animals" )
1174+
1175+
11631176# FIXME: improve testing of dynamic enums
11641177def test_dynamic_enum (schema_view_with_imports : SchemaView ) -> None :
11651178 """Rudimentary test of dynamic enum."""
0 commit comments