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

use a path instance for MISSING_SOURCE_PATH and add test #3217

Merged
merged 1 commit into from
Nov 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
6 changes: 3 additions & 3 deletions src/databricks/labs/ucx/source_code/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,22 +477,22 @@ def __repr__(self):
return f"<DependencyResolver {self._notebook_resolver} {self._import_resolver} {self._file_resolver}, {self._path_lookup}>"


MISSING_SOURCE_PATH = "<MISSING_SOURCE_PATH>"
_MISSING_SOURCE_PATH = Path("<MISSING_SOURCE_PATH>")


@dataclass
class DependencyProblem:
code: str
message: str
source_path: Path = Path(MISSING_SOURCE_PATH)
source_path: Path = _MISSING_SOURCE_PATH
# Lines and columns are both 0-based: the first line is line 0.
start_line: int = -1
start_col: int = -1
end_line: int = -1
end_col: int = -1

def is_path_missing(self) -> bool:
return self.source_path == Path(MISSING_SOURCE_PATH)
return self.source_path == _MISSING_SOURCE_PATH

def as_advisory(self) -> 'Advisory':
return Advisory(
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/source_code/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dataclasses
from pathlib import Path


from databricks.labs.ucx.source_code.base import CurrentSessionState
from databricks.labs.ucx.source_code.graph import DependencyResolver, DependencyGraph
from databricks.labs.ucx.source_code.graph import DependencyResolver, DependencyGraph, DependencyProblem
from databricks.labs.ucx.source_code.known import KnownList, Compatibility, UNKNOWN
from databricks.labs.ucx.source_code.linters.files import FileLoader, ImportFileResolver
from databricks.labs.ucx.source_code.notebooks.loaders import NotebookLoader, NotebookResolver
Expand Down Expand Up @@ -57,3 +58,10 @@ def test_graph_imports_dynamic_import():
container = maybe.dependency.load(path_lookup)
problems = container.build_dependency_graph(graph)
assert not problems


def test_is_path_missing():
problem = DependencyProblem("some-code", "some-message")
assert problem.is_path_missing()
problem = dataclasses.replace(problem, source_path=Path("stuff"))
assert not problem.is_path_missing()