Exemple #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'
Exemple #2
0
def test_smoke(monkeypatch):
    monkeypatch.setenv('VAR', 'str')
    assert get('VAR', str) == 'str'
Exemple #3
0
def test_default_ignore_cast():
    assert get('VAR', str, required=False, default=True) is True
Exemple #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"
Exemple #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'
Exemple #6
0
def test_not_required_and_default():
    assert get('VAR', bool, required=False, default=True) is True
Exemple #7
0
def test_not_required():
    assert get('STR', str, required=False) is None
Exemple #8
0
def test_required():
    with pytest.raises(AttributeError) as e:
        get('VAR', str)
    assert str(e.value) == 'VAR is required'
Exemple #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
Exemple #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"
Exemple #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'