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

Method _test_adapter

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

Source from the content-addressed store, hash-verified

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