@@ -1328,8 +1328,12 @@ def test_alias_slot(schema_view_no_imports: SchemaView) -> None:
13281328 assert postal_code_slot .alias == "zip" # Assert alias is 'zip'
13291329
13301330
1331- def test_enums_and_enum_relationships (schema_view_no_imports : SchemaView ) -> None :
1332- """Test various aspects of Enum representation.
1331+ def test_permissible_value_relationships (schema_view_no_imports : SchemaView ) -> None :
1332+ """Test relationships between permissible values.
1333+
1334+ These tests use valid permissible_value / enum combinations.
1335+
1336+ See test_permissible_value_relationships_fail for invalid enum-PV pairings.
13331337
13341338 CAT:
13351339 LION:
@@ -1344,18 +1348,14 @@ def test_enums_and_enum_relationships(schema_view_no_imports: SchemaView) -> Non
13441348 """
13451349 view = schema_view_no_imports
13461350
1347- # Test for ValueError when passing incorrect parameters
1348- with pytest .raises (ValueError , match = 'No such enum: "not_an_enum"' ):
1349- view .permissible_value_parent ("not_a_pv" , "not_an_enum" )
1350-
13511351 animals = "Animals"
13521352 animal_enum = view .get_enum (animals )
13531353 assert animal_enum .name == animals
13541354
13551355 pv_cat = animal_enum .permissible_values ["CAT" ]
13561356 assert pv_cat .text == "CAT"
13571357 assert pv_cat .is_a is None
1358- assert view .permissible_value_parent ("CAT" , animals ) is None
1358+ assert view .permissible_value_parent ("CAT" , animals ) == []
13591359 assert view .permissible_value_ancestors ("CAT" , animals ) == ["CAT" ]
13601360 assert set (view .permissible_value_children ("CAT" , animals )) == {"LION" , "TABBY" }
13611361 assert set (view .permissible_value_descendants ("CAT" , animals )) == {"CAT" , "LION" , "ANGRY_LION" , "TABBY" }
@@ -1382,6 +1382,19 @@ def test_enums_and_enum_relationships(schema_view_no_imports: SchemaView) -> Non
13821382 assert view .permissible_value_descendants ("ANGRY_LION" , animals ) == ["ANGRY_LION" ]
13831383
13841384
1385+ @pytest .mark .parametrize ("fn" , ["parent" , "children" , "ancestors" , "descendants" ])
1386+ def test_permissible_value_relationships_fail (schema_view_no_imports : SchemaView , fn : str ) -> None :
1387+ """Test permissible_value relationships with incorrect enum/PV pairs."""
1388+ method_name = f"permissible_value_{ fn } "
1389+ # invalid enum
1390+ with pytest .raises (ValueError , match = 'No such enum: "invalid_enum"' ):
1391+ getattr (schema_view_no_imports , method_name )("invalid_pv" , "invalid_enum" )
1392+
1393+ # invalid pv, valid enum
1394+ with pytest .raises (ValueError , match = '"invalid_pv" is not a permissible value of the enum "Animals"' ):
1395+ getattr (schema_view_no_imports , method_name )("invalid_pv" , "Animals" )
1396+
1397+
13851398# FIXME: improve testing of dynamic enums
13861399def test_dynamic_enum (schema_view_with_imports : SchemaView ) -> None :
13871400 """Rudimentary test of dynamic enum."""
0 commit comments