Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle multiple extras and invalid extras #103

Merged
merged 1 commit into from
Sep 2, 2022
Merged
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
12 changes: 11 additions & 1 deletion src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,19 @@ def handle(self) -> None:
"</warning>"
)

# Checking extras
extras = {
extra for extra_opt in self.option("extras") for extra in extra_opt.split()
}
invalid_extras = extras - self.poetry.package.extras.keys()
if invalid_extras:
raise ValueError(
f"Extra [{', '.join(sorted(invalid_extras))}] is not specified."
)

exporter = Exporter(self.poetry)
exporter.only_groups(list(self.activated_groups))
exporter.with_extras(self.option("extras"))
exporter.with_extras(list(extras))
exporter.with_hashes(not self.option("without-hashes"))
exporter.with_credentials(self.option("with-credentials"))
exporter.with_urls(not self.option("without-urls"))
Expand Down
36 changes: 32 additions & 4 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
python = "~2.7 || ^3.6"
foo = "^1.0"
bar = { version = "^1.1", optional = true }
qux = { version = "^1.2", optional = true }

[tool.poetry.group.dev.dependencies]
baz = "^2.0"
Expand All @@ -63,6 +64,7 @@

[tool.poetry.extras]
feature_bar = ["bar"]
feature_qux = ["qux"]
"""


Expand All @@ -72,6 +74,7 @@ def setup(repo: Repository) -> None:
repo.add_package(Package("bar", "1.1.0"))
repo.add_package(Package("baz", "2.0.0"))
repo.add_package(Package("opt", "2.2.0"))
repo.add_package(Package("qux", "1.2.0"))


@pytest.fixture
Expand Down Expand Up @@ -174,15 +177,40 @@ def test_export_groups(
assert tester.io.fetch_output() == expected


def test_export_includes_extras_by_flag(tester: CommandTester, do_lock: None) -> None:
tester.execute("--format requirements.txt --extras feature_bar")
expected = f"""\
@pytest.mark.parametrize(
"extras, expected",
[
(
"feature_bar",
f"""\
bar==1.1.0 ; {MARKER_PY}
foo==1.0.0 ; {MARKER_PY}
"""
""",
),
(
"feature_bar feature_qux",
f"""\
bar==1.1.0 ; {MARKER_PY}
foo==1.0.0 ; {MARKER_PY}
qux==1.2.0 ; {MARKER_PY}
""",
),
],
)
def test_export_includes_extras_by_flag(
tester: CommandTester, do_lock: None, extras: str, expected: str
) -> None:
tester.execute(f"--format requirements.txt --extras '{extras}'")
assert tester.io.fetch_output() == expected


def test_export_reports_invalid_extras(tester: CommandTester, do_lock: None) -> None:
with pytest.raises(ValueError) as error:
tester.execute("--format requirements.txt --extras 'SUS AMONGUS'")
expected = "Extra [AMONGUS, SUS] is not specified."
assert str(error.value) == expected


def test_export_with_urls(
monkeypatch: MonkeyPatch, tester: CommandTester, poetry: Poetry
) -> None:
Expand Down