Example #1
0
def test_source_sequence():

    d = DictNamedTuple([('a', 42)], a=43, b=45)

    assert list(d.keys()) == ['a', 'b']
    assert d.a == 43
    assert d['a'] == 43 and d['b'] == 45
Example #2
0
def test_source_mapping():

    d = DictNamedTuple({'a': 42}, a=43, b=45)

    assert list(d.keys()) == ['a', 'b']
    assert d.a == 43
    assert d['a'] == 43 and d['b'] == 45
Example #3
0
def test_missing():
    d = DictNamedTuple(foo=42, bar='42')

    with pytest.raises(KeyError):
        d['buz']
    with pytest.raises(AttributeError):
        d.buz
Example #4
0
def test_len():
    d = DictNamedTuple(foo=42, bar='42')
    assert len(d) == 2
Example #5
0
def test_source_error():

    with pytest.raises(TypeError):
        DictNamedTuple(100, a=43, b=45)
Example #6
0
def test_repr():
    d = DictNamedTuple(foo=42, bar='42')
    assert eval(repr(d)) == d
Example #7
0
def test_setattr():
    d1 = DictNamedTuple(foo=42, bar='42')
    with pytest.raises(AttributeError):
        d1.a = 100
Example #8
0
def test_eq():
    d1 = DictNamedTuple(foo=42, bar='42')
    d2 = DictNamedTuple(foo=42, bar='42')
    assert d1 == d2
    assert d1 != "foo"