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
+23
View File
@@ -14,6 +14,7 @@
from src.config_parser.json import JSONConfiguration
from src.config_parser.exceptions import JSONObjectSyntaxError, JSONValueSyntaxError, JSONStringSyntaxError, JSONArraySyntaxError, EscapeSequenceSyntaxError
from src.config_parser import set_mutability
def test_json_configuration():
# Test valid JSON configuration parsing
@@ -220,4 +221,26 @@ def test_json_configuration():
JSONConfiguration.from_string('')
assert False, 'Excepted JSONValueSyntaxError'
except JSONValueSyntaxError:
pass
def test_mutability():
config = JSONConfiguration(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