From c515f3bc98ebc2a0c22b31bfe4ee257c4e9447eb Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Wed, 11 Oct 2023 09:53:14 +0200 Subject: [PATCH] Refactor tests, remove platform-specific ones --- .gitignore | 1 + tests/utils/test_environment.py | 86 ++++++++------------------------- 2 files changed, 22 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index db58e072b..7724b5bab 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ pipelines/ defaults/ site/ +scratch* diff --git a/tests/utils/test_environment.py b/tests/utils/test_environment.py index 16eac15b7..ae1b9d897 100644 --- a/tests/utils/test_environment.py +++ b/tests/utils/test_environment.py @@ -1,37 +1,33 @@ import os -from unittest.mock import patch import pytest from kpops.utils.environment import Environment -@pytest.fixture() -def fake_environment_windows(monkeypatch: pytest.MonkeyPatch): +@pytest.fixture(autouse=True) +def environment(monkeypatch: pytest.MonkeyPatch) -> Environment: monkeypatch.setenv("MY", "fake") monkeypatch.setenv("ENVIRONMENT", "here") + return Environment() -@pytest.fixture() -def fake_environment_linux(monkeypatch: pytest.MonkeyPatch): - monkeypatch.setenv("my", "fake") - monkeypatch.setenv("environment", "here") - +def test_get_item(environment: Environment): + assert environment["MY"] == "fake" + assert environment["ENVIRONMENT"] == "here" -@patch("platform.system") -def test_normal_behaviour_get_item(system, fake_environment_linux): - system.return_value = "Linux" - environment = Environment() - assert environment["my"] == "fake" - assert environment["environment"] == "here" +def test_set_item(environment: Environment): + environment["extra"] = "key" + keys = set(environment.keys()) + assert "MY" in keys + assert "ENVIRONMENT" in keys + assert "extra" in keys + assert environment["extra"] == "key" -@patch("platform.system") -def test_normal_behaviour_update_os_environ(system, fake_environment_linux): - system.return_value = "Linux" - environment = Environment() +def test_update_os_environ(environment: Environment): with pytest.raises(KeyError): environment["TEST"] os.environ["TEST"] = "test" @@ -44,57 +40,17 @@ def test_normal_behaviour_update_os_environ(system, fake_environment_linux): assert items["TEST"] == "test" -@patch("platform.system") -def test_normal_behaviour_kwargs(system, fake_environment_linux): - system.return_value = "Linux" +def test_mapping(): environment = Environment(**{"kwarg1": "value1", "kwarg2": "value2"}) - - assert environment["my"] == "fake" - assert environment["environment"] == "here" + assert environment["MY"] == "fake" + assert environment["ENVIRONMENT"] == "here" assert environment["kwarg1"] == "value1" assert environment["kwarg2"] == "value2" -@patch("platform.system") -def test_normal_behaviour_keys_transformation(system, fake_environment_linux): - system.return_value = "Linux" - environment = Environment() - keys = set(environment.keys()) - - assert "my" in keys - assert "environment" in keys - - -@patch("platform.system") -def test_normal_behaviour_set_key(system, fake_environment_linux): - system.return_value = "Linux" - environment = Environment() - environment["extra"] = "key" - - keys = set(environment.keys()) - assert "my" in keys - assert "environment" in keys - assert "extra" in keys - assert environment["extra"] == "key" - - -@patch("platform.system") -def test_windows_behaviour_get_item(system, fake_environment_windows): - system.return_value = "Windows" - - environment = Environment() +def test_kwargs(): + environment = Environment(kwarg1="value1", kwarg2="value2") assert environment["MY"] == "fake" assert environment["ENVIRONMENT"] == "here" - - -@patch("platform.system") -def test_windows_behaviour_set_key(system, fake_environment_windows): - system.return_value = "Windows" - environment = Environment() - environment["extra"] = "key" - - keys = set(environment.keys()) - assert "MY" in keys - assert "ENVIRONMENT" in keys - assert "extra" in keys - assert environment["extra"] == "key" + assert environment["kwarg1"] == "value1" + assert environment["kwarg2"] == "value2"