|
| 1 | +import io |
1 | 2 | import json |
2 | 3 | from collections.abc import Callable, Generator |
3 | 4 | import functools |
|
9 | 10 | from functools import cached_property |
10 | 11 | import shutil |
11 | 12 | import subprocess |
| 13 | +from pathlib import Path |
| 14 | + |
12 | 15 | import pytest # pylint: disable=wrong-import-order |
| 16 | +import yaml |
13 | 17 | from databricks.labs.blueprint.commands import CommandExecutor |
14 | 18 | from databricks.labs.blueprint.entrypoint import is_in_debug |
15 | 19 | from databricks.labs.blueprint.installation import Installation, MockInstallation |
16 | 20 | from databricks.labs.blueprint.parallel import Threads |
| 21 | +from databricks.labs.blueprint.paths import WorkspacePath |
17 | 22 | from databricks.labs.blueprint.tui import MockPrompts |
18 | 23 | from databricks.labs.blueprint.wheels import ProductInfo |
19 | 24 | from databricks.labs.lsql.backends import SqlBackend |
@@ -1175,3 +1180,25 @@ def _run(command: str) -> str: |
1175 | 1180 | except ValueError as err: |
1176 | 1181 | logger.debug(f"pytest_ignore_collect: error: {err}") |
1177 | 1182 | return False |
| 1183 | + |
| 1184 | + |
| 1185 | +@pytest.fixture |
| 1186 | +def populate_for_linting(ws, make_random, make_job, make_notebook, make_query, make_dashboard, watchdog_purge_suffix): |
| 1187 | + def populate_workspace(installation): |
| 1188 | + # keep linting scope to minimum to avoid test timeouts |
| 1189 | + path = Path(installation.install_folder()) / f"dummy-{make_random(4)}-{watchdog_purge_suffix}" |
| 1190 | + notebook_path = make_notebook(path=path, content=io.BytesIO(b"spark.read.parquet('dbfs://mnt/foo/bar')")) |
| 1191 | + job = make_job(notebook_path=notebook_path) |
| 1192 | + query = make_query(sql_query='SELECT * from parquet.`dbfs://mnt/foo/bar`') |
| 1193 | + dashboard = make_dashboard(query=query) |
| 1194 | + # can't use installation.load(WorkspaceConfig)/installation.save() because they populate empty credentials |
| 1195 | + config_path = WorkspacePath(ws, installation.install_folder()) / "config.yml" |
| 1196 | + text = config_path.read_text() |
| 1197 | + config = yaml.safe_load(text) |
| 1198 | + config["include_job_ids"] = [job.job_id] |
| 1199 | + config["include_dashboard_ids"] = [dashboard.id] |
| 1200 | + text = yaml.dump(config) |
| 1201 | + config_path.unlink() |
| 1202 | + config_path.write_text(text) |
| 1203 | + |
| 1204 | + return populate_workspace |
0 commit comments