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

Commit b2e951b

Browse files
authored
Merge pull request #177 from datafold/issue175
Fix for CLI + tests for CLI (issue #175)
2 parents e322806 + 470d5c3 commit b2e951b

File tree

2 files changed

+85
-4
lines changed

2 files changed

+85
-4
lines changed

data_diff/__main__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,8 @@ def _main(
133133
return
134134

135135
key_column = key_column or "id"
136-
if bisection_factor is None:
137-
bisection_factor = DEFAULT_BISECTION_FACTOR
138-
if bisection_threshold is None:
139-
bisection_threshold = DEFAULT_BISECTION_THRESHOLD
136+
bisection_factor = DEFAULT_BISECTION_FACTOR if bisection_factor is None else int(bisection_factor)
137+
bisection_threshold = DEFAULT_BISECTION_THRESHOLD if bisection_threshold is None else int(bisection_threshold)
140138

141139
threaded = True
142140
if threads is None:

tests/test_cli.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import logging
2+
import unittest
3+
import preql
4+
import arrow
5+
import subprocess
6+
import sys
7+
8+
from data_diff import diff_tables, connect_to_table
9+
10+
from .common import TEST_MYSQL_CONN_STRING
11+
12+
13+
def run_datadiff_cli(*args):
14+
try:
15+
stdout = subprocess.check_output([sys.executable, "-m", "data_diff"] + list(args), stderr=subprocess.PIPE)
16+
except subprocess.CalledProcessError as e:
17+
logging.error(e.stderr)
18+
raise
19+
return stdout.splitlines()
20+
21+
22+
class TestCLI(unittest.TestCase):
23+
def setUp(self) -> None:
24+
self.preql = preql.Preql(TEST_MYSQL_CONN_STRING)
25+
self.preql(
26+
r"""
27+
table test_cli {
28+
datetime: datetime
29+
comment: string
30+
}
31+
commit()
32+
33+
func add(date, comment) {
34+
new test_cli(date, comment)
35+
}
36+
"""
37+
)
38+
self.now = now = arrow.get(self.preql.now())
39+
self.preql.add(now, "now")
40+
self.preql.add(now, self.now.shift(seconds=-10))
41+
self.preql.add(now, self.now.shift(seconds=-7))
42+
self.preql.add(now, self.now.shift(seconds=-6))
43+
44+
self.preql(
45+
r"""
46+
const table test_cli_2 = test_cli
47+
commit()
48+
"""
49+
)
50+
51+
self.preql.add(self.now.shift(seconds=-3), "3 seconds ago")
52+
self.preql.commit()
53+
54+
def tearDown(self) -> None:
55+
self.preql.run_statement("drop table if exists test_cli")
56+
self.preql.run_statement("drop table if exists test_cli_2")
57+
self.preql.commit()
58+
self.preql.close()
59+
60+
return super().tearDown()
61+
62+
def test_basic(self):
63+
diff = run_datadiff_cli(TEST_MYSQL_CONN_STRING, "test_cli", TEST_MYSQL_CONN_STRING, "test_cli_2")
64+
assert len(diff) == 1
65+
66+
def test_options(self):
67+
diff = run_datadiff_cli(
68+
TEST_MYSQL_CONN_STRING,
69+
"test_cli",
70+
TEST_MYSQL_CONN_STRING,
71+
"test_cli_2",
72+
"--bisection-factor",
73+
"16",
74+
"--bisection-threshold",
75+
"10000",
76+
"--limit",
77+
"5",
78+
"-t",
79+
"datetime",
80+
"--max-age",
81+
"1h",
82+
)
83+
assert len(diff) == 1

0 commit comments

Comments
 (0)