Example #1
0
def test_clear():
    bx = OrderedDiot()
    bx.a = 1
    bx.c = 4
    bx['g'] = 7
    bx.d = 2
    assert list(bx.keys()) == ['a', 'c', 'g', 'd']
    bx.clear()
    assert bx == {}
    assert list(bx.keys()) == []
    assert bx.__diot__['orderedkeys'] == []
Example #2
0
def test_ordered_box():
    bx = OrderedDiot(h=1)
    bx.a = 1
    bx.c = 4
    bx['g'] = 7
    bx.d = 2
    assert list(bx.keys()) == ['h', 'a', 'c', 'g', 'd']
    del bx.a
    bx.pop('c')
    bx.__delattr__('g')
    assert list(bx.keys()) == ['h', 'd']
Example #3
0
def test_inheritance_copy():
    class Box2(Diot):
        pass

    b = Box2(a=1)
    c = b.copy()
    assert c == b
    assert isinstance(c, Diot)
    c = b.__copy__()
    assert c == b
    assert isinstance(c, Diot)

    d = OrderedDiot()
    d.b = 1
    d.a = 0
    d.x = 9
    assert list(d.copy().keys()) == ['b', 'a', 'x']
Example #4
0
def test_revesed():
    bx = OrderedDiot()
    bx.a = 1
    bx.c = 2
    assert list(reversed(bx)) == ['c', 'a']
Example #5
0
def test_iter():
    bx = OrderedDiot()
    bx.a = 1
    bx.c = 2
    assert list(bx.__iter__()) == ['a', 'c']