Example #1
0
def test__load_env_missing_integer(monkeypatch):
    """Should handle missing integer variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_NUM", "314")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_integer("bar", conf) is None
Example #2
0
def test__load_env_bad_string(monkeypatch):
    """Should handle bad string variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_FOO", "bar")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_string("bar", conf) is None
Example #3
0
def test__load_env_non_float(monkeypatch):
    """Should handle non-float variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_NUM", "bar")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_float("num", conf) is None
Example #4
0
def test__load_env_bad_boolean(monkeypatch):
    """Should handle bad boolean variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_CHECK", "true")
    monkeypatch.setenv("ELECTIVE_TEST_NO_CHECK", "false")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_boolean("bob", conf) is None
Example #5
0
def test__load_env_boolean_false(val, monkeypatch):
    """Should load a boolean variable from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_CHECK", val)
    monkeypatch.setenv("ELECTIVE_TEST_NO_CHECK", val)

    conf = elective.load_env(prefix="ELECTIVE_TEST_")
    assert elective.process_boolean("check", conf) is False
    assert elective.process_boolean("no_check", conf) is True
Example #6
0
def test__load_env_float(val):
    """Should load a float variable from the environment."""
    with pytest.MonkeyPatch().context() as mp:
        mp.setenv("ELECTIVE_TEST_NUM", str(val))
        conf = elective.load_env(prefix="ELECTIVE_TEST_")
        if math.isnan(val):
            assert math.isnan(elective.process_float("num", conf)) is True
        else:
            assert elective.process_float("num", conf) == val
Example #7
0
def test__load_env_non_dict(monkeypatch):
    """Should handle non-dict variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_DICT__0", "0")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__1", "1")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__2", "2")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__3", "3")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_dict("dict", conf) is None
Example #8
0
def test__load_env_missing_dict(monkeypatch):
    """Should handle missing dict variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_DICT__ONE", "uno")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__TWO", "dos")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__THREE", "tres")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__FOUR", "cuatro")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_dict("bar", conf) is None
Example #9
0
def test__load_env_missing_list(monkeypatch):
    """Should handle missing list variables from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_LIST__0", "0")
    monkeypatch.setenv("ELECTIVE_TEST_LIST__1", "1")
    monkeypatch.setenv("ELECTIVE_TEST_LIST__2", "2")
    monkeypatch.setenv("ELECTIVE_TEST_LIST__3", "3")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_list("bar", conf) is None
Example #10
0
def test__load_env_list(monkeypatch):
    """Should load a list variable from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_LIST__0", "0")
    monkeypatch.setenv("ELECTIVE_TEST_LIST__1", "1")
    monkeypatch.setenv("ELECTIVE_TEST_LIST__2", "2")
    monkeypatch.setenv("ELECTIVE_TEST_LIST__3", "3")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")

    assert elective.process_list("list", conf) == ["0", "1", "2", "3"]
Example #11
0
def test__load_env_dict(monkeypatch):
    """Should load a dict variable from the environment."""
    monkeypatch.setenv("ELECTIVE_TEST_DICT__ONE", "uno")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__TWO", "dos")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__THREE", "tres")
    monkeypatch.setenv("ELECTIVE_TEST_DICT__FOUR", "cuatro")

    conf = elective.load_env(prefix="ELECTIVE_TEST_")
    actual = elective.process_dict("dict", conf)
    expected = {
        "ONE": "uno",
        "TWO": "dos",
        "THREE": "tres",
        "FOUR": "cuatro",
    }

    assert actual == expected
Example #12
0
def test__load_env_integer(val):
    """Should load a integer variable from the environment."""
    with pytest.MonkeyPatch().context() as mp:
        mp.setenv("ELECTIVE_TEST_NUM", str(val))
        conf = elective.load_env(prefix="ELECTIVE_TEST_")
        assert elective.process_integer("num", conf) == val
Example #13
0
def test__load_env_string(str):
    """Should load a string variable from the environment."""
    with pytest.MonkeyPatch().context() as mp:
        mp.setenv("ELECTIVE_TEST_FOO", str)
        conf = elective.load_env(prefix="ELECTIVE_TEST_")
        assert elective.process_string("foo", conf) == str
Example #14
0
def test__load_env_no_env():
    """Should handle no environment."""
    actual = elective.load_env(prefix="ELECTIVE_TEST_")
    expected = {}

    assert actual == expected