MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_adapter

Method _test_adapter

test/orm/test_collection.py:150–201  ·  test/orm/test_collection.py::CollectionsTest._test_adapter
(self, typecallable, creator=None, to_set=None)

Source from the content-addressed store, hash-verified

148 return cls.Entity(a or str(id_), b or class="st">"value %s" % id, c)
149
150 def _test_adapter(self, typecallable, creator=None, to_set=None):
151 if creator is None:
152 creator = self.entity_maker
153
154 class Foo:
155 pass
156
157 canary = Canary()
158 instrumentation.register_class(Foo)
159 d = _register_attribute(
160 Foo,
161 class="st">"attr",
162 uselist=True,
163 typecallable=typecallable,
164 useobject=True,
165 )
166 canary.listen(d)
167
168 obj = Foo()
169 adapter = collections.collection_adapter(obj.attr)
170 direct = obj.attr
171 if to_set is None:
172
173 def to_set(col):
174 return set(col)
175
176 def assert_eq():
177 self.assert_(to_set(direct) == canary.data)
178 self.assert_(set(adapter) == canary.data)
179
180 def assert_ne():
181 self.assert_(to_set(direct) != canary.data)
182
183 e1, e2 = creator(), creator()
184
185 adapter.append_with_event(e1)
186 assert_eq()
187
188 adapter.append_without_event(e2)
189 assert_ne()
190 canary.data.add(e2)
191 assert_eq()
192
193 adapter.remove_without_event(e2)
194 assert_ne()
195 canary.data.remove(e2)
196 assert_eq()
197
198 adapter.remove_with_event(e1)
199 assert_eq()
200
201 self._test_empty_init(typecallable, creator=creator)
202
203 def _test_empty_init(self, typecallable, creator=None):
204 if creator is None:

Callers 15

test_listMethod · 0.95
test_list_subclassMethod · 0.95
test_list_duckMethod · 0.95
test_list_emulatesMethod · 0.95
test_setMethod · 0.95
test_set_subclassMethod · 0.95
test_set_duckMethod · 0.95
test_set_emulatesMethod · 0.95
test_dict_subclassMethod · 0.95
test_dict_subclass2Method · 0.95
test_dict_subclass3Method · 0.95

Calls 12

listenMethod · 0.95
_test_empty_initMethod · 0.95
CanaryClass · 0.85
creatorFunction · 0.85
append_with_eventMethod · 0.80
append_without_eventMethod · 0.80
remove_without_eventMethod · 0.80
remove_with_eventMethod · 0.80
_register_attributeFunction · 0.70
FooClass · 0.70
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected