MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_conflicting_names

Method test_conflicting_names

test/sql/test_cte.py:497–540  ·  view source on GitHub ↗

test a flat out name conflict.

(self, identical, clone_type)

Source from the content-addressed store, hash-verified

495 @testing.combinations(True, False, argnames="identical")
496 @testing.variation("clone_type", ["none", "clone", "annotated"])
497 def test_conflicting_names(self, identical, clone_type):
498 """test a flat out name conflict."""
499
500 s1 = select(1)
501 c1 = s1.cte(name="cte1", recursive=True)
502 if clone_type.clone:
503 c2 = c1._clone()
504 if not identical:
505 c2 = c2.union(select(2))
506 elif clone_type.annotated:
507 # this does not seem to trigger the issue that was fixed in
508 # #12364 however is still a worthy test
509 c2 = c1._annotate({"foo": "bar"})
510 if not identical:
511 c2 = c2.union(select(2))
512 else:
513 if identical:
514 s2 = select(1)
515 else:
516 s2 = select(column("q"))
517 c2 = s2.cte(name="cte1", recursive=True)
518
519 s = select(c1, c2)
520
521 if clone_type.clone and identical:
522 self.assert_compile(
523 s,
524 'WITH RECURSIVE cte1("1") AS (SELECT 1) SELECT cte1.1, '
525 'cte1.1 AS "1_1" FROM cte1',
526 )
527 elif clone_type.annotated and identical:
528 # annotated seems to have a slightly different rendering
529 # scheme here
530 self.assert_compile(
531 s,
532 'WITH RECURSIVE cte1("1") AS (SELECT 1) SELECT cte1.1, '
533 'cte1.1 AS "1__1" FROM cte1',
534 )
535 else:
536 assert_raises_message(
537 CompileError,
538 "Multiple, unrelated CTEs found with the same name: 'cte1'",
539 s.compile,
540 )
541
542 @testing.variation("annotated", [True, False])
543 def test_cte_w_annotated(self, annotated):

Callers

nothing calls this directly

Calls 8

selectFunction · 0.90
columnFunction · 0.90
assert_raises_messageFunction · 0.90
assert_compileMethod · 0.80
cteMethod · 0.45
_cloneMethod · 0.45
unionMethod · 0.45
_annotateMethod · 0.45

Tested by

no test coverage detected