MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / flag_combinations

Function flag_combinations

lib/sqlalchemy/testing/util.py:238–284  ·  view source on GitHub ↗

A facade around @testing.combinations() oriented towards boolean keyword-based arguments. Basically generates a nice looking identifier based on the keywords and also sets up the argument names. E.g.:: @testing.flag_combinations( dict(lazy=False, passive=False)

(*combinations)

Source from the content-addressed store, hash-verified

236
237
238def flag_combinations(*combinations):
239 """A facade around @testing.combinations() oriented towards boolean
240 keyword-based arguments.
241
242 Basically generates a nice looking identifier based on the keywords
243 and also sets up the argument names.
244
245 E.g.::
246
247 @testing.flag_combinations(
248 dict(lazy=False, passive=False),
249 dict(lazy=True, passive=False),
250 dict(lazy=False, passive=True),
251 dict(lazy=False, passive=True, raiseload=True),
252 )
253 def test_fn(lazy, passive, raiseload): ...
254
255 would result in::
256
257 @testing.combinations(
258 ("", False, False, False),
259 ("lazy", True, False, False),
260 ("lazy_passive", True, True, False),
261 ("lazy_passive", True, True, True),
262 id_="iaaa",
263 argnames="lazy,passive,raiseload",
264 )
265 def test_fn(lazy, passive, raiseload): ...
266
267 """
268
269 keys = set()
270
271 for d in combinations:
272 keys.update(d)
273
274 keys = sorted(keys)
275
276 return config.combinations(
277 *[
278 ("_".join(k for k in keys if d.get(k, False)),)
279 + tuple(d.get(k, False) for k in keys)
280 for d in combinations
281 ],
282 id_="i" + ("a" * len(keys)),
283 argnames=",".join(keys),
284 )
285
286
287def lambda_combinations(lambda_arg_sets, **kw):

Callers

nothing calls this directly

Calls 4

updateMethod · 0.45
combinationsMethod · 0.45
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected