Skip to content

Commit

Permalink
Add CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed May 11, 2024
1 parent 7f6cc81 commit 9c6191f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
@@ -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")
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9c6191f

Please sign in to comment.