geändert: .gitignore

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
This commit is contained in:
2026-02-07 15:28:28 +01:00
parent d34c40e52a
commit 467d0418ff
15 changed files with 1937 additions and 54 deletions
+46
View File
@@ -0,0 +1,46 @@
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