config/test_config.py: add test for saving modifications
This commit is contained in:
parent
5e9b0448dc
commit
4298d15178
1 changed files with 25 additions and 4 deletions
|
@ -105,6 +105,16 @@ def compare_to_defaults(config: dict, defaults: dict = CONFIG_DEFAULTS):
|
||||||
assert dict_filter_out_None(section_defaults[key]) == section_values_config[key]
|
assert dict_filter_out_None(section_defaults[key]) == section_values_config[key]
|
||||||
|
|
||||||
|
|
||||||
|
def load_toml_file(path) -> dict:
|
||||||
|
with open(path, 'r') as f:
|
||||||
|
text = f.read()
|
||||||
|
assert text
|
||||||
|
return toml.loads(text)
|
||||||
|
|
||||||
|
def get_path_from_stateholder(c: ConfigStateHolder):
|
||||||
|
return c.runtime['config_file']
|
||||||
|
|
||||||
|
|
||||||
def test_config_save_nonexistant(configstate_nonexistant: ConfigStateHolder):
|
def test_config_save_nonexistant(configstate_nonexistant: ConfigStateHolder):
|
||||||
c = configstate_nonexistant
|
c = configstate_nonexistant
|
||||||
confpath = c.runtime['config_file']
|
confpath = c.runtime['config_file']
|
||||||
|
@ -112,14 +122,25 @@ def test_config_save_nonexistant(configstate_nonexistant: ConfigStateHolder):
|
||||||
c.write()
|
c.write()
|
||||||
assert confpath
|
assert confpath
|
||||||
assert os.path.exists(confpath)
|
assert os.path.exists(confpath)
|
||||||
with open(confpath, 'r') as f:
|
loaded = load_toml_file(confpath)
|
||||||
text = f.read()
|
assert loaded
|
||||||
assert text
|
|
||||||
loaded = toml.loads(text)
|
|
||||||
# sadly we can't just assert `loaded == CONFIG_DEFAULTS` due to `None` values
|
# sadly we can't just assert `loaded == CONFIG_DEFAULTS` due to `None` values
|
||||||
compare_to_defaults(loaded)
|
compare_to_defaults(loaded)
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_save_modified(configstate_emptyfile: ConfigStateHolder):
|
||||||
|
c = configstate_emptyfile
|
||||||
|
WRAPPER_KEY = 'wrapper'
|
||||||
|
TYPE_KEY = 'type'
|
||||||
|
assert WRAPPER_KEY in c.file
|
||||||
|
assert TYPE_KEY in c.file[WRAPPER_KEY]
|
||||||
|
wrapper_section = CONFIG_DEFAULTS[WRAPPER_KEY] | {TYPE_KEY: 'none'}
|
||||||
|
c.file[WRAPPER_KEY] |= wrapper_section
|
||||||
|
c.write()
|
||||||
|
defaults_modified = CONFIG_DEFAULTS | {WRAPPER_KEY: wrapper_section}
|
||||||
|
compare_to_defaults(load_toml_file(get_path_from_stateholder(c)), defaults_modified)
|
||||||
|
|
||||||
|
|
||||||
def test_profile():
|
def test_profile():
|
||||||
p = None
|
p = None
|
||||||
p = Profile()
|
p = Profile()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue