示例#1
0
def test_value_extractor():
    e = ValueExtractor(os.environ)
    assert isinstance(e.get_path('HOME'), Path)
    v = ValueExtractor({'a': {'b': 1, 'c': None}, 'env': e})
    assert isinstance(v.get('a'), ValueExtractor)
    assert v.a.get_int('b') is v.a.b
    assert v.env is e

    with pytest.raises(RuntimeError):
        v.x = 1

    with pytest.raises(TypeError):
        v.a.get_int('c')
    assert v.a.get_int('c', null=True) is None

    with pytest.raises(AttributeError):
        getattr(v, '_a')

    assert repr(v)
示例#2
0
def test_value_extractor():
    e = ValueExtractor(os.environ)
    if os.name == 'nt':
        os.environ.setdefault(
            'HOME',
            os.environ['HOMEDRIVE'] + os.environ['HOMEPATH'],
        )
    assert isinstance(e.get_path('HOME'), Path)
    v = ValueExtractor({'a': {'b': 1, 'c': None}, 'env': e})
    assert isinstance(v.get('a'), ValueExtractor)
    assert v.a.get_int('b') is v.a.b
    assert v.env._val == e._val

    with pytest.raises(RuntimeError):
        v.x = 1

    with pytest.raises(TypeError):
        v.a.get_int('c')
    assert v.a.get_int('c', null=True) is None

    with pytest.raises(AttributeError):
        getattr(v, '_a')

    assert repr(v)