diff --git a/pyproject.toml b/pyproject.toml index 359d2080..d3f7cfd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" [project] name = "ops-scenario" -version = "5.6" +version = "5.6.1" authors = [ { name = "Pietro Pasotti", email = "pietro.pasotti@canonical.com" } diff --git a/scenario/mocking.py b/scenario/mocking.py index 872a8134..1ac515ef 100644 --- a/scenario/mocking.py +++ b/scenario/mocking.py @@ -72,6 +72,9 @@ def send_signal(self, sig: Union[int, str]): # noqa: U100 raise NotImplementedError() +_NOT_GIVEN = object() # non-None default value sentinel + + class _MockModelBackend(_ModelBackend): def __init__( self, @@ -221,8 +224,10 @@ def config_get(self): for key, value in charm_config["options"].items(): # if it has a default, and it's not overwritten from State, use it: - if key not in state_config and (default_value := value.get("default")): - state_config[key] = default_value + if key not in state_config: + default_value = value.get("default", _NOT_GIVEN) + if default_value is not _NOT_GIVEN: # accept False as default value + state_config[key] = default_value return state_config # full config diff --git a/tests/test_e2e/test_config.py b/tests/test_e2e/test_config.py index 3a9fe5e5..55c5b70d 100644 --- a/tests/test_e2e/test_config.py +++ b/tests/test_e2e/test_config.py @@ -41,6 +41,7 @@ def test_config_get_default_from_meta(mycharm): def check_cfg(charm: CharmBase): assert charm.config["foo"] == "bar" assert charm.config["baz"] == 2 + assert charm.config["qux"] is False trigger( State( @@ -53,6 +54,7 @@ def check_cfg(charm: CharmBase): "options": { "foo": {"type": "string"}, "baz": {"type": "integer", "default": 2}, + "qux": {"type": "boolean", "default": False}, }, }, post_event=check_cfg,