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

Method test_copy

test/sql/test_metadata.py:1057–1111  ·  view source on GitHub ↗
(self, metadata, copy_fixture, copy_tables_fixture)

Source from the content-addressed store, hash-verified

1055
1056 @testing.requires.check_constraints
1057 def test_copy(self, metadata, copy_fixture, copy_tables_fixture):
1058
1059 table, table2, table3 = copy_fixture
1060 table_c, table2_c, table3_c, (has_constraints, reflect) = (
1061 copy_tables_fixture
1062 )
1063
1064 self.assert_tables_equal(table, table_c)
1065 self.assert_tables_equal(table2, table2_c)
1066 assert table is not table_c
1067 assert table.primary_key is not table_c.primary_key
1068 assert list(table2_c.c.myid.foreign_keys)[0].column is table_c.c.myid
1069 assert list(table2_c.c.myid.foreign_keys)[0].column is not table.c.myid
1070 assert "x" in str(table_c.c.foo.server_default.arg)
1071 if not reflect:
1072 assert isinstance(table_c.c.myid.default, Sequence)
1073 assert str(table_c.c.foo.server_onupdate.arg) == "q"
1074 assert str(table_c.c.bar.default.arg) == "y"
1075 assert (
1076 getattr(
1077 table_c.c.bar.onupdate.arg,
1078 "arg",
1079 table_c.c.bar.onupdate.arg,
1080 )
1081 == "z"
1082 )
1083 assert isinstance(table2_c.c.id.default, Sequence)
1084
1085 if testing.requires.unique_constraint_reflection.enabled:
1086 for c in table_c.constraints:
1087 if isinstance(c, UniqueConstraint):
1088 break
1089 else:
1090 for c in table_c.indexes:
1091 break
1092 else:
1093 assert False
1094
1095 assert c.columns.contains_column(table_c.c.name)
1096 assert not c.columns.contains_column(table.c.name)
1097
1098 # CHECK constraints don't get reflected for any dialect right
1099 # now
1100
1101 if has_constraints:
1102 for c in table_c.c.description.constraints:
1103 if isinstance(c, CheckConstraint):
1104 break
1105 else:
1106 assert False
1107 assert str(c.sqltext) == "description='hi'"
1108
1109 if testing.requires.comment_reflection.enabled:
1110 eq_(table3_c.comment, "table comment")
1111 eq_(table3_c.c.foo.comment, "some column")
1112
1113 def test_col_key_fk_parent(self):
1114 # test #2643

Callers

nothing calls this directly

Calls 3

eq_Function · 0.90
assert_tables_equalMethod · 0.80
contains_columnMethod · 0.45

Tested by

no test coverage detected