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

Method test_dupe_col_targeting

test/sql/test_resultset.py:2591–2640  ·  view source on GitHub ↗

test #11306

(self, connection, pos, texttype)

Source from the content-addressed store, hash-verified

2589 @testing.combinations((None,), (0,), (1,), (2,), argnames="pos")
2590 @testing.variation("texttype", ["literal", "text"])
2591 def test_dupe_col_targeting(self, connection, pos, texttype):
2592 """test #11306"""
2593
2594 keyed2 = self.tables.keyed2
2595 col = keyed2.c.b
2596 data_value = "b2"
2597
2598 cols = [col, col, col]
2599 expected = [data_value, data_value, data_value]
2600
2601 if pos is not None:
2602 if texttype.literal:
2603 cols[pos] = literal_column("10")
2604 elif texttype.text:
2605 cols[pos] = text("10")
2606 else:
2607 texttype.fail()
2608
2609 expected[pos] = 10
2610
2611 stmt = select(*cols)
2612
2613 result = connection.execute(stmt)
2614
2615 if texttype.text and pos is not None:
2616 # when using text(), the name of the col is taken from
2617 # cursor.description directly since we don't know what's
2618 # inside a text()
2619 key_for_text_col = result.cursor.description[pos][0]
2620 elif texttype.literal and pos is not None:
2621 # for literal_column(), we use the text
2622 key_for_text_col = "10"
2623
2624 eq_(result.all(), [tuple(expected)])
2625
2626 result = connection.execute(stmt).mappings()
2627 if pos is None:
2628 eq_(set(result.keys()), {"b", "b__1", "b__2"})
2629 eq_(
2630 result.all(),
2631 [{"b": data_value, "b__1": data_value, "b__2": data_value}],
2632 )
2633
2634 else:
2635 eq_(set(result.keys()), {"b", "b__1", key_for_text_col})
2636
2637 eq_(
2638 result.all(),
2639 [{"b": data_value, "b__1": data_value, key_for_text_col: 10}],
2640 )
2641
2642 def test_columnclause_schema_column_one(self, connection):
2643 # originally addressed by [ticket:2932], however liberalized

Callers

nothing calls this directly

Calls 9

literal_columnFunction · 0.90
textFunction · 0.90
selectFunction · 0.90
eq_Function · 0.90
failMethod · 0.45
executeMethod · 0.45
allMethod · 0.45
mappingsMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected