MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_replace_col_with_index

Method test_replace_col_with_index

test/sql/test_metadata.py:2074–2102  ·  view source on GitHub ↗
(self, new_index)

Source from the content-addressed store, hash-verified

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"

Callers

nothing calls this directly

Calls 9

insert_columnMethod · 0.95
TableClass · 0.90
MetaDataClass · 0.90
ColumnClass · 0.90
is_Function · 0.90
eq_Function · 0.90
maxClass · 0.85
insertMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected