This repository has been archived on 2026-03-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
config-parser/tests/test_configuration_class.py
T

79 lines
2.0 KiB
Python

# Copyright 2026 jCloud Services GbR
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
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