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

Method _test_instance_guards

test/orm/test_session.py:2144–2199  ·  view source on GitHub ↗
(self, user_arg)

Source from the content-addressed store, hash-verified

2142 )
2143
2144 def _test_instance_guards(self, user_arg):
2145 watchdog = set()
2146
2147 def x_raises_(obj, method, *args, **kw):
2148 watchdog.add(method)
2149 callable_ = getattr(obj, method)
2150 assert_raises(
2151 sa.orm.exc.UnmappedInstanceError, callable_, *args, **kw
2152 )
2153
2154 def raises_(method, *args, **kw):
2155 x_raises_(fixture_session(), method, *args, **kw)
2156
2157 for name in [
2158 "__contains__",
2159 "is_modified",
2160 "merge",
2161 "refresh",
2162 "add",
2163 "delete",
2164 "expire",
2165 "expunge",
2166 "enable_relationship_loading",
2167 ]:
2168 raises_(name, user_arg)
2169
2170 raises_("add_all", (user_arg,))
2171
2172 # flush will no-op without something in the unit of work
2173 def _():
2174 class OK:
2175 pass
2176
2177 self._map_it(OK)
2178
2179 s = fixture_session()
2180 s.add(OK())
2181 x_raises_(s, "flush", objects=(user_arg,))
2182
2183 _()
2184
2185 instance_methods = (
2186 self._public_session_methods()
2187 - self._class_methods
2188 - {
2189 "bulk_update_mappings",
2190 "bulk_insert_mappings",
2191 "bulk_save_objects",
2192 }
2193 )
2194
2195 eq_(
2196 watchdog,
2197 instance_methods,
2198 watchdog.symmetric_difference(instance_methods),
2199 )
2200
2201 def _test_class_guards(self, user_arg, is_class=True):

Calls 3

eq_Function · 0.90
symmetric_differenceMethod · 0.45

Tested by

no test coverage detected