467d0418ff
geändert: README.md geändert: pyproject.toml geändert: src/config_parser/__init__.py neue Datei: src/config_parser/_configuration.py neue Datei: src/config_parser/exceptions.py neue Datei: src/config_parser/ini.py neue Datei: src/config_parser/json.py neue Datei: src/config_parser/parse/ini.py neue Datei: src/config_parser/parse/json.py neue Datei: tests/ini/test_ini.py neue Datei: tests/json/test.json neue Datei: tests/json/test_json.py neue Datei: tests/json/test_parser.py neue Datei: tests/test_configuration_class.py
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from src.config_parser.ini import INIConfiguration, INIConfigurationGroup
|
|
from src.config_parser.exceptions import INISyntaxError
|
|
|
|
def test_generating():
|
|
config = INIConfiguration()
|
|
config.test_group = INIConfigurationGroup('test_group')
|
|
config.test_group.key1 = 'value1'
|
|
config.test_group.key2 = 'value2'
|
|
assert config.to_string() == '''[test_group]
|
|
key1=value1
|
|
key2=value2'''
|
|
|
|
def test_parsing():
|
|
# Test deserializer
|
|
config_string = '''
|
|
property1 = 42
|
|
property2=123
|
|
|
|
[configuration_group1]
|
|
hello=world
|
|
key1=value1
|
|
|
|
[group2]
|
|
world=hel#lo
|
|
key2 = "val#ue2"
|
|
[]
|
|
hello2=world2
|
|
invalid_line1
|
|
|
|
invalid_line2
|
|
|
|
# comment'''
|
|
|
|
assert dict(INIConfiguration.from_string(config_string, ignore_errors=True)) == {'configuration_group1': {'hello': 'world', 'key1': 'value1'}, 'group2': {'world': 'hel', 'key2': 'val#ue2', 'hello2': 'world2'}}
|
|
|
|
try:
|
|
INIConfiguration.from_string('key="value')
|
|
assert False, 'Expected INISyntaxError for unterminated literal'
|
|
except INISyntaxError:
|
|
pass
|
|
|
|
try:
|
|
INIConfiguration.from_string('key=value"')
|
|
assert False, 'Expected INISyntaxError for unterminated literal'
|
|
except INISyntaxError:
|
|
pass |