Skip to content

Commit

Permalink
test: added basic tests for compile flag
Browse files Browse the repository at this point in the history
  • Loading branch information
KineticCookie committed Jan 24, 2024
1 parent 7b98955 commit 6329415
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,28 @@ def test_bundler_can_filter_dependency_groups(
• Bundled simple-project (1.2.3) into {path}
"""
assert expected == io.fetch_output()

@pytest.mark.parametrize("compile", [True, False])
def test_bundler_passes_compile_flag(
io: BufferedIO, tmp_venv: VirtualEnv, poetry: Poetry, mocker: MockerFixture, compile: bool
):
mocker.patch("poetry.installation.executor.Executor._execute_operation")

bundler = VenvBundler()
bundler.set_path(tmp_venv.path)
bundler.set_remove(True)
bundler.set_compile(compile)

assert bundler.bundle(poetry, io)

path = str(tmp_venv.path)
python_version = ".".join(str(v) for v in sys.version_info[:3])
expected = f"""\
• Bundling simple-project (1.2.3) into {path}
• Bundling simple-project (1.2.3) into {path}: Removing existing virtual environment
• Bundling simple-project (1.2.3) into {path}: Creating a virtual environment using Python {python_version}
• Bundling simple-project (1.2.3) into {path}: Installing dependencies
• Bundling simple-project (1.2.3) into {path}: Installing simple-project (1.2.3)
• Bundled simple-project (1.2.3) into {path}
"""
assert expected == io.fetch_output()
17 changes: 16 additions & 1 deletion tests/console/commands/bundle/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ def test_venv_calls_venv_bundler(
) -> None:
mock = mocker.patch(
"poetry_plugin_bundle.bundlers.venv_bundler.VenvBundler.bundle",
side_effect=[True, False, False, False],
side_effect=[True, False, False, False, False],
)
set_path = mocker.spy(VenvBundler, "set_path")
set_executable = mocker.spy(VenvBundler, "set_executable")
set_remove = mocker.spy(VenvBundler, "set_remove")
set_activated_groups = mocker.spy(VenvBundler, "set_activated_groups")
set_compile = mocker.spy(VenvBundler, "set_compile")

app_tester.application.catch_exceptions(False)
assert app_tester.execute("bundle venv /foo") == 0
Expand All @@ -33,36 +34,50 @@ def test_venv_calls_venv_bundler(
)
assert app_tester.execute("bundle venv /foo --only dev") == 1
assert app_tester.execute("bundle venv /foo --without main --with dev") == 1
assert app_tester.execute("bundle venv /foo --compile") == 1

assert isinstance(app_tester.application, Application)
assert [
mocker.call(app_tester.application.poetry, mocker.ANY),
mocker.call(app_tester.application.poetry, mocker.ANY),
mocker.call(app_tester.application.poetry, mocker.ANY),
mocker.call(app_tester.application.poetry, mocker.ANY),
mocker.call(app_tester.application.poetry, mocker.ANY),
] == mock.call_args_list

assert set_path.call_args_list == [
mocker.call(mocker.ANY, Path("/foo")),
mocker.call(mocker.ANY, Path("/foo")),
mocker.call(mocker.ANY, Path("/foo")),
mocker.call(mocker.ANY, Path("/foo")),
mocker.call(mocker.ANY, Path("/foo")),
]
assert set_executable.call_args_list == [
mocker.call(mocker.ANY, None),
mocker.call(mocker.ANY, "python3.8"),
mocker.call(mocker.ANY, None),
mocker.call(mocker.ANY, None),
mocker.call(mocker.ANY, None),
]
assert set_remove.call_args_list == [
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, True),
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, False),
]
assert set_activated_groups.call_args_list == [
mocker.call(mocker.ANY, {"main"}),
mocker.call(mocker.ANY, {"main", "dev"}),
mocker.call(mocker.ANY, {"dev"}),
mocker.call(mocker.ANY, {"dev"}),
mocker.call(mocker.ANY, {"main"}),
]

assert set_compile.call_args_list == [
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, False),
mocker.call(mocker.ANY, True),
]

0 comments on commit 6329415

Please sign in to comment.