forked from datafold/data-diff
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_cli.py
More file actions
76 lines (64 loc) · 2.12 KB
/
test_cli.py
File metadata and controls
76 lines (64 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import logging
import subprocess
import sys
from datetime import datetime, timedelta
from data_diff.queries.api import commit, current_timestamp
from tests.common import CONN_STRINGS, DiffTestCase
from tests.test_diff_tables import apply_each_database
def run_datadiff_cli(*args):
try:
p = subprocess.Popen(
[sys.executable, "-m", "data_diff"] + list(args),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = p.communicate()
except subprocess.CalledProcessError as e:
logging.error(e.stderr)
raise
if p.returncode != 0:
raise Exception(stderr or stdout)
return stdout.splitlines()
@apply_each_database
class TestCLI(DiffTestCase):
src_schema = {"id": int, "datetime": datetime, "text_comment": str}
def setUp(self) -> None:
super().setUp()
now = self.connection.query(current_timestamp(), datetime)
rows = [
(now, "now"),
(now - timedelta(seconds=10), "a"),
(now - timedelta(seconds=7), "b"),
(now - timedelta(seconds=6), "c"),
]
self.connection.query(
[
self.src_table.insert_rows((i, ts, s) for i, (ts, s) in enumerate(rows)),
self.dst_table.create(self.src_table),
self.src_table.insert_row(len(rows), now - timedelta(seconds=3), "3 seconds ago"),
commit,
]
)
def test_basic(self):
conn_str = CONN_STRINGS[self.db_cls]
diff = run_datadiff_cli(conn_str, self.table_src_name, conn_str, self.table_dst_name)
assert len(diff) == 1
def test_options(self):
conn_str = CONN_STRINGS[self.db_cls]
diff = run_datadiff_cli(
conn_str,
self.table_src_name,
conn_str,
self.table_dst_name,
"--bisection-factor",
"16",
"--bisection-threshold",
"10000",
"--limit",
"5",
"-t",
"datetime",
"--max-age",
"1h",
)
assert len(diff) == 1, diff