large refactor (break up ConfigManager), add more tests
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
[app.test]
|
||||
config_dir = 'sym_tgt/test'
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark'
|
||||
@@ -1 +0,0 @@
|
||||
gsettings set org.gnome.desktop.interface color-scheme 'prefer-light'
|
||||
@@ -1 +1 @@
|
||||
echo "> none-light ran"
|
||||
echo "none-light ran"
|
||||
|
||||
@@ -1 +1 @@
|
||||
echo "> none-none ran"
|
||||
echo "none-none ran"
|
||||
|
||||
1
tests/test-config-dir/groups/test/none.toml
Normal file
1
tests/test-config-dir/groups/test/none.toml
Normal file
@@ -0,0 +1 @@
|
||||
base = "aaa"
|
||||
1
tests/test-config-dir/groups/test/test.toml
Normal file
1
tests/test-config-dir/groups/test/test.toml
Normal file
@@ -0,0 +1 @@
|
||||
concrete = "zzz"
|
||||
@@ -1,132 +0,0 @@
|
||||
from pathlib import Path
|
||||
from symconf import ConfigManager
|
||||
|
||||
|
||||
config_dir = Path(
|
||||
__file__, '..', 'test-config-dir/'
|
||||
).resolve()
|
||||
cm = ConfigManager(config_dir)
|
||||
|
||||
def test_config_map():
|
||||
file_map = cm.app_config_map('test')
|
||||
|
||||
# from user
|
||||
assert 'none-none.aaa' in file_map
|
||||
assert 'none-light.aaa' in file_map
|
||||
assert 'test-dark.bbb' in file_map
|
||||
assert 'test-light.ccc' in file_map
|
||||
|
||||
# from generated
|
||||
assert 'test-none.aaa' in file_map
|
||||
|
||||
def test_matching_configs_exact():
|
||||
'''
|
||||
Test matching exact palette 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. (palette, none) :: test-none.aaa & test-none.ddd
|
||||
4. (palette, scheme) :: test-light.ccc
|
||||
|
||||
Yielding "test-none.aaa", "test-light.ccc", "test-none.ddd" (unique only on path name).
|
||||
'''
|
||||
any_light = cm.get_matching_configs(
|
||||
'test',
|
||||
palette='test',
|
||||
scheme='light',
|
||||
)
|
||||
|
||||
assert len(any_light) == 3
|
||||
assert any_light['aaa'].name == 'test-none.aaa'
|
||||
assert any_light['ccc'].name == 'test-light.ccc'
|
||||
assert any_light['ddd'].name == 'test-none.ddd'
|
||||
|
||||
def test_matching_configs_any_palette():
|
||||
'''
|
||||
Test matching exact palette and scheme. Given strict mode not set (allowing relaxation
|
||||
to "none"), the order of matching should be
|
||||
|
||||
1. (palette, none) :: test-none.aaa & test-none.ddd & none-none.aaa
|
||||
2. (none, none) :: none-none.aaa
|
||||
3. (palette, 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 path name).
|
||||
'''
|
||||
any_dark = cm.get_matching_configs(
|
||||
'test',
|
||||
palette='any',
|
||||
scheme='dark',
|
||||
)
|
||||
|
||||
assert len(any_dark) == 3
|
||||
assert any_dark['aaa'].name == 'none-none.aaa'
|
||||
assert any_dark['bbb'].name == 'test-dark.bbb'
|
||||
assert any_dark['ddd'].name == 'test-none.ddd'
|
||||
|
||||
def test_matching_configs_any_scheme():
|
||||
'''
|
||||
Test matching exact palette and 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
|
||||
3. (palette, scheme) :: test-dark.bbb & test-light.ccc & test-none.aaa & test-none.ddd
|
||||
4. (palette, none) :: test-none.aaa & test-none.ddd
|
||||
|
||||
Yielding "test-none.aaa", "test-none.ddd", "test-light.ccc", "test-dark.bbb"
|
||||
'''
|
||||
test_any = cm.get_matching_configs(
|
||||
'test',
|
||||
palette='test',
|
||||
scheme='any',
|
||||
)
|
||||
|
||||
assert len(test_any) == 4
|
||||
assert test_any['aaa'].name == 'test-none.aaa'
|
||||
assert test_any['bbb'].name == 'test-dark.bbb'
|
||||
assert test_any['ccc'].name == 'test-light.ccc'
|
||||
assert test_any['ddd'].name == 'test-none.ddd'
|
||||
|
||||
def test_matching_scripts():
|
||||
'''
|
||||
Test matching exact palette 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. (palette, none) :: test-none.sh
|
||||
4. (palette, scheme) :: (nothing)
|
||||
|
||||
Yielding (ordered by dec specificity) "test-none.sh" as primary match, then relaxation
|
||||
match "none-none.sh".
|
||||
'''
|
||||
test_any = cm.get_matching_scripts(
|
||||
'test',
|
||||
palette='test',
|
||||
scheme='any',
|
||||
)
|
||||
|
||||
assert len(test_any) == 2
|
||||
assert list(map(lambda p:p.name, test_any)) == ['test-none.sh', 'none-none.sh']
|
||||
|
||||
any_light = cm.get_matching_scripts(
|
||||
'test',
|
||||
palette='any',
|
||||
scheme='light',
|
||||
)
|
||||
|
||||
assert len(any_light) == 2
|
||||
assert list(map(lambda p:p.name, any_light)) == ['none-light.sh', 'none-none.sh']
|
||||
|
||||
any_dark = cm.get_matching_scripts(
|
||||
'test',
|
||||
palette='any',
|
||||
scheme='dark',
|
||||
)
|
||||
|
||||
assert len(any_dark) == 2
|
||||
assert list(map(lambda p:p.name, any_dark)) == ['test-none.sh', 'none-none.sh']
|
||||
@@ -1,5 +1,11 @@
|
||||
def test_imports():
|
||||
from symconf import ConfigManager
|
||||
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 theme
|
||||
from symconf import util
|
||||
|
||||
120
tests/test_matching.py
Normal file
120
tests/test_matching.py
Normal file
@@ -0,0 +1,120 @@
|
||||
from pathlib import Path
|
||||
|
||||
from symconf import ConfigManager
|
||||
|
||||
|
||||
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
|
||||
|
||||
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).
|
||||
'''
|
||||
any_light = cm.get_matching_configs(
|
||||
'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'
|
||||
|
||||
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
|
||||
|
||||
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).
|
||||
'''
|
||||
any_dark = cm.get_matching_configs(
|
||||
'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'
|
||||
|
||||
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
|
||||
|
||||
1. (none, scheme) :: none-light.aaa & none-none.aaa
|
||||
2. (none, none) :: none-none.aaa
|
||||
3. (style, scheme) :: test-dark.bbb & test-light.ccc & test-none.aaa
|
||||
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',
|
||||
)
|
||||
|
||||
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'
|
||||
|
||||
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
|
||||
|
||||
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".
|
||||
'''
|
||||
test_any = cm.get_matching_scripts(
|
||||
'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']
|
||||
|
||||
any_light = cm.get_matching_scripts(
|
||||
'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']
|
||||
|
||||
any_dark = cm.get_matching_scripts(
|
||||
'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']
|
||||
31
tests/test_template.py
Normal file
31
tests/test_template.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from pathlib import Path
|
||||
|
||||
from symconf import Template, TOMLTemplate
|
||||
|
||||
def test_template_fill():
|
||||
# test simple replacment
|
||||
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 }}'
|
||||
|
||||
# test tight nested brackets (requires greedy quantifier)
|
||||
assert Template('{{f{{a}} - f{{b}}}}').fill({
|
||||
'a': 1,
|
||||
'b': 2,
|
||||
}) == '{{1 - 2}}'
|
||||
|
||||
def test_toml_template_fill():
|
||||
test_group_dir = Path(
|
||||
__file__, '..', 'test-config-dir/groups/test/'
|
||||
).resolve()
|
||||
|
||||
stacked_dict = TOMLTemplate.stack_toml(test_group_dir.iterdir())
|
||||
|
||||
assert stacked_dict == {'base':'aaa','concrete':'zzz'}
|
||||
Reference in New Issue
Block a user