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

Commit 779892d

Browse files
authored
Merge pull request #313 from datafold/nov24
Nov24 - Small fixes to tests
2 parents 15f7f84 + c2924f3 commit 779892d

File tree

14 files changed

+121
-167
lines changed

14 files changed

+121
-167
lines changed

data_diff/sqeleton/databases/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
121121

122122
class BaseDialect(AbstractDialect):
123123
SUPPORTS_PRIMARY_KEY = False
124+
SUPPORTS_INDEXES = False
124125
TYPE_CLASSES: Dict[str, type] = {}
125126

126127
def offset_limit(self, offset: Optional[int] = None, limit: Optional[int] = None):

data_diff/sqeleton/databases/databricks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
DbPath,
1414
ColType,
1515
UnknownColType,
16-
Boolean
16+
Boolean,
1717
)
1818
from ..abcs.mixins import AbstractMixin_MD5, AbstractMixin_NormalizeValue
1919
from .base import MD5_HEXDIGITS, CHECKSUM_HEXDIGITS, BaseDialect, ThreadedDatabase, import_helper, parse_table_name

data_diff/sqeleton/databases/duckdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Dialect(BaseDialect, Mixin_Schema):
5858
name = "DuckDB"
5959
ROUNDS_ON_PREC_LOSS = False
6060
SUPPORTS_PRIMARY_KEY = True
61+
SUPPORTS_INDEXES = True
6162

6263
TYPE_CLASSES = {
6364
# Timestamps

data_diff/sqeleton/databases/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Dialect(BaseDialect, Mixin_Schema):
5151
name = "MySQL"
5252
ROUNDS_ON_PREC_LOSS = True
5353
SUPPORTS_PRIMARY_KEY = True
54+
SUPPORTS_INDEXES = True
5455
TYPE_CLASSES = {
5556
# Dates
5657
"datetime": Datetime,

data_diff/sqeleton/databases/oracle.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,23 @@ def normalize_number(self, value: str, coltype: FractionalType) -> str:
5959
format_str += "0." + "9" * (coltype.precision - 1) + "0"
6060
return f"to_char({value}, '{format_str}')"
6161

62+
6263
class Mixin_Schema(AbstractMixin_Schema):
6364
def list_tables(self, table_schema: str, like: Compilable = None) -> Compilable:
6465
return (
65-
table('ALL_TABLES')
66+
table("ALL_TABLES")
6667
.where(
6768
this.OWNER == table_schema,
6869
this.TABLE_NAME.like(like) if like is not None else SKIP,
6970
)
70-
.select(table_name = this.TABLE_NAME)
71+
.select(table_name=this.TABLE_NAME)
7172
)
7273

7374

7475
class Dialect(BaseDialect, Mixin_Schema):
7576
name = "Oracle"
7677
SUPPORTS_PRIMARY_KEY = True
78+
SUPPORTS_INDEXES = True
7779
TYPE_CLASSES: Dict[str, type] = {
7880
"NUMBER": Decimal,
7981
"FLOAT": Float,

data_diff/sqeleton/databases/postgresql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class PostgresqlDialect(BaseDialect, Mixin_Schema):
5252
name = "PostgreSQL"
5353
ROUNDS_ON_PREC_LOSS = True
5454
SUPPORTS_PRIMARY_KEY = True
55+
SUPPORTS_INDEXES = True
5556

5657
TYPE_CLASSES = {
5758
# Timestamps

data_diff/table_segment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def source_table(self):
100100
return table(*self.table_path, schema=self._schema)
101101

102102
def make_select(self):
103-
return self.source_table.where(*self._make_key_range(), *self._make_update_range(), Code(self.where) if self.where else SKIP)
103+
return self.source_table.where(
104+
*self._make_key_range(), *self._make_update_range(), Code(self.where) if self.where else SKIP
105+
)
104106

105107
def get_values(self) -> list:
106108
"Download all the relevant values of the segment from the database"

tests/common.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,11 @@ def str_to_checksum(str: str):
129129
return int(md5[half_pos:], 16)
130130

131131

132-
class TestPerDatabase(unittest.TestCase):
132+
class DiffTestCase(unittest.TestCase):
133+
"Sets up two tables for diffing (doesn't create them)"
133134
db_cls = None
135+
src_schema = None
136+
dst_schema = None
134137

135138
def setUp(self):
136139
assert self.db_cls, self.db_cls
@@ -144,12 +147,16 @@ def setUp(self):
144147
self.table_src_path = self.connection.parse_table_name(self.table_src_name)
145148
self.table_dst_path = self.connection.parse_table_name(self.table_dst_name)
146149

147-
self.table_src = ".".join(map(self.connection.dialect.quote, self.table_src_path))
148-
self.table_dst = ".".join(map(self.connection.dialect.quote, self.table_dst_path))
149-
150150
drop_table(self.connection, self.table_src_path)
151151
drop_table(self.connection, self.table_dst_path)
152152

153+
if self.src_schema:
154+
self.src_table = table(self.table_src_path, schema=self.src_schema)
155+
self.connection.query(self.src_table.create())
156+
if self.dst_schema:
157+
self.dst_table = table(self.table_dst_path, schema=self.dst_schema)
158+
self.connection.query(self.dst_table.create())
159+
153160
return super().setUp()
154161

155162
def tearDown(self):

tests/sqeleton/test_database.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import unittest
33

44
from ..common import str_to_checksum, TEST_MYSQL_CONN_STRING
5-
from ..common import str_to_checksum, test_each_database_in_list, TestPerDatabase, get_conn, random_table_suffix
5+
from ..common import str_to_checksum, test_each_database_in_list, DiffTestCase, get_conn, random_table_suffix
6+
67
# from data_diff.sqeleton import databases as db
78
# from data_diff.sqeleton import connect
89

@@ -52,16 +53,16 @@ def test_bad_uris(self):
5253

5354

5455
@test_each_database
55-
class TestSchema(TestPerDatabase):
56+
class TestSchema(unittest.TestCase):
5657
def test_table_list(self):
57-
name = self.table_src_name
58-
db = self.connection
59-
tbl = table(db.parse_table_name(name), schema={'id': int})
58+
name = "tbl_" + random_table_suffix()
59+
db = get_conn(self.db_cls)
60+
tbl = table(db.parse_table_name(name), schema={"id": int})
6061
q = db.dialect.list_tables(db.default_schema, name)
6162
assert not db.query(q)
6263

6364
db.query(tbl.create())
64-
self.assertEqual( db.query(q, List[str] ), [name])
65+
self.assertEqual(db.query(q, List[str]), [name])
6566

66-
db.query( tbl.drop() )
67+
db.query(tbl.drop())
6768
assert not db.query(q)

tests/sqeleton/test_query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ def test_basic(self):
7474
assert c.compile(t) == "SELECT * FROM point WHERE (x = 1) AND (y = 2)"
7575

7676
t = table("person").where(this.name == "Albert")
77-
self.assertEqual( c.compile(t), "SELECT * FROM person WHERE (name = 'Albert')" )
78-
77+
self.assertEqual(c.compile(t), "SELECT * FROM person WHERE (name = 'Albert')")
7978

8079
def test_outerjoin(self):
8180
c = Compiler(MockDatabase())

0 commit comments

Comments
 (0)