mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-27 17:53:35 +05:00
Compare commits
8 Commits
v6.0.0-alp
...
08ab2d6090
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08ab2d6090 | ||
|
|
681e5d8d05 | ||
|
|
687822d540 | ||
|
|
12080a2c42 | ||
|
|
e68979967d | ||
|
|
2f924a2550 | ||
|
|
453e7181a5 | ||
|
|
2897f38e4e |
@@ -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(
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user