Skip to content

Commit b075724

Browse files
authored
use a path instance for MISSING_SOURCE_PATH and add test (#3217)
## Changes improve MISSING_SOURCE_PATH handling ### Linked issues None ### Functionality None ### Tests - [x] ran unit tests Co-authored-by: Eric Vergnaud <eric.vergnaud@databricks.com>
1 parent 32de6bb commit b075724

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/databricks/labs/ucx/source_code/graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,22 +477,22 @@ def __repr__(self):
477477
return f"<DependencyResolver {self._notebook_resolver} {self._import_resolver} {self._file_resolver}, {self._path_lookup}>"
478478

479479

480-
MISSING_SOURCE_PATH = "<MISSING_SOURCE_PATH>"
480+
_MISSING_SOURCE_PATH = Path("<MISSING_SOURCE_PATH>")
481481

482482

483483
@dataclass
484484
class DependencyProblem:
485485
code: str
486486
message: str
487-
source_path: Path = Path(MISSING_SOURCE_PATH)
487+
source_path: Path = _MISSING_SOURCE_PATH
488488
# Lines and columns are both 0-based: the first line is line 0.
489489
start_line: int = -1
490490
start_col: int = -1
491491
end_line: int = -1
492492
end_col: int = -1
493493

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

497497
def as_advisory(self) -> 'Advisory':
498498
return Advisory(

tests/integration/source_code/test_graph.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import dataclasses
12
from pathlib import Path
23

34

45
from databricks.labs.ucx.source_code.base import CurrentSessionState
5-
from databricks.labs.ucx.source_code.graph import DependencyResolver, DependencyGraph
6+
from databricks.labs.ucx.source_code.graph import DependencyResolver, DependencyGraph, DependencyProblem
67
from databricks.labs.ucx.source_code.known import KnownList, Compatibility, UNKNOWN
78
from databricks.labs.ucx.source_code.linters.files import FileLoader, ImportFileResolver
89
from databricks.labs.ucx.source_code.notebooks.loaders import NotebookLoader, NotebookResolver
@@ -57,3 +58,10 @@ def test_graph_imports_dynamic_import():
5758
container = maybe.dependency.load(path_lookup)
5859
problems = container.build_dependency_graph(graph)
5960
assert not problems
61+
62+
63+
def test_is_path_missing():
64+
problem = DependencyProblem("some-code", "some-message")
65+
assert problem.is_path_missing()
66+
problem = dataclasses.replace(problem, source_path=Path("stuff"))
67+
assert not problem.is_path_missing()

0 commit comments

Comments
 (0)