From b43b5f4eb414a382c1f8c63d81b15ecbddd2378a Mon Sep 17 00:00:00 2001 From: Luis Pedro Coelho Date: Fri, 11 Jul 2025 13:09:30 +1000 Subject: [PATCH] Fix bool handling in config and add tests --- jug/options.py | 5 ++++- jug/tests/test_options.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/jug/options.py b/jug/options.py index c142e2c..8b4611b 100644 --- a/jug/options.py +++ b/jug/options.py @@ -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) diff --git a/jug/tests/test_options.py b/jug/tests/test_options.py index 673376d..ce51493 100644 --- a/jug/tests/test_options.py +++ b/jug/tests/test_options.py @@ -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