Skip to content

Commit

Permalink
Use stdlib only
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Jul 1, 2024
1 parent 2b7ab9f commit 4110781
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
43 changes: 22 additions & 21 deletions bimmer_connected/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
import subprocess
import sys
import tempfile
from pathlib import Path

import pytest
from cli_test_helpers import ArgvContext, shell

import bimmer_connected.cli

Expand All @@ -15,18 +16,18 @@

def test_run_entrypoint():
"""Test if the entrypoint is installed correctly."""
result = shell("bimmerconnected --help")
result = subprocess.run(["bimmerconnected", "--help"], capture_output=True, text=True)

assert FIXTURE_CLI_HELP in result.stdout
assert result.exit_code == 0
assert result.returncode == 0


def test_run_module():
"""Test if the module can be run as a python module."""
result = shell("python -m bimmer_connected.cli --help")
result = subprocess.run(["python", "-m", "bimmer_connected.cli", "--help"], capture_output=True, text=True)

assert FIXTURE_CLI_HELP in result.stdout
assert result.exit_code == 0
assert result.returncode == 0


@pytest.mark.usefixtures("bmw_fixture")
Expand All @@ -41,11 +42,11 @@ def test_run_module():
def test_status_json_filtered(capsys: pytest.CaptureFixture, vin, expected_count):
"""Test the status command JSON output filtered by VIN."""

with ArgvContext("bimmerconnected", "status", "-j", "-v", vin, *ARGS_USER_PW_REGION):
try:
bimmer_connected.cli.main()
except SystemExit:
pass
sys.argv = ["bimmerconnected", "status", "-j", "-v", vin, *ARGS_USER_PW_REGION]
try:
bimmer_connected.cli.main()
except SystemExit:
pass
result = capsys.readouterr()

if expected_count == 1:
Expand All @@ -60,8 +61,8 @@ def test_status_json_filtered(capsys: pytest.CaptureFixture, vin, expected_count
def test_status_json_unfiltered(capsys: pytest.CaptureFixture):
"""Test the status command JSON output filtered by VIN."""

with ArgvContext("bimmerconnected", "status", "-j", *ARGS_USER_PW_REGION):
bimmer_connected.cli.main()
sys.argv = ["bimmerconnected", "status", "-j", *ARGS_USER_PW_REGION]
bimmer_connected.cli.main()
result = capsys.readouterr()

result_json = json.loads(result.out)
Expand All @@ -81,11 +82,11 @@ def test_status_json_unfiltered(capsys: pytest.CaptureFixture):
def test_status_filtered(capsys: pytest.CaptureFixture, vin, expected_count):
"""Test the status command text output filtered by VIN."""

with ArgvContext("bimmerconnected", "status", "-v", vin, *ARGS_USER_PW_REGION):
try:
bimmer_connected.cli.main()
except SystemExit:
pass
sys.argv = ["bimmerconnected", "status", "-v", vin, *ARGS_USER_PW_REGION]
try:
bimmer_connected.cli.main()
except SystemExit:
pass
result = capsys.readouterr()

assert f"Found {get_fingerprint_count('states')} vehicles" in result.out
Expand All @@ -101,8 +102,8 @@ def test_status_filtered(capsys: pytest.CaptureFixture, vin, expected_count):
def test_status_unfiltered(capsys: pytest.CaptureFixture):
"""Test the status command text output filtered by VIN."""

with ArgvContext("bimmerconnected", "status", *ARGS_USER_PW_REGION):
bimmer_connected.cli.main()
sys.argv = ["bimmerconnected", "status", *ARGS_USER_PW_REGION]
bimmer_connected.cli.main()
result = capsys.readouterr()

assert f"Found {get_fingerprint_count('states')} vehicles" in result.out
Expand All @@ -118,8 +119,8 @@ def test_fingerprint(capsys: pytest.CaptureFixture, monkeypatch: pytest.MonkeyPa
tmp_path = Path(tmpdirname)
monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)

with ArgvContext("bimmerconnected", "fingerprint", *ARGS_USER_PW_REGION):
bimmer_connected.cli.main()
sys.argv = ["bimmerconnected", "fingerprint", *ARGS_USER_PW_REGION]
bimmer_connected.cli.main()
result = capsys.readouterr()

assert "fingerprint of the vehicles written to" in result.out
Expand Down
3 changes: 1 addition & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ time_machine<2.13.0
pre-commit
backports.zoneinfo;python_version<"3.9"
ruff
types-Pillow
cli-test-helpers
types-Pillow

0 comments on commit 4110781

Please sign in to comment.