Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added content assertion for assert_file_uploaded and assert_file_dbfs_uploaded in MockInstallation #101

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/databricks/labs/blueprint/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,20 +903,27 @@
actual = self._overwrites[filename]
assert expected == actual, f"{filename} content missmatch"

def assert_file_uploaded(self, filename):
self._assert_upload(filename, self._uploads)
def assert_file_uploaded(self, filename, expected: bytes | None = None):
"""Asserts that a file was uploaded with the expected content"""
self._assert_upload(filename, self._uploads, expected)

def assert_file_dbfs_uploaded(self, filename):
self._assert_upload(filename, self._dbfs)
def assert_file_dbfs_uploaded(self, filename, expected: bytes | None = None):
"""Asserts that a file was uploaded to DBFS with the expected content"""
self._assert_upload(filename, self._dbfs, expected)

def assert_removed(self):
assert self._removed

@staticmethod
def _assert_upload(filename: Any, loc: dict[str, bytes]):
def _assert_upload(filename: Any, loc: dict[str, bytes], expected: bytes | None = None):
if isinstance(filename, re.Pattern):
for name in loc.keys():
if filename.match(name):
return
if not filename.match(name):
continue

Check warning on line 922 in src/databricks/labs/blueprint/installation.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/blueprint/installation.py#L922

Added line #L922 was not covered by tests
if expected:
assert loc[name] == expected, f"{filename} content missmatch"

Check warning on line 924 in src/databricks/labs/blueprint/installation.py

View check run for this annotation

Codecov / codecov/patch

src/databricks/labs/blueprint/installation.py#L924

Added line #L924 was not covered by tests
return
raise AssertionError(f'Cannot find {filename.pattern} among {", ".join(loc.keys())}')
assert filename in loc, f"{filename} had no writes"
if expected:
assert loc[filename] == expected, f"{filename} content missmatch"
6 changes: 6 additions & 0 deletions tests/unit/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,9 @@ def test_load_empty_data_class():
)
load = installation.load(ComplexClass, filename="backups/complex-class.json")
assert load == complex_class


def test_assert_file_uploaded():
installation = MockInstallation()
installation.upload("foo", b"bar")
installation.assert_file_uploaded("foo", b"bar")
Loading