MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_empty_init

Method _test_empty_init

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

Source from the content-addressed store, hash-verified

201 self._test_empty_init(typecallable, creator=creator)
202
203 def _test_empty_init(self, typecallable, creator=None):
204 if creator is None:
205 creator = self.entity_maker
206
207 class Foo:
208 pass
209
210 instrumentation.register_class(Foo)
211 _register_attribute(
212 Foo,
213 "attr",
214 uselist=True,
215 typecallable=typecallable,
216 useobject=True,
217 )
218
219 obj = Foo()
220 e1 = creator()
221 e2 = creator()
222 implicit_collection = obj.attr
223 is_true("attr" not in obj.__dict__)
224 adapter = collections.collection_adapter(implicit_collection)
225 is_true(adapter.empty)
226 assert_raises_message(
227 sa_exc.InvalidRequestError,
228 "This is a special 'empty'",
229 adapter.append_without_event,
230 e1,
231 )
232
233 adapter.append_with_event(e1)
234 is_false(adapter.empty)
235 is_true("attr" in obj.__dict__)
236 adapter.append_without_event(e2)
237 eq_(set(adapter), {e1, e2})
238
239 def _test_list(self, typecallable, creator=None):
240 if creator is None:

Callers 1

_test_adapterMethod · 0.95

Calls 9

is_trueFunction · 0.90
assert_raises_messageFunction · 0.90
is_falseFunction · 0.90
eq_Function · 0.90
creatorFunction · 0.85
append_with_eventMethod · 0.80
append_without_eventMethod · 0.80
_register_attributeFunction · 0.70
FooClass · 0.70

Tested by

no test coverage detected