Compare commits

..

8 Commits

Author SHA1 Message Date
dw-0
08ab2d6090 Merge commit '681e5d8d05d035905e6fc694af93ee27ac87dbf2' into fix/section-adding 2024-09-24 22:11:53 +02:00
dw-0
681e5d8d05 Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 7835d2b..3a006f1
3a006f1 fix: correctly update last element value

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 3a006f1b4695919f27c6759c94b538acdda13e48
2024-09-24 22:11:53 +02:00
dw-0
687822d540 Merge commit '12080a2c42152df276b6239d7fda72504ea7fe0f' into fix/section-adding 2024-09-24 21:37:56 +02:00
dw-0
12080a2c42 Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 90081a6..7835d2b
7835d2b refactor: further improvement of adding new sections (#3)

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 7835d2b6e37ea0de940b0e4158278f4cfc349379
2024-09-24 21:37:56 +02:00
dw-0
e68979967d Merge commit '2f924a2550d9011604ce0170b21d1550501e6108' as 'kiauh/core/submodules/simple_config_parser' 2024-09-24 19:22:13 +02:00
dw-0
2f924a2550 Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit 90081a6
git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 90081a6539ec38adf6a1a5bb707a0e9934567c7f
2024-09-24 19:22:13 +02:00
dw-0
453e7181a5 chore: remove scp submodule
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-24 19:22:04 +02:00
dw-0
2897f38e4e refactor: log successfully added sections
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
2024-09-24 19:20:36 +02:00
3 changed files with 11 additions and 30 deletions

View File

@@ -311,7 +311,7 @@ class SimpleConfigParser:
"""Return the value of the given option in the given section as a converted value""" """Return the value of the given option in the given section as a converted value"""
try: try:
return conv(self.getval(section, option, fallback)) return conv(self.getval(section, option, fallback))
except (ValueError, TypeError, AttributeError) as e: except ValueError as e:
if fallback is not _UNSET: if fallback is not _UNSET:
return fallback return fallback
raise ValueError( raise ValueError(

View File

@@ -57,7 +57,6 @@ def test_getval(parser):
def test_getval_fallback(parser): def test_getval_fallback(parser):
assert parser.getval("section_1", "option_128", "fallback") == "fallback" assert parser.getval("section_1", "option_128", "fallback") == "fallback"
assert parser.getval("section_1", "option_128", None) is None
def test_getval_exceptions(parser): def test_getval_exceptions(parser):
@@ -90,7 +89,6 @@ def test_getint_from_boolean(parser):
def test_getint_fallback(parser): def test_getint_fallback(parser):
assert parser.getint("section_1", "option_128", 128) == 128 assert parser.getint("section_1", "option_128", 128) == 128
assert parser.getint("section_1", "option_128", None) is None
def test_getboolean(parser): def test_getboolean(parser):
@@ -117,7 +115,6 @@ def test_getboolean_from_float(parser):
def test_getboolean_fallback(parser): def test_getboolean_fallback(parser):
assert parser.getboolean("section_1", "option_128", True) is True assert parser.getboolean("section_1", "option_128", True) is True
assert parser.getboolean("section_1", "option_128", False) is False assert parser.getboolean("section_1", "option_128", False) is False
assert parser.getboolean("section_1", "option_128", None) is None
def test_getfloat(parser): def test_getfloat(parser):
@@ -142,7 +139,6 @@ def test_getfloat_from_boolean(parser):
def test_getfloat_fallback(parser): def test_getfloat_fallback(parser):
assert parser.getfloat("section_1", "option_128", 1.234) == 1.234 assert parser.getfloat("section_1", "option_128", 1.234) == 1.234
assert parser.getfloat("section_1", "option_128", None) is None
def test_set_existing_option(parser): def test_set_existing_option(parser):

View File

@@ -25,65 +25,50 @@ def parser():
return parser return parser
def test_get_int_conv(parser): def test_get_conv(parser):
# Test conversion to int
should_be_int = parser._get_conv("section_1", "option_1_2", int) should_be_int = parser._get_conv("section_1", "option_1_2", int)
assert isinstance(should_be_int, int) assert isinstance(should_be_int, int)
# Test conversion to float
def test_get_float_conv(parser):
should_be_float = parser._get_conv("section_1", "option_1_3", float) should_be_float = parser._get_conv("section_1", "option_1_3", float)
assert isinstance(should_be_float, float) assert isinstance(should_be_float, float)
# Test conversion to boolean
def test_get_bool_conv(parser):
should_be_bool = parser._get_conv( should_be_bool = parser._get_conv(
"section_1", "option_1_1", parser._convert_to_boolean "section_1", "option_1_1", parser._convert_to_boolean
) )
assert isinstance(should_be_bool, bool) assert isinstance(should_be_bool, bool)
# Test fallback for int
def test_get_int_conv_fallback(parser):
should_be_fallback_int = parser._get_conv( should_be_fallback_int = parser._get_conv(
"section_1", "option_128", int, fallback=128 "section_1", "option_128", int, fallback=128
) )
assert isinstance(should_be_fallback_int, int) assert isinstance(should_be_fallback_int, int)
assert should_be_fallback_int == 128 assert should_be_fallback_int == 128
assert parser._get_conv("section_1", "option_128", int, None) is None
# Test fallback for float
def test_get_float_conv_fallback(parser):
should_be_fallback_float = parser._get_conv( should_be_fallback_float = parser._get_conv(
"section_1", "option_128", float, fallback=1.234 "section_1", "option_128", float, fallback=1.234
) )
assert isinstance(should_be_fallback_float, float) assert isinstance(should_be_fallback_float, float)
assert should_be_fallback_float == 1.234 assert should_be_fallback_float == 1.234
assert parser._get_conv("section_1", "option_128", float, None) is None # Test fallback for boolean
def test_get_bool_conv_fallback(parser):
should_be_fallback_bool = parser._get_conv( should_be_fallback_bool = parser._get_conv(
"section_1", "option_128", parser._convert_to_boolean, fallback=True "section_1", "option_128", parser._convert_to_boolean, fallback=True
) )
assert isinstance(should_be_fallback_bool, bool) assert isinstance(should_be_fallback_bool, bool)
assert should_be_fallback_bool is True assert should_be_fallback_bool is True
assert ( # Test ValueError exception for invalid int conversion
parser._get_conv("section_1", "option_128", parser._convert_to_boolean, None)
is None
)
def test_get_int_conv_exception(parser):
with pytest.raises(ValueError): with pytest.raises(ValueError):
parser._get_conv("section_1", "option_1", int) parser._get_conv("section_1", "option_1", int)
# Test ValueError exception for invalid float conversion
def test_get_float_conv_exception(parser):
with pytest.raises(ValueError): with pytest.raises(ValueError):
parser._get_conv("section_1", "option_1", float) parser._get_conv("section_1", "option_1", float)
# Test ValueError exception for invalid boolean conversion
def test_get_bool_conv_exception(parser):
with pytest.raises(ValueError): with pytest.raises(ValueError):
parser._get_conv("section_1", "option_1", parser._convert_to_boolean) parser._get_conv("section_1", "option_1", parser._convert_to_boolean)