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:
@@ -0,0 +1,68 @@
|
||||
import sys, os; sys.path.append(os.getcwd())
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user