Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed May 21, 2024
1 parent afd25a3 commit 85a9281
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/packaged/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def cli(argv: list[str] | None = None) -> int:
parser.add_argument(
"--quiet",
help="Disable all output",
action="store_false" if "CI" in os.environ else "store_true",
action="store_true",
default="CI" in os.environ,
)
args = parser.parse_args(argv)
config = Config(**vars(args))
Expand Down
35 changes: 34 additions & 1 deletion tests/cli_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from __future__ import annotations

import os
from unittest import mock

from pytest import MonkeyPatch

import packaged
import packaged.cli


def test_cli() -> None:
def test_cli(monkeypatch: MonkeyPatch) -> None:
"""Ensures that CLI passes args to `create_package()` properly."""
with mock.patch.object(packaged.cli, "create_package") as mocked:
packaged.cli.cli(["./foo", "pip install foo", "python -m foo"])
Expand Down Expand Up @@ -68,3 +71,33 @@ def test_cli() -> None:
packaged.DEFAULT_PYTHON_VERSION,
True,
)

# Test --quiet when CI is true, regardless of if the flag is passed
monkeypatch.setattr(os, "environ", {"CI": "1"})
with mock.patch.object(packaged.cli, "create_package") as mocked:
packaged.cli.cli(["./some", "pip install some", "python some.py", "./some.bin"])

# quiet is True
mocked.assert_called_with(
mock.ANY,
"./some",
"pip install some",
"python some.py",
packaged.DEFAULT_PYTHON_VERSION,
True,
)
monkeypatch.setattr(os, "environ", {"CI": "1"})
with mock.patch.object(packaged.cli, "create_package") as mocked:
packaged.cli.cli(
["./some", "pip install some", "python some.py", "./some.bin", "--quiet"]
)

# quiet is True
mocked.assert_called_with(
mock.ANY,
"./some",
"pip install some",
"python some.py",
packaged.DEFAULT_PYTHON_VERSION,
True,
)

0 comments on commit 85a9281

Please sign in to comment.