el = Element()
x = Bar()
x.element = el
- eq_(attributes.get_history(attributes.instance_state(x), 'element'), ([el],[], []))
+ eq_(attributes.get_history(attributes.instance_state(x), 'element'), ([el], (), ()))
attributes.instance_state(x).commit_all()
(added, unchanged, deleted) = attributes.get_history(attributes.instance_state(x), 'element')
- assert added == []
+ assert added == ()
assert unchanged == [el]
def test_lazyhistory(self):
# case 1. new object
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), (), ()))
f.someattr = "hi"
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['hi'], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['hi'], (), ()))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['hi'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['hi'], ()))
f.someattr = 'there'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['there'], [], ['hi']))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['there'], (), ['hi']))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['there'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['there'], ()))
del f.someattr
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], ['there']))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), (), ['there']))
# case 2. object with direct dictionary settings (similar to a load operation)
f = Foo()
f.__dict__['someattr'] = 'new'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['new'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['new'], ()))
f.someattr = 'old'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['old'], [], ['new']))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['old'], (), ['new']))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['old'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['old'], ()))
# setting None on uninitialized is currently a change for a scalar attribute
# no lazyload occurs so this allows overwrite operation to proceed
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), (), ()))
f.someattr = None
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], (), ()))
f = Foo()
f.__dict__['someattr'] = 'new'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['new'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['new'], ()))
f.someattr = None
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], [], ['new']))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], (), ['new']))
# set same value twice
f = Foo()
attributes.instance_state(f).commit(['someattr'])
f.someattr = 'one'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['one'], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['one'], (), ()))
f.someattr = 'two'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['two'], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['two'], (), ()))
def test_mutable_scalar(self):
# case 1. new object
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), (), ()))
f.someattr = {'foo':'hi'}
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([{'foo':'hi'}], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([{'foo':'hi'}], (), ()))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [{'foo':'hi'}], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [{'foo':'hi'}], ()))
eq_(attributes.instance_state(f).committed_state['someattr'], {'foo':'hi'})
f.someattr['foo'] = 'there'
eq_(attributes.instance_state(f).committed_state['someattr'], {'foo':'hi'})
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([{'foo':'there'}], [], [{'foo':'hi'}]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([{'foo':'there'}], (), [{'foo':'hi'}]))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [{'foo':'there'}], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [{'foo':'there'}], ()))
# case 2. object with direct dictionary settings (similar to a load operation)
f = Foo()
f.__dict__['someattr'] = {'foo':'new'}
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [{'foo':'new'}], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [{'foo':'new'}], ()))
f.someattr = {'foo':'old'}
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([{'foo':'old'}], [], [{'foo':'new'}]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([{'foo':'old'}], (), [{'foo':'new'}]))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [{'foo':'old'}], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [{'foo':'old'}], ()))
def test_use_object(self):
# case 1. new object
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [None], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [None], ()))
f.someattr = hi
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([hi], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([hi], (), ()))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [hi], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [hi], ()))
f.someattr = there
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([there], [], [hi]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([there], (), [hi]))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [there], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [there], ()))
del f.someattr
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], [], [there]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], (), [there]))
# case 2. object with direct dictionary settings (similar to a load operation)
f = Foo()
f.__dict__['someattr'] = 'new'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['new'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['new'], ()))
f.someattr = old
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([old], [], ['new']))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([old], (), ['new']))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [old], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [old], ()))
# setting None on uninitialized is currently not a change for an object attribute
# (this is different than scalar attribute). a lazyload has occured so if its
# None, its really None
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [None], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [None], ()))
f.someattr = None
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [None], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [None], ()))
f = Foo()
f.__dict__['someattr'] = 'new'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], ['new'], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), ['new'], ()))
f.someattr = None
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], [], ['new']))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([None], (), ['new']))
# set same value twice
f = Foo()
attributes.instance_state(f).commit(['someattr'])
f.someattr = 'one'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['one'], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['one'], (), ()))
f.someattr = 'two'
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['two'], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), (['two'], (), ()))
def test_object_collections_set(self):
class Foo(_base.BasicEntity):
# case 1. new object
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [], ()))
f.someattr = [hi]
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([hi], [], []))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [hi], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [hi], ()))
f.someattr = [there]
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([there], [], [hi]))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [there], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [there], ()))
f.someattr = [hi]
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([hi], [], [there]))
collection = attributes.init_collection(attributes.instance_state(f), 'someattr')
collection.append_without_event(new)
attributes.instance_state(f).commit_all()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [new], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [new], ()))
f.someattr = [old]
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([old], [], [new]))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [old], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [old], ()))
def test_dict_collections(self):
class Foo(_base.BasicEntity):
new = Bar(name='new')
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [], ()))
f.someattr['hi'] = hi
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([hi], [], []))
f.someattr['there'] = there
- eq_(tuple([set(x) for x in attributes.get_history(attributes.instance_state(f), 'someattr')]), (set([hi, there]), set([]), set([])))
+ eq_(tuple([set(x) for x in attributes.get_history(attributes.instance_state(f), 'someattr')]), (set([hi, there]), set(), set()))
attributes.instance_state(f).commit(['someattr'])
- eq_(tuple([set(x) for x in attributes.get_history(attributes.instance_state(f), 'someattr')]), (set([]), set([hi, there]), set([])))
+ eq_(tuple([set(x) for x in attributes.get_history(attributes.instance_state(f), 'someattr')]), (set(), set([hi, there]), set()))
def test_object_collections_mutate(self):
class Foo(_base.BasicEntity):
# case 1. new object
f = Foo(id=1)
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [], ()))
f.someattr.append(hi)
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([hi], [], []))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [hi], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [hi], ()))
f.someattr.append(there)
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([there], [hi], []))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [hi, there], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [hi, there], ()))
f.someattr.remove(there)
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [hi], [there]))
f.someattr.append(new)
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([old, new], [hi], [there]))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [hi, old, new], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [hi, old, new], ()))
f.someattr.pop(0)
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [old, new], [hi]))
collection = attributes.init_collection(attributes.instance_state(f), 'someattr')
collection.append_without_event(new)
attributes.instance_state(f).commit_all()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [new], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [new], ()))
f.someattr.append(old)
eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([old], [new], []))
attributes.instance_state(f).commit(['someattr'])
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [new, old], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [new, old], ()))
f = Foo()
collection = attributes.init_collection(attributes.instance_state(f), 'someattr')
collection.append_without_event(new)
attributes.instance_state(f).commit_all()
- eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ([], [new], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'someattr'), ((), [new], ()))
f.id = 1
f.someattr.remove(new)
f1 = Foo()
b1 = Bar()
- eq_(attributes.get_history(attributes.instance_state(f1), 'bars'), ([], [], []))
- eq_(attributes.get_history(attributes.instance_state(b1), 'foo'), ([], [None], []))
+ eq_(attributes.get_history(attributes.instance_state(f1), 'bars'), ((), [], ()))
+ eq_(attributes.get_history(attributes.instance_state(b1), 'foo'), ((), [None], ()))
#b1.foo = f1
f1.bars.append(b1)
eq_(attributes.get_history(attributes.instance_state(f1), 'bars'), ([b1], [], []))
- eq_(attributes.get_history(attributes.instance_state(b1), 'foo'), ([f1], [], []))
+ eq_(attributes.get_history(attributes.instance_state(b1), 'foo'), ([f1], (), ()))
b2 = Bar()
f1.bars.append(b2)
eq_(attributes.get_history(attributes.instance_state(f1), 'bars'), ([b1, b2], [], []))
- eq_(attributes.get_history(attributes.instance_state(b1), 'foo'), ([f1], [], []))
- eq_(attributes.get_history(attributes.instance_state(b2), 'foo'), ([f1], [], []))
+ eq_(attributes.get_history(attributes.instance_state(b1), 'foo'), ([f1], (), ()))
+ eq_(attributes.get_history(attributes.instance_state(b2), 'foo'), ([f1], (), ()))
def test_lazy_backref_collections(self):
class Foo(_base.BasicEntity):
lazy_load = [bar1, bar2, bar3]
attributes.instance_state(f).expire_attributes(['bars'])
- eq_(attributes.get_history(attributes.instance_state(f), 'bars'), ([], [bar1, bar2, bar3], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bars'), ((), [bar1, bar2, bar3], ()))
def test_collections_via_lazyload(self):
class Foo(_base.BasicEntity):
f = Foo()
eq_(f.bar, "hi")
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([], ["hi"], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ((), ["hi"], ()))
f = Foo()
f.bar = None
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], (), ()))
f = Foo()
f.bar = "there"
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), (["there"], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), (["there"], (), ()))
f.bar = "hi"
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), (["hi"], [], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), (["hi"], (), ()))
f = Foo()
eq_(f.bar, "hi")
del f.bar
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([], [], ["hi"]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ((), (), ["hi"]))
assert f.bar is None
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], [], ["hi"]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], (), ["hi"]))
def test_scalar_object_via_lazyload(self):
class Foo(_base.BasicEntity):
# operations
f = Foo()
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([], [bar1], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ((), [bar1], ()))
f = Foo()
f.bar = None
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], [], [bar1]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], (), [bar1]))
f = Foo()
f.bar = bar2
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([bar2], [], [bar1]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([bar2], (), [bar1]))
f.bar = bar1
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([], [bar1], []))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ((), [bar1], ()))
f = Foo()
eq_(f.bar, bar1)
del f.bar
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], [], [bar1]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], (), [bar1]))
assert f.bar is None
- eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], [], [bar1]))
+ eq_(attributes.get_history(attributes.instance_state(f), 'bar'), ([None], (), [bar1]))
if __name__ == "__main__":