Skip to content

Commit 0f70e18

Browse files
committed
tests: add basic sql tests
1 parent ff4338b commit 0f70e18

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

tests/test_diff_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from xdiff.database import connect_to_uri
77
from xdiff.diff_tables import TableDiffer, TableSegment
88

9-
from .common import str_to_checksum, TEST_MYSQL_CONN_STRING
9+
from .common import TEST_MYSQL_CONN_STRING, str_to_checksum
1010

1111

1212
class TestDiffTables(unittest.TestCase):

tests/test_sql.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
3+
from xdiff.database import connect_to_uri
4+
from xdiff.sql import Compiler, Select, TableName
5+
6+
from .common import TEST_MYSQL_CONN_STRING
7+
8+
9+
class TestSQL(unittest.TestCase):
10+
def setUp(self):
11+
self.mysql = connect_to_uri(TEST_MYSQL_CONN_STRING)
12+
self.compiler = Compiler(self.mysql)
13+
14+
def test_compile_string(self):
15+
self.assertEqual("SELECT 1", self.compiler.compile("SELECT 1"))
16+
17+
def test_compile_int(self):
18+
self.assertEqual("1", self.compiler.compile(1))
19+
20+
def test_compile_table_name(self):
21+
self.assertEqual("`marine_mammals.walrus`", self.compiler.compile(
22+
TableName(("marine_mammals", "walrus"))))
23+
24+
def test_compile_select(self):
25+
expected_sql = "SELECT name FROM `marine_mammals.walrus`"
26+
self.assertEqual(expected_sql, self.compiler.compile(
27+
Select(
28+
["name"],
29+
TableName(("marine_mammals", "walrus")),
30+
))
31+
)

0 commit comments

Comments
 (0)