From d4c2fe44f43d426ecf963bbce9325c45dbc40fc8 Mon Sep 17 00:00:00 2001 From: Ashley Whetter Date: Fri, 19 Mar 2021 21:15:15 -0700 Subject: [PATCH] POETRY_EXPERIMENTAL_NEW_INSTALLER is interpreted as a boolean --- src/poetry/config/config.py | 1 + tests/config/test_config.py | 36 +++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/poetry/config/config.py b/src/poetry/config/config.py index 82eb95b3282..03ff85de8ec 100644 --- a/src/poetry/config/config.py +++ b/src/poetry/config/config.py @@ -132,6 +132,7 @@ def _get_normalizer(self, name: str) -> Callable: "virtualenvs.in-project", "virtualenvs.options.always-copy", "virtualenvs.options.system-site-packages", + "experimental.new-installer", "installer.parallel", }: return boolean_normalizer diff --git a/tests/config/test_config.py b/tests/config/test_config.py index f3b13f23003..0d1e0e48b6d 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -1,7 +1,22 @@ import os +import re import pytest +from poetry.config.config import Config + + +def get_boolean_options(config=None): + if config is None: + config = Config.default_config + + for k, v in config.items(): + if isinstance(v, bool) or v is None: + yield k + if isinstance(v, dict): + for suboption in get_boolean_options(v): + yield "{}.{}".format(k, suboption) + @pytest.mark.parametrize( ("name", "value"), [("installer.parallel", True), ("virtualenvs.create", True)] @@ -14,16 +29,19 @@ def test_config_get_processes_depended_on_values(config, config_cache_dir): assert str(config_cache_dir / "virtualenvs") == config.get("virtualenvs.path") +def generate_environment_variable_tests(): + for env_value, value in [("true", True), ("false", False)]: + for name in get_boolean_options(): + env_var = "POETRY_{}".format(re.sub("[.-]+", "_", name).upper()) + yield (name, env_var, env_value, value) + + @pytest.mark.parametrize( - ("name", "env_value", "value"), - [ - ("installer.parallel", "true", True), - ("installer.parallel", "false", False), - ("virtualenvs.create", "true", True), - ("virtualenvs.create", "false", False), - ], + ("name", "env_var", "env_value", "value"), + list(generate_environment_variable_tests()), ) -def test_config_get_from_environment_variable(config, environ, name, env_value, value): - env_var = "POETRY_{}".format("_".join(k.upper() for k in name.split("."))) +def test_config_get_from_environment_variable( + config, environ, name, env_var, env_value, value +): os.environ[env_var] = env_value assert config.get(name) is value