Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions data_diff/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,8 @@ def _main(
return

key_column = key_column or "id"
if bisection_factor is None:
bisection_factor = DEFAULT_BISECTION_FACTOR
if bisection_threshold is None:
bisection_threshold = DEFAULT_BISECTION_THRESHOLD
bisection_factor = DEFAULT_BISECTION_FACTOR if bisection_factor is None else int(bisection_factor)
bisection_threshold = DEFAULT_BISECTION_THRESHOLD if bisection_threshold is None else int(bisection_threshold)

threaded = True
if threads is None:
Expand Down
83 changes: 83 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import logging
import unittest
import preql
import arrow
import subprocess
import sys

from data_diff import diff_tables, connect_to_table

from .common import TEST_MYSQL_CONN_STRING


def run_datadiff_cli(*args):
try:
stdout = subprocess.check_output([sys.executable, "-m", "data_diff"] + list(args), stderr=subprocess.PIPE)
except subprocess.CalledProcessError as e:
logging.error(e.stderr)
raise
return stdout.splitlines()


class TestCLI(unittest.TestCase):
def setUp(self) -> None:
self.preql = preql.Preql(TEST_MYSQL_CONN_STRING)
self.preql(
r"""
table test_cli {
datetime: datetime
comment: string
}
commit()

func add(date, comment) {
new test_cli(date, comment)
}
"""
)
self.now = now = arrow.get(self.preql.now())
self.preql.add(now, "now")
self.preql.add(now, self.now.shift(seconds=-10))
self.preql.add(now, self.now.shift(seconds=-7))
self.preql.add(now, self.now.shift(seconds=-6))

self.preql(
r"""
const table test_cli_2 = test_cli
commit()
"""
)

self.preql.add(self.now.shift(seconds=-3), "3 seconds ago")
self.preql.commit()

def tearDown(self) -> None:
self.preql.run_statement("drop table if exists test_cli")
self.preql.run_statement("drop table if exists test_cli_2")
self.preql.commit()
self.preql.close()

return super().tearDown()

def test_basic(self):
diff = run_datadiff_cli(TEST_MYSQL_CONN_STRING, "test_cli", TEST_MYSQL_CONN_STRING, "test_cli_2")
assert len(diff) == 1

def test_options(self):
diff = run_datadiff_cli(
TEST_MYSQL_CONN_STRING,
"test_cli",
TEST_MYSQL_CONN_STRING,
"test_cli_2",
"--bisection-factor",
"16",
"--bisection-threshold",
"10000",
"--limit",
"5",
"-t",
"datetime",
"--max-age",
"1h",
)
assert len(diff) == 1