Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jug/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ def read_configuration_file(fp=None, default_options=None):
old_value = getattr(default_options, new_name, None)
if old_value is not None:
# Cast the config object to the same type as the default
value = type(old_value)(value)
if isinstance(old_value, bool):
value = _str_to_bool(value)
else:
value = type(old_value)(value)

logging.debug("Setting %s to %s", new_name, value)
setattr(inifile, new_name, value)
Expand Down
14 changes: 14 additions & 0 deletions jug/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,17 @@ def test_bool():
assert _str_to_bool("on")
assert _str_to_bool("true")
assert _str_to_bool("1")


_bool_options_file = """
[main]
will-cite=false
"""


def test_bool_from_config():
opts = jug.options.read_configuration_file(
StringIO(_bool_options_file),
default_options=jug.options.default_options,
)
assert opts.will_cite is False