improve config lookup when there are multiple possible locations

This specifically applies to all Mastodon extractors and all
extractors with a 'basecategory', i.e. 'booru', 'foolslide', etc.

Values inside those general config locations wouldn't be recognized
when a value with the same was set on the 'extractor' level.

For example 'extractor.mastodon.directory' should be used over
'extractor.directory' when both are set, but this was impossible
with the previous implementation.

(fixes #843)
This commit is contained in:
Mike Fährmann
2020-06-20 21:41:59 +02:00
parent 1b3870a4be
commit 53cc498d9c
4 changed files with 73 additions and 9 deletions

View File

@@ -68,6 +68,34 @@ class TestConfig(unittest.TestCase):
self.assertEqual(config.interpolate(("b",), "d", 1) , 2)
self.assertEqual(config.interpolate(("d",), "d", 1) , 2)
def test_interpolate_common(self):
def lookup():
return config.interpolate_common(
("Z1", "Z2"), (
("A1", "A2"),
("B1",),
("C1", "C2", "C3"),
), "KEY", "DEFAULT",
)
def test(path, value, expected=None):
config.set(path, "KEY", value)
self.assertEqual(lookup(), expected or value)
self.assertEqual(lookup(), "DEFAULT")
test(("Z1",), 1)
test(("Z1", "Z2"), 2)
test(("Z1", "Z2", "C1"), 3)
test(("Z1", "Z2", "C1", "C2"), 4)
test(("Z1", "Z2", "C1", "C2", "C3"), 5)
test(("Z1", "Z2", "B1"), 6)
test(("Z1", "Z2", "A1"), 7)
test(("Z1", "Z2", "A1", "A2"), 8)
test(("Z1", "A1", "A2"), 999, 8)
test(("Z1", "Z2", "A1", "A2", "A3"), 999, 8)
test((), 9)
def test_set(self):
config.set(() , "c", [1, 2, 3])
config.set(("b",) , "c", [1, 2, 3])