@@ -53,6 +53,49 @@ class ConfigFileProcessor(ConfigFileReader):
53
53
schema = ConfigFileProcessor .select_config_schema_for ("unbounded.section" )
54
54
assert schema is None
55
55
56
+ @pytest .mark .parametrize ("section_name, expected_schema" , [
57
+ # -- SECTION NAME STARTS WITH: foo.*
58
+ ("foo.alice" , "schema1" ),
59
+ ("foo.bob" , "schema1" ),
60
+ # -- SECTION NAME ENDS WITH: *.foo
61
+ ("some.foo" , "schema2" ),
62
+ ("other.foo" , "schema2" ),
63
+ # -- SECTION NAME CONTAINS: *.foo.*
64
+ ("loo.foo.bar" , "schema3" ),
65
+ ("xxx.foo.zzz" , "schema3" ),
66
+ # -- UNBOUNDED/UNSUPPORTED: section names
67
+ ("foo_bar" , None ),
68
+ ("baz_foo" , None ),
69
+ ("xxx_foo_zzz" , None ),
70
+ ])
71
+ def test_select_config_schema_for__with_schema_using_wildcards (self ,
72
+ section_name , expected_schema ):
73
+ # -- SETUP:
74
+ @matches_section ("foo.*" )
75
+ class ExampleSchema1 (SectionSchema ):
76
+ schema_name = "schema1"
77
+
78
+ @matches_section ("*.foo" )
79
+ class ExampleSchema2 (SectionSchema ):
80
+ schema_name = "schema2"
81
+
82
+ @matches_section ("*.foo.*" )
83
+ class ExampleSchema3 (SectionSchema ):
84
+ schema_name = "schema3"
85
+
86
+ class ConfigFileProcessor (ConfigFileReader ):
87
+ config_section_schemas = [
88
+ ExampleSchema1 , ExampleSchema2 , ExampleSchema3 ]
89
+
90
+ # -- PERFORM TEST:
91
+ schema = ConfigFileProcessor .select_config_schema_for (section_name )
92
+ if expected_schema is None :
93
+ # -- UNBOUNDED SECTION (not supported; no mapping to schema provided)
94
+ assert schema is None
95
+ else :
96
+ # -- EXPECTED SECTION:
97
+ assert schema is not None
98
+ assert schema .schema_name == expected_schema
56
99
57
100
# -- TESTS FOR: ConfigFileReader.collect_config_sections_from_schemas()
58
101
def test_collect_config_sections_from_schemas__without_arg (self ):
0 commit comments