Skip to content

Commit

Permalink
remove test dep, cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: William Woodruff <[email protected]>
  • Loading branch information
woodruffw committed May 10, 2024
1 parent 4216a38 commit 1ab54d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ requires-python = ">=3.8"

[project.optional-dependencies]
test = [
"cli-test-helpers",
"coverage[toml] ~= 7.0, != 7.3.3", # https://github.com/nedbat/coveragepy/issues/1713
"pretend",
"pytest",
Expand Down
26 changes: 13 additions & 13 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pretend # type: ignore
import pytest
from cli_test_helpers import ArgvContext, EnvironContext

import pip_audit._cli
from pip_audit._cli import (
Expand Down Expand Up @@ -101,7 +100,7 @@ def test_plurals(capsys, monkeypatch, args, vuln_count, pkg_count, expected):
monkeypatch.setattr(pip_audit._cli, "PipSource", lambda *a, **kw: dummysource)

parser = pip_audit._cli._parser()
monkeypatch.setattr(pip_audit._cli, "_parse_args", lambda x: parser.parse_args(args))
monkeypatch.setattr(pip_audit._cli, "_parse_args", lambda *a: parser.parse_args(args))

result = [
(
Expand Down Expand Up @@ -168,7 +167,7 @@ def test_print_format(monkeypatch, vuln_count, pkg_count, skip_count, print_form
monkeypatch.setattr(pip_audit._cli, "ColumnsFormat", lambda *a, **kw: dummyformat)

parser = pip_audit._cli._parser()
monkeypatch.setattr(pip_audit._cli, "_parse_args", lambda x: parser.parse_args([]))
monkeypatch.setattr(pip_audit._cli, "_parse_args", lambda *a: parser.parse_args([]))

result = [
(
Expand Down Expand Up @@ -220,19 +219,20 @@ def test_print_format(monkeypatch, vuln_count, pkg_count, skip_count, print_form
assert bool(dummyformat.format.calls) == print_format


def test_environment_variable():
def test_environment_variable(monkeypatch):
"""Environment variables set before execution change CLI option default."""
with ArgvContext("pip-audit"), EnvironContext(
PIP_AUDIT_DESC="off",
PIP_AUDIT_FORMAT="markdown",
PIP_AUDIT_OUTPUT="stderr",
PIP_AUDIT_PROGRESS_SPINNER="off",
PIP_AUDIT_VULNERABILITY_SERVICE="osv",
):
args = pip_audit._cli._parser().parse_args()
monkeypatch.setenv("PIP_AUDIT_DESC", "off")
monkeypatch.setenv("PIP_AUDIT_FORMAT", "markdown")
monkeypatch.setenv("PIP_AUDIT_OUTPUT", "/tmp/fake")
monkeypatch.setenv("PIP_AUDIT_PROGRESS_SPINNER", "off")
monkeypatch.setenv("PIP_AUDIT_VULNERABILITY_SERVICE", "osv")

parser = pip_audit._cli._parser()
monkeypatch.setattr(pip_audit._cli, "_parse_args", lambda *a: parser.parse_args([]))
args = pip_audit._cli._parse_args(parser, [])

assert args.desc == VulnerabilityDescriptionChoice.Off
assert args.format == OutputFormatChoice.Markdown
assert args.output == Path("stderr")
assert args.output == Path("/tmp/fake")
assert not args.progress_spinner
assert args.vulnerability_service == VulnerabilityServiceChoice.Osv

0 comments on commit 1ab54d9

Please sign in to comment.