~homeworkprod/byceps

ref: 2c36ca1dd7ac5667b5d8502ae39f59d2a17e3e00 byceps/tests/unit/util/test_system.py -rw-r--r-- 906 bytes
2c36ca1d — Jochen Kupperschmidt Use `flask.Config.from_envvar`, remove `byceps.util.system.get_config_filename_from_env[_or_exit]` 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

import pytest

from byceps.config import ConfigurationError
from byceps.util.system import get_env_value


def test_get_env_value_with_value(monkeypatch):
    monkeypatch.setenv('LAUNCH_CODE', '3-2-1-LIFT-OFF')

    actual = get_env_value('LAUNCH_CODE', 'Invalid launch code')

    assert actual == '3-2-1-LIFT-OFF'


def test_get_env_value_with_empty_value(monkeypatch):
    monkeypatch.setenv('LAUNCH_CODE', '')

    with pytest.raises(ConfigurationError) as excinfo:
        get_env_value('LAUNCH_CODE', 'Invalid launch code')

    assert str(excinfo.value) == 'Invalid launch code'


def test_get_env_value_without_value():
    with pytest.raises(ConfigurationError) as excinfo:
        get_env_value('LAUNCH_CODE', 'Invalid launch code')

    assert str(excinfo.value) == 'Invalid launch code'