Skip to content

Commit ca918b9

Browse files
committed
Add test with schemas that use wildcards (in @matches_section).
1 parent a1056e2 commit ca918b9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tests/unit/test_configfile_reader.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,49 @@ class ConfigFileProcessor(ConfigFileReader):
5353
schema = ConfigFileProcessor.select_config_schema_for("unbounded.section")
5454
assert schema is None
5555

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
5699

57100
# -- TESTS FOR: ConfigFileReader.collect_config_sections_from_schemas()
58101
def test_collect_config_sections_from_schemas__without_arg(self):

0 commit comments

Comments
 (0)