| 2072 | |
| 2073 | @testing.combinations(-4, -3, -2, -1, 0, 1, 2, 3) |
| 2074 | def test_replace_col_with_index(self, new_index): |
| 2075 | t = Table( |
| 2076 | "t", |
| 2077 | MetaData(), |
| 2078 | Column("a", Integer), |
| 2079 | Column("b", Integer), |
| 2080 | Column("c", Integer), |
| 2081 | Column("d", Integer), |
| 2082 | ) |
| 2083 | newcol = Column("b", String) |
| 2084 | |
| 2085 | expected = ["a", "q", "c", "d"] |
| 2086 | expected.insert(new_index, "b") |
| 2087 | expected.remove("q") |
| 2088 | |
| 2089 | t.insert_column(newcol, index=new_index, replace_existing=True) |
| 2090 | is_(t.c.b, newcol) |
| 2091 | is_(t.c.b.type._type_affinity, String) |
| 2092 | |
| 2093 | eq_([c.key for c in t.c], expected) |
| 2094 | |
| 2095 | effective_positive_index = ( |
| 2096 | new_index if new_index >= 0 else max(0, 4 + new_index) |
| 2097 | ) |
| 2098 | if effective_positive_index > 1: |
| 2099 | # because we replaced |
| 2100 | effective_positive_index -= 1 |
| 2101 | |
| 2102 | is_(t.c[effective_positive_index], newcol) |
| 2103 | |
| 2104 | @testing.combinations( |
| 2105 | ((0,),), ((0, 1),), ((1, 2),), ((3,),), argnames="positions" |