From 4110781e74c53400d005b93ec4f56233522313d4 Mon Sep 17 00:00:00 2001 From: rikroe <42204099+rikroe@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:27:35 +0200 Subject: [PATCH] Use stdlib only --- bimmer_connected/tests/test_cli.py | 43 +++++++++++++++--------------- requirements-test.txt | 3 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bimmer_connected/tests/test_cli.py b/bimmer_connected/tests/test_cli.py index 0b1efa2d..6f5eec83 100644 --- a/bimmer_connected/tests/test_cli.py +++ b/bimmer_connected/tests/test_cli.py @@ -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 @@ -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") @@ -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: @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/requirements-test.txt b/requirements-test.txt index 18f0cb2e..54f057be 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -11,5 +11,4 @@ time_machine<2.13.0 pre-commit backports.zoneinfo;python_version<"3.9" ruff -types-Pillow -cli-test-helpers \ No newline at end of file +types-Pillow \ No newline at end of file