Skip to content

Commit e258402

Browse files
committed
Added validation to (min/max)_(update/key)
1 parent 78d28db commit e258402

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

data_diff/diff_tables.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ def __post_init__(self):
6565
if not self.update_column and (self.min_update or self.max_update):
6666
raise ValueError("Error: min_update/max_update feature requires to specify 'update_column'")
6767

68+
if self.min_key is not None and self.max_key is not None and self.min_key >= self.max_key:
69+
raise ValueError("Error: min_key expected to be smaller than max_key!")
70+
71+
if self.min_update is not None and self.max_update is not None and self.min_update >= self.max_update:
72+
raise ValueError("Error: min_update expected to be smaller than max_update!")
73+
6874
def _make_key_range(self):
6975
if self.min_key is not None:
7076
yield Compare("<=", str(self.min_key), self.key_column)

tests/test_diff_tables.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,16 @@ def test_diff_sorted_by_key(self):
210210
("-", (4, datetime.datetime(2022, 1, 1, 0, 0))),
211211
]
212212
self.assertEqual(expected, diff)
213+
214+
class TestTableSegment(TestWithConnection):
215+
def setUp(self) -> None:
216+
self.table = TableSegment(self.connection, ("ratings_test",), "id", "timestamp")
217+
self.table2 = TableSegment(self.connection, ("ratings_test2",), "id", "timestamp")
218+
return super().setUp()
219+
220+
def test_table_segment(self):
221+
early = datetime.datetime(2021, 1, 1, 0, 0)
222+
late = datetime.datetime(2022, 1, 1, 0, 0)
223+
self.assertRaises(ValueError, self.table.replace, min_update=late, max_update=early)
224+
225+
self.assertRaises(ValueError, self.table.replace, min_key=10, max_key=0)

0 commit comments

Comments
 (0)