test #11306
(self, connection, pos, texttype)
| 2676 | @testing.combinations((None,), (0,), (1,), (2,), argnames="pos") |
| 2677 | @testing.variation("texttype", ["literal", "text"]) |
| 2678 | def test_dupe_col_targeting(self, connection, pos, texttype): |
| 2679 | """test #11306""" |
| 2680 | |
| 2681 | keyed2 = self.tables.keyed2 |
| 2682 | col = keyed2.c.b |
| 2683 | data_value = "b2" |
| 2684 | |
| 2685 | cols = [col, col, col] |
| 2686 | expected = [data_value, data_value, data_value] |
| 2687 | |
| 2688 | if pos is not None: |
| 2689 | if texttype.literal: |
| 2690 | cols[pos] = literal_column("10") |
| 2691 | elif texttype.text: |
| 2692 | cols[pos] = text("10") |
| 2693 | else: |
| 2694 | texttype.fail() |
| 2695 | |
| 2696 | expected[pos] = 10 |
| 2697 | |
| 2698 | stmt = select(*cols) |
| 2699 | |
| 2700 | result = connection.execute(stmt) |
| 2701 | |
| 2702 | if texttype.text and pos is not None: |
| 2703 | # when using text(), the name of the col is taken from |
| 2704 | # cursor.description directly since we don't know what's |
| 2705 | # inside a text() |
| 2706 | key_for_text_col = result.cursor.description[pos][0] |
| 2707 | elif texttype.literal and pos is not None: |
| 2708 | # for literal_column(), we use the text |
| 2709 | key_for_text_col = "10" |
| 2710 | |
| 2711 | eq_(result.all(), [tuple(expected)]) |
| 2712 | |
| 2713 | result = connection.execute(stmt).mappings() |
| 2714 | if pos is None: |
| 2715 | eq_(set(result.keys()), {"b", "b__1", "b__2"}) |
| 2716 | eq_( |
| 2717 | result.all(), |
| 2718 | [{"b": data_value, "b__1": data_value, "b__2": data_value}], |
| 2719 | ) |
| 2720 | |
| 2721 | else: |
| 2722 | eq_(set(result.keys()), {"b", "b__1", key_for_text_col}) |
| 2723 | |
| 2724 | eq_( |
| 2725 | result.all(), |
| 2726 | [{"b": data_value, "b__1": data_value, key_for_text_col: 10}], |
| 2727 | ) |
| 2728 | |
| 2729 | def test_columnclause_schema_column_one(self, connection): |
| 2730 | # originally addressed by [ticket:2932], however liberalized |