improve type hint coverage, make ruff format compliant

This commit is contained in:
2025-09-28 00:31:32 -07:00
parent 2b0702fe36
commit 4d707b97e4
16 changed files with 997 additions and 1168 deletions

View File

@@ -1,10 +0,0 @@
def test_imports():
from symconf.runner import Runner
from symconf.reader import DictReader
from symconf.config import ConfigManager
from symconf.matching import Matcher, FilePart
from symconf.template import Template, FileTemplate, TOMLTemplate
from symconf import config
from symconf import reader
from symconf import util

View File

@@ -2,64 +2,64 @@ from pathlib import Path
from symconf import ConfigManager
config_dir = Path(
__file__, '..', 'test-config-dir/'
).resolve()
config_dir = Path(__file__, "..", "test-config-dir/").resolve()
cm = ConfigManager(config_dir)
def test_matching_configs_exact():
'''
Test matching exact style and scheme. Given strict mode not set (allowing relaxation
to "none"), the order of matching should be
def test_matching_configs_exact() -> None:
"""
Test matching exact style and scheme. Given strict mode not set (allowing
relaxation to "none"), the order of matching should be
1. (none, none) :: none-none.aaa
2. (none, scheme) :: none-light.aaa
3. (style, none) :: test-none.aaa
4. (style, scheme) :: test-light.ccc
Yielding "test-light.aaa", "test-light.ccc" (unique only on config pathname).
'''
Yielding "test-light.aaa", "test-light.ccc" (unique only on config
pathname).
"""
any_light = cm.get_matching_configs(
'test',
style='test',
scheme='light',
"test",
style="test",
scheme="light",
)
print(any_light)
assert len(any_light) == 2
assert any_light['aaa'].pathname == 'test-none.aaa'
assert any_light['ccc'].pathname == 'test-light.ccc'
assert any_light["aaa"].pathname == "test-none.aaa"
assert any_light["ccc"].pathname == "test-light.ccc"
def test_matching_configs_any_style():
'''
Test matching "any" style and exact scheme. Given strict mode not set (allowing
relaxation to "none"), the order of matching should be
def test_matching_configs_any_style() -> None:
"""
Test matching "any" style and exact scheme. Given strict mode not set
(allowing relaxation to "none"), the order of matching should be
1. (style, none) :: none-none.aaa, test-none.aaa
2. (none, none) :: none-none.aaa
3. (style, scheme) :: test-dark.bbb
4. (none, scheme) :: (nothing)
Yielding "none-none.aaa" (should always overwrite "test-none.aaa" due to "any"'s
preference for non-specific matches, i.e., "none"s), "test-none.ddd", "test-dark.bbb"
(unique only on config pathname).
'''
Yielding "none-none.aaa" (should always overwrite "test-none.aaa" due to
"any"'s preference for non-specific matches, i.e., "none"s),
"test-none.ddd", "test-dark.bbb" (unique only on config pathname).
"""
any_dark = cm.get_matching_configs(
'test',
style='any',
scheme='dark',
"test",
style="any",
scheme="dark",
)
assert len(any_dark) == 2
assert any_dark['aaa'].pathname == 'none-none.aaa'
assert any_dark['bbb'].pathname == 'test-dark.bbb'
assert any_dark["aaa"].pathname == "none-none.aaa"
assert any_dark["bbb"].pathname == "test-dark.bbb"
def test_matching_configs_any_scheme():
'''
Test matching exact style and "any" scheme. Given strict mode not set (allowing
relaxation to "none"), the order of matching should be
def test_matching_configs_any_scheme() -> None:
"""
Test matching exact style and "any" scheme. Given strict mode not set
(allowing relaxation to "none"), the order of matching should be
1. (none, scheme) :: none-light.aaa & none-none.aaa
2. (none, none) :: none-none.aaa
@@ -67,54 +67,64 @@ def test_matching_configs_any_scheme():
4. (style, none) :: test-none.aaa
Yielding "test-none.aaa", "test-light.ccc", "test-dark.bbb"
'''
"""
test_any = cm.get_matching_configs(
'test',
style='test',
scheme='any',
"test",
style="test",
scheme="any",
)
assert len(test_any) == 3
assert test_any['aaa'].pathname == 'test-none.aaa'
assert test_any['bbb'].pathname == 'test-dark.bbb'
assert test_any['ccc'].pathname == 'test-light.ccc'
assert test_any["aaa"].pathname == "test-none.aaa"
assert test_any["bbb"].pathname == "test-dark.bbb"
assert test_any["ccc"].pathname == "test-light.ccc"
def test_matching_scripts():
'''
Test matching exact style and scheme. Given strict mode not set (allowing relaxation
to "none"), the order of matching should be
def test_matching_scripts() -> None:
"""
Test matching exact style and scheme. Given strict mode not set (allowing
relaxation to "none"), the order of matching should be
1. (none, none) :: none-none.sh
2. (none, scheme) :: none-light.sh
3. (style, none) :: test-none.sh
4. (style, scheme) :: (nothing)
Yielding (ordered by dec specificity) "test-none.sh" as primary match, then relaxation
match "none-none.sh".
'''
Yielding (ordered by dec specificity) "test-none.sh" as primary match, then
relaxation match "none-none.sh".
"""
test_any = cm.get_matching_scripts(
'test',
style='test',
scheme='any',
"test",
style="test",
scheme="any",
)
assert len(test_any) == 2
assert list(map(lambda p:p.pathname, test_any)) == ['test-none.sh', 'none-none.sh']
assert [p.pathname for p in test_any] == [
"test-none.sh",
"none-none.sh",
]
any_light = cm.get_matching_scripts(
'test',
style='any',
scheme='light',
"test",
style="any",
scheme="light",
)
assert len(any_light) == 2
assert list(map(lambda p:p.pathname, any_light)) == ['none-light.sh', 'none-none.sh']
assert [p.pathname for p in any_light] == [
"none-light.sh",
"none-none.sh",
]
any_dark = cm.get_matching_scripts(
'test',
style='any',
scheme='dark',
"test",
style="any",
scheme="dark",
)
assert len(any_dark) == 2
assert list(map(lambda p:p.pathname, any_dark)) == ['test-none.sh', 'none-none.sh']
assert [p.pathname for p in any_dark] == [
"test-none.sh",
"none-none.sh",
]

View File

@@ -2,30 +2,47 @@ from pathlib import Path
from symconf import Template, TOMLTemplate
def test_template_fill():
def test_template_fill() -> None:
# test simple replacment
assert Template('f{{a}} - f{{b}}').fill({
'a': 1,
'b': 2,
}) == '1 - 2'
assert (
Template("f{{a}} - f{{b}}").fill(
{
"a": 1,
"b": 2,
}
)
== "1 - 2"
)
# test nested brackets (using default pattern)
assert Template('{{ f{{a}} - f{{b}} }}').fill({
'a': 1,
'b': 2,
}) == '{{ 1 - 2 }}'
assert (
Template("{{ f{{a}} - f{{b}} }}").fill(
{
"a": 1,
"b": 2,
}
)
== "{{ 1 - 2 }}"
)
# test tight nested brackets (requires greedy quantifier)
assert Template('{{f{{a}} - f{{b}}}}').fill({
'a': 1,
'b': 2,
}) == '{{1 - 2}}'
assert (
Template("{{f{{a}} - f{{b}}}}").fill(
{
"a": 1,
"b": 2,
}
)
== "{{1 - 2}}"
)
def test_toml_template_fill():
def test_toml_template_fill() -> None:
test_group_dir = Path(
__file__, '..', 'test-config-dir/groups/test/'
__file__, "..", "test-config-dir/groups/test/"
).resolve()
stacked_dict = TOMLTemplate.stack_toml(test_group_dir.iterdir())
assert stacked_dict == {'base':'aaa','concrete':'zzz'}
assert stacked_dict == {"base": "aaa", "concrete": "zzz"}