MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _test_set

Method _test_set

test/orm/test_collection.py:761–1027  ·  view source on GitHub ↗
(self, typecallable, creator=None)

Source from the content-addressed store, hash-verified

759 assert e in canary.appended_wo_mutation
760
761 def _test_set(self, typecallable, creator=None):
762 if creator is None:
763 creator = self.entity_maker
764
765 class Foo:
766 pass
767
768 canary = Canary()
769 instrumentation.register_class(Foo)
770 d = _register_attribute(
771 Foo,
772 "attr",
773 uselist=True,
774 typecallable=typecallable,
775 useobject=True,
776 )
777 canary.listen(d)
778
779 obj = Foo()
780 adapter = collections.collection_adapter(obj.attr)
781 direct = obj.attr
782 control = set()
783
784 def assert_eq():
785 eq_(set(direct), canary.data)
786 eq_(set(adapter), canary.data)
787 eq_(direct, control)
788
789 def addall(*values):
790 for item in values:
791 direct.add(item)
792 control.add(item)
793 assert_eq()
794
795 def zap():
796 for item in list(direct):
797 direct.remove(item)
798 control.clear()
799
800 addall(creator())
801
802 e = creator()
803 addall(e)
804 addall(e)
805
806 if hasattr(direct, "remove"):
807 e = creator()
808 addall(e)
809
810 direct.remove(e)
811 control.remove(e)
812 assert_eq()
813
814 e = creator()
815 try:
816 direct.remove(e)
817 except KeyError:
818 assert_eq()

Callers 4

test_setMethod · 0.95
test_set_subclassMethod · 0.95
test_set_duckMethod · 0.95
test_set_emulatesMethod · 0.95

Calls 14

listenMethod · 0.95
CanaryClass · 0.85
creatorFunction · 0.85
_register_attributeFunction · 0.70
FooClass · 0.70
removeMethod · 0.45
assert_Method · 0.45
discardMethod · 0.45
updateMethod · 0.45
clearMethod · 0.45
popMethod · 0.45
difference_updateMethod · 0.45

Tested by

no test coverage detected