Skip to content

Commit

Permalink
Refactor tests, remove platform-specific ones
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted committed Oct 11, 2023
1 parent 08885eb commit c515f3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
pipelines/
defaults/
site/
scratch*
86 changes: 21 additions & 65 deletions tests/utils/test_environment.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"

0 comments on commit c515f3b

Please sign in to comment.