MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_dict_wo_mutation

Method _test_dict_wo_mutation

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

Source from the content-addressed store, hash-verified

1202 self.assert_(getattr(SetIsh, "_sa_instrumented") == id(SetIsh))
1203
1204 def _test_dict_wo_mutation(self, typecallable, creator=None):
1205 if creator is None:
1206 creator = self.dictable_entity
1207
1208 class Foo:
1209 pass
1210
1211 canary = Canary()
1212 instrumentation.register_class(Foo)
1213 d = _register_attribute(
1214 Foo,
1215 "attr",
1216 uselist=True,
1217 typecallable=typecallable,
1218 useobject=True,
1219 )
1220 canary.listen(d)
1221
1222 obj = Foo()
1223
1224 e = creator()
1225
1226 obj.attr[e.a] = e
1227 assert e in canary.added
1228 assert e not in canary.appended_wo_mutation
1229
1230 with canary.defer_dupe_check():
1231 # __setitem__ sets every time
1232 obj.attr[e.a] = e
1233 assert e in canary.added
1234 assert e not in canary.appended_wo_mutation
1235
1236 if hasattr(obj.attr, "update"):
1237 e = creator()
1238 obj.attr.update({e.a: e})
1239 assert e in canary.added
1240 assert e not in canary.appended_wo_mutation
1241
1242 obj.attr.update({e.a: e})
1243 assert e in canary.added
1244 assert e in canary.appended_wo_mutation
1245
1246 e = creator()
1247 obj.attr.update(**{e.a: e})
1248 assert e in canary.added
1249 assert e not in canary.appended_wo_mutation
1250
1251 obj.attr.update(**{e.a: e})
1252 assert e in canary.added
1253 assert e in canary.appended_wo_mutation
1254
1255 if hasattr(obj.attr, "setdefault"):
1256 e = creator()
1257 obj.attr.setdefault(e.a, e)
1258 assert e in canary.added
1259 assert e not in canary.appended_wo_mutation
1260
1261 obj.attr.setdefault(e.a, e)

Callers 5

test_dict_subclassMethod · 0.95
test_dict_subclass2Method · 0.95
test_dict_subclass3Method · 0.95
test_dict_duckMethod · 0.95
test_dict_emulatesMethod · 0.95

Calls 8

listenMethod · 0.95
defer_dupe_checkMethod · 0.95
CanaryClass · 0.85
creatorFunction · 0.85
_register_attributeFunction · 0.70
FooClass · 0.70
updateMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected