MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_associatives

Method test_associatives

test/sql/test_operators.py:494–536  ·  view source on GitHub ↗
(self, op, reverse, negate)

Source from the content-addressed store, hash-verified

492 @testing.combinations(True, False, argnames="reverse")
493 @testing.combinations(True, False, argnames="negate")
494 def test_associatives(self, op, reverse, negate):
495 t1 = table("t", column("q"), column("p"))
496
497 num = 500
498
499 expr = op(t1.c.q, t1.c.p)
500
501 if reverse:
502 for i in range(num - 1, -1, -1):
503 expr = op(column(f"d{i}"), expr)
504 else:
505 for i in range(num):
506 expr = op(expr, column(f"d{i}"))
507
508 opstring = compiler.OPERATORS[op]
509 exprs = opstring.join(f"d{i}" for i in range(num))
510
511 if negate:
512 self.assert_compile(
513 select(~expr),
514 (
515 f"SELECT NOT (t.q{opstring}t.p{opstring}{exprs}) "
516 "AS anon_1 FROM t"
517 if not reverse
518 else (
519 f"SELECT NOT ({exprs}{opstring}t.q{opstring}t.p) "
520 "AS anon_1 FROM t"
521 )
522 ),
523 )
524 else:
525 self.assert_compile(
526 select(expr),
527 (
528 f"SELECT t.q{opstring}t.p{opstring}{exprs} "
529 "AS anon_1 FROM t"
530 if not reverse
531 else (
532 f"SELECT {exprs}{opstring}t.q{opstring}t.p "
533 "AS anon_1 FROM t"
534 )
535 ),
536 )
537
538 @testing.combinations(
539 operators.gt,

Callers

nothing calls this directly

Calls 6

tableFunction · 0.90
columnFunction · 0.90
opFunction · 0.85
selectFunction · 0.85
assert_compileMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected