Commit b70940bf authored by Grant's avatar Grant
Browse files

some more testing walkthroughs

parent acc4ea1f
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
import os
import pytest
from common.env import boolify
from common.env import boolify, check_environment


def test_boolify_true():
@@ -20,3 +21,34 @@ def test_boolify_raises_typeerror():
    for val in non_bool_values:
        with pytest.raises(TypeError, match="unable to evaluate expected boolean"):
            boolify(val)


def test_check_environment_existing_variables():
    os.environ["TEST_VAR"] = "test_value"
    assert (
        check_environment("TEST_VAR", default="default_value") == "test_value"
    ), "Something really bad happened"


def test_check_environment_non_existing_with_default():
    if "NON_EXISTING_VAR" in os.environ:
        del os.environ["NON_EXISTING_VAR"]
    assert (
        check_environment("NON_EXISTING_VAR", default="default_value")
        == "default_value"
    ), "Default value is broken"


def test_check_environment_type_conversion_to_bool():
    os.environ["BOOL_VAR"] = "True"
    assert (
        check_environment("BOOL_VAR", default=False) is True
    ), "Failed to boolify and check_environment"


# TODO - checks for conversion to int, etc

def teardown_function(function):
    for var in ["TEST_VAR", "BOOL_VAR"]:
        if var in os.environ:
            del os.environ[var]