Support for mutable and immutable configurations

This commit is contained in:
2026-03-12 19:08:37 +01:00
parent 71fa689945
commit 66cbb21941
7 changed files with 176 additions and 18 deletions
+24 -1
View File
@@ -14,6 +14,7 @@
from src.config_parser.ini import INIConfiguration, INIConfigurationSection
from src.config_parser.exceptions import INISyntaxError
from src.config_parser import set_mutability
def test_generating():
config = INIConfiguration()
@@ -71,4 +72,26 @@ l2=w2''')
assert dict(INIConfiguration.from_string('''[section1]
k1=v1
k2=v2
k4=v4''', default = default_configuration)) == {'section1': {'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'}, 'section2': {'l1': 'w1', 'l2': 'w2'}}
k4=v4''', default = default_configuration)) == {'section1': {'k1': 'v1', 'k2': 'v2', 'k3': 'v3', 'k4': 'v4'}, 'section2': {'l1': 'w1', 'l2': 'w2'}}
def test_mutability():
config = INIConfiguration(mutable=False)
try:
config.key = 'value'
assert False, 'Expected TypeError'
except TypeError:
pass
set_mutability(config, True)
assert config._mutable == True
config.key = 'value'
set_mutability(config, False)
assert config._mutable == False
try:
del config.key
assert False, 'Expected TypeError'
except TypeError:
pass