From 9c6191f4f4942d4ae2a0a338930118e2defa153e Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Sat, 11 May 2024 20:23:04 +0530 Subject: [PATCH] Add CLI tests --- tests/cli_test.py | 37 +++++++++++++++++++ tests/{ => end_to_end}/conftest.py | 0 tests/{ => end_to_end}/packaged_test.py | 0 .../test_packages/just_python/foo.py | 0 .../test_packages/numpy_pandas/somefile.py | 0 5 files changed, 37 insertions(+) create mode 100644 tests/cli_test.py rename tests/{ => end_to_end}/conftest.py (100%) rename tests/{ => end_to_end}/packaged_test.py (100%) rename tests/{ => end_to_end}/test_packages/just_python/foo.py (100%) rename tests/{ => end_to_end}/test_packages/numpy_pandas/somefile.py (100%) diff --git a/tests/cli_test.py b/tests/cli_test.py new file mode 100644 index 0000000..731885b --- /dev/null +++ b/tests/cli_test.py @@ -0,0 +1,37 @@ +from unittest import mock + +from pytest import MonkeyPatch + +import packaged.cli + + +def test_cli(monkeypatch: MonkeyPatch) -> None: + """Ensures that CLI passes args to `create_package()` properly.""" + # Don't want to run makeself while testing CLI + monkeypatch.setattr(packaged.cli, "ensure_makeself", lambda: None) + + with mock.patch.object(packaged.cli, "create_package") as mocked: + packaged.cli.cli(["./foo", "pip install foo", "python -m foo"]) + + # source_directory is None + mocked.assert_called_with(None, "./foo", "pip install foo", "python -m foo") + + with mock.patch.object(packaged.cli, "create_package") as mocked: + packaged.cli.cli( + [ + "./bar", + "pip install -rrequirements.txt", + "python src/mypackage/cli.py", + "./mypackage", + ] + ) + + # source_directory is `./mypackage` + mocked.assert_called_with( + mock.ANY, + "./bar", + "pip install -rrequirements.txt", + "python src/mypackage/cli.py", + ) + args = mocked.call_args[0] + assert args[0].endswith("/mypackage") diff --git a/tests/conftest.py b/tests/end_to_end/conftest.py similarity index 100% rename from tests/conftest.py rename to tests/end_to_end/conftest.py diff --git a/tests/packaged_test.py b/tests/end_to_end/packaged_test.py similarity index 100% rename from tests/packaged_test.py rename to tests/end_to_end/packaged_test.py diff --git a/tests/test_packages/just_python/foo.py b/tests/end_to_end/test_packages/just_python/foo.py similarity index 100% rename from tests/test_packages/just_python/foo.py rename to tests/end_to_end/test_packages/just_python/foo.py diff --git a/tests/test_packages/numpy_pandas/somefile.py b/tests/end_to_end/test_packages/numpy_pandas/somefile.py similarity index 100% rename from tests/test_packages/numpy_pandas/somefile.py rename to tests/end_to_end/test_packages/numpy_pandas/somefile.py