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

Method _test_empty_init

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

Source from the content-addressed store, hash-verified

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