From 49ac15d7a15e2311c6c96a8083aff6d1fdd45289 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sun, 27 Sep 2020 18:01:56 +0200 Subject: [PATCH 1/3] fix (console.commands.init): allow whitespace in list of extras for a package --- poetry/console/commands/init.py | 2 +- tests/console/commands/test_init.py | 9 +++++++++ tests/console/conftest.py | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/poetry/console/commands/init.py b/poetry/console/commands/init.py index 976988f26c2..606dad2870a 100644 --- a/poetry/console/commands/init.py +++ b/poetry/console/commands/init.py @@ -373,7 +373,7 @@ def _parse_requirements( for requirement in requirements: requirement = requirement.strip() extras = [] - extras_m = re.search(r"\[([\w\d,-_]+)\]$", requirement) + extras_m = re.search(r"\[([\w\d,-_ ]+)\]$", requirement) if extras_m: extras = [e.strip() for e in extras_m.group(1).split(",")] requirement, _ = requirement.split("[") diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index 20f992327e7..e175614f69d 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -556,3 +556,12 @@ def test_predefined_and_interactive_dev_dependencies(tester, repo): assert expected in output assert 'pytest-requests = "^0.2.0"' in output assert 'pytest = "^3.6.0"' in output + + +def test_add_package_with_extras_and_whitespace(init_command): + result = init_command._parse_requirements(["databases[postgresql, sqlite]"]) + + assert result[0]["name"] == "databases" + assert len(result[0]["extras"]) == 2 + assert "postgresql" in result[0]["extras"] + assert "sqlite" in result[0]["extras"] diff --git a/tests/console/conftest.py b/tests/console/conftest.py index 8a3a5cba8ae..2916aad14fd 100644 --- a/tests/console/conftest.py +++ b/tests/console/conftest.py @@ -4,6 +4,7 @@ from cleo import ApplicationTester +from poetry.console.commands import InitCommand from poetry.factory import Factory from poetry.installation.noop_installer import NoopInstaller from poetry.io.null_io import NullIO @@ -113,3 +114,10 @@ def new_installer_disabled(config): @pytest.fixture() def executor(poetry, config, env): return TestExecutor(env, poetry.pool, config, NullIO()) + + +@pytest.fixture() +def init_command(app): + command = InitCommand() + command._application = app + return command From cddbcad19076cdb0595d70200cc098bcab573f71 Mon Sep 17 00:00:00 2001 From: finswimmer Date: Sun, 27 Sep 2020 20:20:34 +0200 Subject: [PATCH 2/3] fix (console.commands.test_init): use app to get InitCommand --- tests/console/commands/test_init.py | 5 +++-- tests/console/conftest.py | 8 -------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index e175614f69d..73d0a7d8628 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -558,8 +558,9 @@ def test_predefined_and_interactive_dev_dependencies(tester, repo): assert 'pytest = "^3.6.0"' in output -def test_add_package_with_extras_and_whitespace(init_command): - result = init_command._parse_requirements(["databases[postgresql, sqlite]"]) +def test_add_package_with_extras_and_whitespace(app): + command = app.find("init") + result = command._parse_requirements(["databases[postgresql, sqlite]"]) assert result[0]["name"] == "databases" assert len(result[0]["extras"]) == 2 diff --git a/tests/console/conftest.py b/tests/console/conftest.py index 2916aad14fd..8a3a5cba8ae 100644 --- a/tests/console/conftest.py +++ b/tests/console/conftest.py @@ -4,7 +4,6 @@ from cleo import ApplicationTester -from poetry.console.commands import InitCommand from poetry.factory import Factory from poetry.installation.noop_installer import NoopInstaller from poetry.io.null_io import NullIO @@ -114,10 +113,3 @@ def new_installer_disabled(config): @pytest.fixture() def executor(poetry, config, env): return TestExecutor(env, poetry.pool, config, NullIO()) - - -@pytest.fixture() -def init_command(app): - command = InitCommand() - command._application = app - return command From 754de26973b700eb38fe392c1e43d7a00c8acfff Mon Sep 17 00:00:00 2001 From: finswimmer Date: Mon, 28 Sep 2020 06:39:44 +0200 Subject: [PATCH 3/3] fix (console.commands.test_init): use tester to get InitCommand --- tests/console/commands/test_init.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/console/commands/test_init.py b/tests/console/commands/test_init.py index 73d0a7d8628..d367fbc8b8e 100644 --- a/tests/console/commands/test_init.py +++ b/tests/console/commands/test_init.py @@ -558,9 +558,8 @@ def test_predefined_and_interactive_dev_dependencies(tester, repo): assert 'pytest = "^3.6.0"' in output -def test_add_package_with_extras_and_whitespace(app): - command = app.find("init") - result = command._parse_requirements(["databases[postgresql, sqlite]"]) +def test_add_package_with_extras_and_whitespace(tester): + result = tester._command._parse_requirements(["databases[postgresql, sqlite]"]) assert result[0]["name"] == "databases" assert len(result[0]["extras"]) == 2