Skip to content

Commit 3e44bdf

Browse files
authored
[TECHDEBT] Increase test coverage (#2782)
## Changes Increase test coverage to avoid failing CI with code changes hat cannot be unit tested ### Linked issues None ### Functionality None ### Tests - [x] added unit tests --------- Co-authored-by: Eric Vergnaud <eric.vergnaud@databricks.com>
1 parent 5ad7e88 commit 3e44bdf

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

src/databricks/labs/ucx/source_code/python/python_analyzer.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ def build_inherited_context(self, child_path: Path) -> InheritedContext:
9090
context.tree.append_globals(globs)
9191
return context
9292

93-
def _build_full_tree(self, inherited_context: Tree | None) -> Tree:
94-
full_tree = Tree.new_module()
95-
if inherited_context is not None:
96-
full_tree = full_tree.append_tree(inherited_context)
97-
full_tree = full_tree.renumber(-1)
98-
tree = Tree.normalize_and_parse(self._python_code)
99-
return full_tree.append_tree(tree)
100-
10193
def _parse_and_extract_nodes(self) -> tuple[Tree, list[NodeBase], Iterable[DependencyProblem]]:
10294
problems: list[DependencyProblem] = []
10395
tree = Tree.normalize_and_parse(self._python_code)

tests/unit/source_code/test_directfs_access.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
def test_crawler_appends_dfsas():
1313
backend = MockBackend()
1414
crawler = DirectFsAccessCrawler.for_paths(backend, "schema")
15+
existing = list(crawler.snapshot())
16+
assert not existing
1517
dfsas = list(
1618
DirectFsAccess(
1719
path=path,

tests/unit/source_code/test_known.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from pathlib import Path
2+
from typing import cast
23
from unittest import mock
34

45
import pytest
56

67
from databricks.labs.ucx.source_code.known import KnownList
8+
from databricks.labs.ucx.source_code.path_lookup import PathLookup
79

810

911
def test_checks_compatibility():
@@ -21,6 +23,10 @@ def test_checks_compatibility():
2123
assert os_path.known
2224
assert not os_path.problems
2325

26+
other = known.module_compatibility(cast(str, None))
27+
assert not other.known
28+
assert not other.problems
29+
2430

2531
def test_checks_library_compatibility():
2632
known = KnownList()
@@ -33,6 +39,10 @@ def test_checks_library_compatibility():
3339
assert s3fs.known
3440
assert len(s3fs.problems) == 1
3541

42+
other = known.distribution_compatibility(cast(str, None))
43+
assert not other.known
44+
assert not other.problems
45+
3646

3747
def test_loads_known_json():
3848
known_json = KnownList._get_known() # pylint: disable=protected-access
@@ -51,3 +61,19 @@ def test_rebuild_trivial():
5161
# No-op: the known.json file is already up-to-date
5262
cwd = Path.cwd()
5363
KnownList.rebuild(cwd)
64+
65+
66+
def test_analyze_dist_info():
67+
68+
class TestKnownList(KnownList):
69+
70+
@classmethod
71+
def analyze_cachetools_dist_info(cls):
72+
path_lookup = PathLookup.from_sys_path(Path.cwd())
73+
for library_root in path_lookup.library_roots:
74+
for dist_info_folder in library_root.glob("*.dist-info"):
75+
if "cachetools" in dist_info_folder.as_posix():
76+
cls._analyze_dist_info(dist_info_folder, {}, library_root)
77+
return
78+
79+
TestKnownList.analyze_cachetools_dist_info()

tests/unit/source_code/test_queries.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from unittest import mock
12
from unittest.mock import create_autospec
23

34
import pytest
@@ -45,3 +46,17 @@ def test_query_liner_refresh_report_writes_query_problems(migration_index, mock_
4546
assert mock_backend.has_rows_written_for("`test`.query_problems")
4647
ws.dashboards.list.assert_called_once()
4748
crawlers.assert_not_called()
49+
50+
51+
def test_lints_queries(migration_index, mock_backend) -> None:
52+
with mock.patch("databricks.labs.ucx.source_code.queries.Redash") as mocked_redash:
53+
query = LegacyQuery(id="123", query="SELECT * from nowhere")
54+
mocked_redash.get_queries_from_dashboard.return_value = [query]
55+
ws = create_autospec(WorkspaceClient)
56+
crawlers = create_autospec(DirectFsAccessCrawler)
57+
linter = QueryLinter(ws, migration_index, crawlers, ["1"])
58+
linter.refresh_report(mock_backend, inventory_database="test")
59+
60+
assert mock_backend.has_rows_written_for("`test`.query_problems")
61+
ws.dashboards.list.assert_not_called()
62+
crawlers.assert_not_called()

0 commit comments

Comments
 (0)