Skip to content

Commit

Permalink
command: restore default behavior, consistent behavior for --with/--w…
Browse files Browse the repository at this point in the history
…ithout, tests
  • Loading branch information
radoering committed Apr 11, 2022
1 parent 14180c7 commit f927b84
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/poetry_plugin_export/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class ExportCommand(InstallerCommand):
option("with-credentials", None, "Include credentials for extra indices."),
]

@property
def non_optional_groups(self) -> set[str]:
return {"default"}

def handle(self) -> None:
fmt = self.option("format")

Expand Down
39 changes: 39 additions & 0 deletions tests/command/test_command_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
foo = "^1.0"
bar = { version = "^1.1", optional = true }
[tool.poetry.group.dev.dependencies]
baz = "^2.0"
[tool.poetry.group.opt]
optional = true
[tool.poetry.group.opt.dependencies]
opt = "^2.2"
[tool.poetry.extras]
feature_bar = ["bar"]
"""
Expand All @@ -59,6 +69,8 @@
def setup(repo: Repository) -> None:
repo.add_package(Package("foo", "1.0.0"))
repo.add_package(Package("bar", "1.1.0"))
repo.add_package(Package("baz", "2.0.0"))
repo.add_package(Package("opt", "2.2.0"))


@pytest.fixture
Expand Down Expand Up @@ -129,6 +141,33 @@ def test_export_uses_requirements_txt_format_by_default(
assert tester.io.fetch_output() == expected


@pytest.mark.parametrize(
"options, expected",
[
("", f"foo==1.0.0 ; {MARKER_PY}\n"),
("--with dev", f"baz==2.0.0 ; {MARKER_PY}\nfoo==1.0.0 ; {MARKER_PY}\n"),
("--with opt", f"foo==1.0.0 ; {MARKER_PY}\nopt==2.2.0 ; {MARKER_PY}\n"),
(
"--with dev,opt",
f"baz==2.0.0 ; {MARKER_PY}\nfoo==1.0.0 ; {MARKER_PY}\nopt==2.2.0 ;"
f" {MARKER_PY}\n",
),
("--without default", "\n"),
("--without dev", f"foo==1.0.0 ; {MARKER_PY}\n"),
("--without opt", f"foo==1.0.0 ; {MARKER_PY}\n"),
("--without default,dev,opt", "\n"),
("--only default", f"foo==1.0.0 ; {MARKER_PY}\n"),
("--only dev", f"baz==2.0.0 ; {MARKER_PY}\n"),
("--only default,dev", f"baz==2.0.0 ; {MARKER_PY}\nfoo==1.0.0 ; {MARKER_PY}\n"),
],
)
def test_export_groups(
tester: CommandTester, do_lock: None, options: str, expected: str
):
tester.execute(options)
assert tester.io.fetch_output() == expected


def test_export_includes_extras_by_flag(tester: CommandTester, do_lock: None):
tester.execute("--format requirements.txt --extras feature_bar")
expected = f"""\
Expand Down

0 comments on commit f927b84

Please sign in to comment.