forked from databrickslabs/ucx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'databrickslabs:main' into main
- Loading branch information
Showing
17 changed files
with
377 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from databricks.labs.ucx.contexts.application import GlobalContext | ||
|
||
|
||
@pytest.mark.parametrize("attribute", ["dependency_resolver", "pip_resolver", "site_packages", "site_packages_path"]) | ||
def test_global_context_attributes_not_none(attribute: str): | ||
"""Attributes should be not None""" | ||
# Goal is to improve test coverage | ||
ctx = GlobalContext() | ||
assert hasattr(ctx, attribute) | ||
assert getattr(ctx, attribute) is not None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from pathlib import Path | ||
from unittest.mock import create_autospec | ||
|
||
from databricks.labs.ucx.source_code.graph import Dependency, DependencyGraph, DependencyResolver | ||
from databricks.labs.ucx.source_code.files import FileLoader | ||
from databricks.labs.ucx.source_code.notebooks.cells import CellLanguage, PipCell | ||
from databricks.labs.ucx.source_code.notebooks.loaders import ( | ||
NotebookResolver, | ||
NotebookLoader, | ||
) | ||
from databricks.labs.ucx.source_code.site_packages import PipResolver | ||
|
||
|
||
def test_pip_cell_language_is_pip(): | ||
assert PipCell("code").language == CellLanguage.PIP | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_invokes_register_library(): | ||
graph = create_autospec(DependencyGraph) | ||
|
||
code = "%pip install databricks" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 0 | ||
graph.register_library.assert_called_once_with("databricks") | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_pip_registers_missing_library(): | ||
graph = create_autospec(DependencyGraph) | ||
|
||
code = "%pip install" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 1 | ||
assert problems[0].code == "library-install-failed" | ||
assert problems[0].message == "Missing arguments in '%pip install'" | ||
graph.register_library.assert_not_called() | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_reports_incorrect_syntax(): | ||
graph = create_autospec(DependencyGraph) | ||
|
||
code = "%pip installl pytest" # typo on purpose | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 1 | ||
assert problems[0].code == "library-install-failed" | ||
assert problems[0].message == "Unsupported %pip command: installl" | ||
graph.register_library.assert_not_called() | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_reports_unknown_library(mock_path_lookup): | ||
dependency = Dependency(FileLoader(), Path("test")) | ||
notebook_loader = NotebookLoader() | ||
notebook_resolver = NotebookResolver(notebook_loader) | ||
dependency_resolver = DependencyResolver([PipResolver()], notebook_resolver, [], mock_path_lookup) | ||
graph = DependencyGraph(dependency, None, dependency_resolver, mock_path_lookup) | ||
|
||
code = "%pip install unknown-library-name" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 1 | ||
assert problems[0].code == "library-install-failed" | ||
assert problems[0].message.startswith("Failed to install unknown-library-name") | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_resolves_installed_library(mock_path_lookup): | ||
dependency = Dependency(FileLoader(), Path("test")) | ||
notebook_loader = NotebookLoader() | ||
notebook_resolver = NotebookResolver(notebook_loader) | ||
dependency_resolver = DependencyResolver([PipResolver()], notebook_resolver, [], mock_path_lookup) | ||
graph = DependencyGraph(dependency, None, dependency_resolver, mock_path_lookup) | ||
|
||
code = "%pip install pytest" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 0 | ||
assert graph.path_lookup.resolve(Path("pytest")).exists() |
Oops, something went wrong.