Beispiel #1
0
def test_missing_different_from_empty(monkeypatch):
    monkeypatch.setenv('VAR', '')

    assert get('VAR', str) == ''
    with pytest.raises(AttributeError) as e:
        get('VAR2', str)
    assert str(e.value) == 'VAR2 is required'
Beispiel #2
0
def test_smoke(monkeypatch):
    monkeypatch.setenv('VAR', 'str')
    assert get('VAR', str) == 'str'
Beispiel #3
0
def test_default_ignore_cast():
    assert get('VAR', str, required=False, default=True) is True
Beispiel #4
0
def test_fail_invalid_default(invalid):
    with pytest.raises(AssertionError) as e:
        get('VAR', str, required=False, default='noempty', validate=invalid)
    assert str(e.value) == "assert 'noempty' == False"
Beispiel #5
0
def test_required_and_default():
    with pytest.raises(AttributeError) as e:
        get('VAR', str, default=True)
    assert str(e.value) == 'VAR is required'
Beispiel #6
0
def test_not_required_and_default():
    assert get('VAR', bool, required=False, default=True) is True
Beispiel #7
0
def test_not_required():
    assert get('STR', str, required=False) is None
Beispiel #8
0
def test_required():
    with pytest.raises(AttributeError) as e:
        get('VAR', str)
    assert str(e.value) == 'VAR is required'
Beispiel #9
0
def test_cast(test, output, cast, argtest, monkeypatch):
    monkeypatch.setenv('VAR', test)
    argtest.casted(cast)
    assert get('VAR', argtest) == output
    assert argtest.arg == test
Beispiel #10
0
def test_fail_validation(invalid, monkeypatch):
    monkeypatch.setenv('VAR', 'noempty')
    with pytest.raises(AssertionError) as e:
        get('VAR', str, validate=invalid)
    assert str(e.value) == "assert 'noempty' == False"
Beispiel #11
0
def test_not_valid_cast(monkeypatch):
    monkeypatch.setenv('VAR', 'str')
    with pytest.raises(ValueError) as e:
        get('VAR', None)
    assert str(e.value) == 'cast: NoneType is not a callable'