Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 3
0
def test_value_extractor_order_keys():
    v = ValueExtractor(MergeDict(a=1))
    assert list(v.new_child(b=1)) == ['a', 'b']
    assert list(v.new_parent(b=1)) == ['a', 'b']
    assert list(v.new_parent(b=1).new_child(c=1)) == ['a', 'b', 'c']