a1c1d2b975
geändert: src/config_parser/json.py geändert: src/config_parser/parse/json.py geändert: tests/test_configuration_class.py
66 lines
1.4 KiB
Python
66 lines
1.4 KiB
Python
from src.config_parser import Configuration
|
|
|
|
|
|
def test_crud_configuration_attrs():
|
|
config = Configuration()
|
|
|
|
# Test setting an attribute
|
|
config.abc = 42
|
|
|
|
# Test getting an attribute
|
|
assert config.abc == 42
|
|
|
|
# Test getting a non-existing attribute
|
|
try:
|
|
config.non_existing
|
|
assert False, "AttributeError was not raised"
|
|
except AttributeError:
|
|
pass
|
|
|
|
# Test updating an attribute
|
|
config.abc = 100
|
|
|
|
# Test getting the updated attribute
|
|
assert config.abc == 100
|
|
|
|
# Test getting dictionary
|
|
assert dict(config) == {'abc': 100}
|
|
|
|
# Test deleting an attribute
|
|
del config.abc
|
|
try:
|
|
config.abc
|
|
assert False, "AttributeError was not raised"
|
|
except AttributeError:
|
|
pass
|
|
|
|
def test_crud_configuration_config_items():
|
|
config = Configuration()
|
|
|
|
# Test setting an item
|
|
config['key1'] = 'value1'
|
|
|
|
# Test getting an item
|
|
assert config['key1'] == 'value1'
|
|
assert config.key1 == 'value1'
|
|
|
|
# Test updating an item
|
|
config['key1'] = 'value2'
|
|
|
|
# Test getting the updated item
|
|
assert config['key1'] == 'value2'
|
|
assert config.key1 == 'value2'
|
|
|
|
# Test deleting an item and exceptions
|
|
del config['key1']
|
|
try:
|
|
config['key1']
|
|
assert False, "KeyError was not raised"
|
|
except KeyError:
|
|
pass
|
|
|
|
try:
|
|
config.key1
|
|
assert False, "AttributeError was not raised"
|
|
except AttributeError:
|
|
pass |