MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_set

Method _test_set

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

Source from the content-addressed store, hash-verified

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

Callers 4

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

Calls 15

listenMethod · 0.95
expect_raisesFunction · 0.90
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

Tested by

no test coverage detected