Skip to content

Commit

Permalink
Extend the no rows written test and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
JCZuurmond committed Sep 19, 2024
1 parent 2cc3e38 commit c362ffe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/databricks/labs/lsql/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def has_rows_written_for(self, full_name: str) -> bool:
This method allows to differentiate between "never written to the table" (returns False) and "zero rows written
to the table" (return True).
Otherwise, the check is the same as: `len(mock_backend.rows_written_for(full_name, mode)) > 0`
Otherwise, the check is the same as: `assert (not) mock_backend.rows_written_for(full_name, mode)`
"""
for stub_full_name, _, _ in self._save_table:
if stub_full_name == full_name:
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,13 @@ def test_mock_backend_overwrite():
]


def test_mock_backend_has_no_rows_written() -> None:
@pytest.mark.parametrize("mode", ["append", "overwrite"])
def test_mock_backend_has_no_rows_written(mode) -> None:
mock_backend = MockBackend()
# There are no rows written
assert not mock_backend.has_rows_written_for("a.b.d")
# and the results contains no rows
assert not mock_backend.rows_written_for("a.b.c", mode)


@pytest.mark.parametrize("mode", ["append", "overwrite"])
Expand All @@ -462,7 +466,7 @@ def test_mock_backend_has_zero_rows_written(mode) -> None:
mock_backend.save_table("a.b.c", [], Foo, mode)
# There are rows written
assert mock_backend.has_rows_written_for("a.b.c")
# But the results contains no rows
# while the results contains no rows
assert not mock_backend.rows_written_for("a.b.c", mode)


Expand Down

0 comments on commit c362ffe

Please sign in to comment.