Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit e65dede

Browse files
committed
Added more tests
1 parent b6cf899 commit e65dede

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

tests/test_diff_tables.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,8 @@ def test_duplicates(self):
770770
self.assertEqual(diff, self.diffs)
771771

772772

773+
@test_each_database
773774
class TestCompoundKeySimple1(DiffTestCase):
774-
db_cls = db.MySQL
775775
src_schema = {"id": int, "id2": int}
776776
dst_schema = {"id": int, "id2": int}
777777

@@ -804,8 +804,8 @@ def test_simple1(self):
804804
self.assertEqual(diff, expected)
805805

806806

807+
@test_each_database
807808
class TestCompoundKeySimple2(DiffTestCase):
808-
db_cls = db.MySQL
809809
src_schema = {"id": int, "id2": int}
810810
dst_schema = {"id": int, "id2": int}
811811

@@ -838,8 +838,42 @@ def test_simple2(self):
838838
self.assertEqual(diff, expected)
839839

840840

841+
@test_each_database
842+
class TestCompoundKeySimple3(DiffTestCase):
843+
src_schema = {"id": int, "id2": int}
844+
dst_schema = {"id": int, "id2": int}
845+
846+
def test_negative_keys(self):
847+
N = 1000
848+
K = -N + 1
849+
V1 = N + 1
850+
V2 = -N * 1000 + 2
851+
852+
diffs = [(i, i + N) for i in range(N)]
853+
self.connection.query(
854+
[
855+
self.src_table.insert_rows(diffs + [(K, V1)]),
856+
self.dst_table.insert_rows(diffs + [(K, V2)]),
857+
commit,
858+
]
859+
)
860+
861+
expected = {("-", (str(K), str(V1))), ("+", (str(K), str(V2)))}
862+
differ = HashDiffer()
863+
864+
a = TableSegment(self.connection, self.src_table.path, ("id",), extra_columns=("id2",))
865+
b = TableSegment(self.connection, self.dst_table.path, ("id",), extra_columns=("id2",))
866+
diff = set(differ.diff_tables(a, b))
867+
self.assertEqual(diff, expected)
868+
869+
aa = TableSegment(self.connection, self.src_table.path, ("id", "id2"))
870+
bb = TableSegment(self.connection, self.dst_table.path, ("id", "id2"))
871+
diff = set(differ.diff_tables(aa, bb))
872+
self.assertEqual(diff, expected)
873+
874+
875+
@test_each_database
841876
class TestCompoundKeyAlphanum(DiffTestCase):
842-
db_cls = db.MySQL
843877
src_schema = {"id": str, "id2": int, "comment": str}
844878
dst_schema = {"id": str, "id2": int, "comment": str}
845879

0 commit comments

Comments
 (0)