Exemplo n.º 1
0
def test_inherit():
    bag = Bag('a', a=1)
    bag2 = Bag.inherit('b', b=2, _parent=bag)
    bag3 = bag.extend('c', c=3)
    bag4 = Bag('d', d=4)

    assert bag.args == ('a', )
    assert bag.kwargs == {'a': 1}
    assert bag.flags is ()

    assert bag2.args == ('a', 'b', )
    assert bag2.kwargs == {'a': 1, 'b': 2}
    assert INHERIT_INPUT in bag2.flags

    assert bag3.args == ('a', 'c', )
    assert bag3.kwargs == {'a': 1, 'c': 3}
    assert bag3.flags is ()

    assert bag4.args == ('d', )
    assert bag4.kwargs == {'d': 4}
    assert bag4.flags is ()

    bag4.set_parent(bag)
    assert bag4.args == ('a', 'd', )
    assert bag4.kwargs == {'a': 1, 'd': 4}
    assert bag4.flags is ()

    bag4.set_parent(bag3)
    assert bag4.args == ('a', 'c', 'd', )
    assert bag4.kwargs == {'a': 1, 'c': 3, 'd': 4}
    assert bag4.flags is ()
Exemplo n.º 2
0
def test_pickle():
    bag1 = Bag('a', a=1)
    bag2 = Bag.inherit('b', b=2, _parent=bag1)
    bag3 = bag1.extend('c', c=3)
    bag4 = Bag('d', d=4)

    # XXX todo this probably won't work with inheriting bags if parent is not there anymore? maybe that's not true
    # because the parent may be in the serialization output but we need to verify this assertion.

    for bag in bag1, bag2, bag3, bag4:
        pickled = pickle.dumps(bag)
        unpickled = pickle.loads(pickled)
        assert unpickled == bag