MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / variation

Function variation

lib/sqlalchemy/testing/config.py:233–299  ·  view source on GitHub ↗

a helper around testing.combinations that provides a single namespace that can be used as a switch. e.g.:: @testing.variation("querytyp", ["select", "subquery", "legacy_query"]) @testing.variation("lazy", ["select", "raise", "raise_on_sql"]) def test_thing(self, que

(argname_or_fn, cases=None)

Source from the content-addressed store, hash-verified

231
232
233def variation(argname_or_fn, cases=None):
234 """a helper around testing.combinations that provides a single namespace
235 that can be used as a switch.
236
237 e.g.::
238
239 @testing.variation("querytyp", ["select", "subquery", "legacy_query"])
240 @testing.variation("lazy", ["select", "raise", "raise_on_sql"])
241 def test_thing(self, querytyp, lazy, decl_base):
242 class Thing(decl_base):
243 __tablename__ = "thing"
244
245 # use name directly
246 rel = relationship("Rel", lazy=lazy.name)
247
248 # use as a switch
249 if querytyp.select:
250 stmt = select(Thing)
251 elif querytyp.subquery:
252 stmt = select(Thing).subquery()
253 elif querytyp.legacy_query:
254 stmt = Session.query(Thing)
255 else:
256 querytyp.fail()
257
258 The variable provided is a slots object of boolean variables, as well
259 as the name of the case itself under the attribute ".name"
260
261 """
262
263 if inspect.isfunction(argname_or_fn):
264 argname = argname_or_fn.__name__
265 cases = argname_or_fn(None)
266
267 @variation_fixture(argname, cases)
268 def go(self, request):
269 yield request.param
270
271 return go
272 else:
273 argname = argname_or_fn
274 cases_plus_limitations = [
275 (
276 entry
277 if (isinstance(entry, tuple) and len(entry) == 2)
278 else (entry, None)
279 )
280 for entry in cases
281 ]
282
283 variations = Variation.generate_cases(
284 argname, [c for c, l in cases_plus_limitations]
285 )
286 return combinations(
287 *[
288 (
289 (variation._name, variation, limitation)
290 if limitation is not None

Callers

nothing calls this directly

Calls 2

combinationsFunction · 0.85
generate_casesMethod · 0.80

Tested by

no test coverage detected