|
| 1 | +from typing import get_type_hints |
1 | 2 | from unittest.mock import create_autospec |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from databricks.sdk import WorkspaceClient |
5 | 6 | from databricks.sdk.service.catalog import CatalogInfo, MetastoreAssignment |
6 | 7 | from databricks.sdk.service.jobs import BaseRun, RunResultState, RunState |
7 | 8 |
|
8 | | -from databricks.labs.ucx.assessment.clusters import ClustersCrawler, PoliciesCrawler |
9 | | -from databricks.labs.ucx.assessment.jobs import JobsCrawler |
10 | | -from databricks.labs.ucx.assessment.pipelines import PipelinesCrawler |
11 | 9 | from databricks.labs.ucx.progress.workflows import MigrationProgress |
12 | 10 | from databricks.labs.ucx.contexts.workflow_task import RuntimeContext |
13 | | -from databricks.labs.ucx.hive_metastore import TablesCrawler |
14 | | -from databricks.labs.ucx.hive_metastore.grants import GrantsCrawler |
15 | | -from databricks.labs.ucx.hive_metastore.table_migration_status import TableMigrationStatusRefresher |
16 | | -from databricks.labs.ucx.hive_metastore.udfs import UdfsCrawler |
17 | 11 |
|
18 | 12 |
|
19 | 13 | @pytest.mark.parametrize( |
20 | | - "task, crawler, crawler_class", |
21 | | - [ |
22 | | - (MigrationProgress.crawl_tables, RuntimeContext.tables_crawler, TablesCrawler), |
23 | | - (MigrationProgress.crawl_udfs, RuntimeContext.udfs_crawler, UdfsCrawler), |
24 | | - (MigrationProgress.crawl_grants, RuntimeContext.grants_crawler, GrantsCrawler), |
25 | | - (MigrationProgress.assess_jobs, RuntimeContext.jobs_crawler, JobsCrawler), |
26 | | - (MigrationProgress.assess_clusters, RuntimeContext.clusters_crawler, ClustersCrawler), |
27 | | - (MigrationProgress.assess_pipelines, RuntimeContext.pipelines_crawler, PipelinesCrawler), |
28 | | - (MigrationProgress.crawl_cluster_policies, RuntimeContext.policies_crawler, PoliciesCrawler), |
29 | | - ( |
30 | | - MigrationProgress.refresh_table_migration_status, |
31 | | - RuntimeContext.migration_status_refresher, |
32 | | - TableMigrationStatusRefresher, |
33 | | - ), |
34 | | - ], |
| 14 | + "task, crawler", |
| 15 | + ( |
| 16 | + (MigrationProgress.crawl_tables, RuntimeContext.tables_crawler), |
| 17 | + (MigrationProgress.crawl_udfs, RuntimeContext.udfs_crawler), |
| 18 | + (MigrationProgress.crawl_grants, RuntimeContext.grants_crawler), |
| 19 | + (MigrationProgress.assess_jobs, RuntimeContext.jobs_crawler), |
| 20 | + (MigrationProgress.assess_clusters, RuntimeContext.clusters_crawler), |
| 21 | + (MigrationProgress.assess_pipelines, RuntimeContext.pipelines_crawler), |
| 22 | + (MigrationProgress.crawl_cluster_policies, RuntimeContext.policies_crawler), |
| 23 | + (MigrationProgress.refresh_table_migration_status, RuntimeContext.migration_status_refresher), |
| 24 | + ), |
35 | 25 | ) |
36 | | -def test_migration_progress_runtime_refresh(run_workflow, task, crawler, crawler_class) -> None: |
| 26 | +def test_migration_progress_runtime_refresh(run_workflow, task, crawler) -> None: |
| 27 | + crawler_class = get_type_hints(crawler.func)["return"] |
37 | 28 | mock_crawler = create_autospec(crawler_class) |
38 | 29 | crawler_name = crawler.attrname |
39 | 30 | run_workflow(task, **{crawler_name: mock_crawler}) |
40 | 31 | mock_crawler.snapshot.assert_called_once_with(force_refresh=True) |
41 | 32 |
|
42 | 33 |
|
| 34 | +@pytest.mark.parametrize( |
| 35 | + "task, linter", |
| 36 | + ( |
| 37 | + (MigrationProgress.assess_dashboards, RuntimeContext.query_linter), |
| 38 | + (MigrationProgress.assess_workflows, RuntimeContext.workflow_linter), |
| 39 | + ), |
| 40 | +) |
| 41 | +def test_linter_runtime_refresh(run_workflow, task, linter) -> None: |
| 42 | + linter_class = get_type_hints(linter.func)["return"] |
| 43 | + mock_linter = create_autospec(linter_class) |
| 44 | + linter_name = linter.attrname |
| 45 | + ctx = run_workflow(task, **{linter_name: mock_linter}) |
| 46 | + mock_linter.refresh_report.assert_called_once_with(ctx.sql_backend, ctx.inventory_database) |
| 47 | + |
| 48 | + |
43 | 49 | def test_migration_progress_with_valid_prerequisites(run_workflow) -> None: |
44 | 50 | ws = create_autospec(WorkspaceClient) |
45 | 51 | ws.metastores.current.return_value = MetastoreAssignment(metastore_id="test", workspace_id=123456789) |
|
0 commit comments