You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[FEATURE] Extend make_job to run SparkPythonTask (#60)
## Changes
Extend `make_job` to run `SparkPythonTask` by:
- Add `make_workspace_file` fixture to create the Python file to run.
- Support SQL notebooks and files
- Add `task_type` to `make_job` to signal what type of task to run
(notebook or python file)
- Add `instance_pool_id` to `make_job` for speeding up a job in
integration tests by reusing an instance pool
- Add unit tests for changed fixtures
- Run jobs in integration tests
### Tests
- [x] manually tested
- [x] added unit tests
- [x] added integration tests
@@ -410,22 +410,26 @@ Create a Databricks job and clean it up after the test. Returns a function to cr
410
410
a [`Job`](https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/jobs.html#databricks.sdk.service.jobs.Job) instance.
411
411
412
412
Keyword Arguments:
413
-
*`notebook_path` (str, optional): The path to the notebook. If not provided, a random notebook will be created.
414
413
*`name` (str, optional): The name of the job. If not provided, a random name will be generated.
415
-
*`spark_conf` (dict, optional): The Spark configuration of the job.
414
+
*`path` (str, optional): The path to the notebook or file used in the job. If not provided, a random notebook or file will be created
415
+
*[DEPRECATED: Use `path` instead]`notebook_path` (str, optional): The path to the notebook. If not provided, a random notebook will be created.
416
+
*`content` (str | bytes, optional): The content of the notebook or file used in the job. If not provided, default content of `make_notebook` will be used.
417
+
*`task_type` (type[NotebookTask] | type[SparkPythonTask], optional): The type of task. If not provides, `type[NotebookTask]` will be used.
418
+
*`instance_pool_id` (str, optional): The instance pool id to add to the job cluster. If not provided, no instance pool will be used.
419
+
*`spark_conf` (dict, optional): The Spark configuration of the job. If not provided, Spark configuration is not explicitly set.
416
420
*`libraries` (list, optional): The list of libraries to install on the job.
417
-
*other arguments are passed to `WorkspaceClient.jobs.create` method.
418
-
419
-
If no task argument is provided, a single task with a notebook task will be created, along with a disposable notebook.
420
-
Latest Spark version and a single worker clusters will be used to run this ephemeral job.
421
+
*`tags` (list[str], optional): A list of job tags. If not provided, no additional tags will be set on the job.
422
+
*`tasks` (list[Task], optional): A list of job tags. If not provided, a single task with a notebook task will be
423
+
created, along with a disposable notebook. Latest Spark version and a single worker clusters will be used to run
424
+
this ephemeral job.
421
425
422
426
Usage:
423
427
```python
424
428
deftest_job(make_job):
425
429
logger.info(f"created {make_job()}")
426
430
```
427
431
428
-
See also [`ws`](#ws-fixture), [`make_random`](#make_random-fixture), [`make_notebook`](#make_notebook-fixture), [`watchdog_remove_after`](#watchdog_remove_after-fixture).
432
+
See also [`ws`](#ws-fixture), [`make_random`](#make_random-fixture), [`make_notebook`](#make_notebook-fixture), [`make_workspace_file`](#make_workspace_file-fixture), [`watchdog_remove_after`](#watchdog_remove_after-fixture).
429
433
430
434
431
435
[[back to top](#python-testing-for-databricks)]
@@ -621,8 +625,9 @@ The function returns [`os.PathLike` object](https://github.com/databrickslabs/bl
621
625
622
626
Keyword arguments:
623
627
*`path` (str, optional): The path of the notebook. Defaults to `dummy-*` notebook in current user's home folder.
624
-
*`content` (typing.BinaryIO, optional): The content of the notebook. Defaults to `print(1)`.
628
+
*`content` (str | bytes | io.BinaryIO, optional): The content of the notebook. Defaults to `print(1)` for Python and `SELECT 1` for SQL.
625
629
*`language` ([`Language`](https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/workspace.html#databricks.sdk.service.workspace.Language), optional): The language of the notebook. Defaults to `Language.PYTHON`.
630
+
*`encoding` (`str`, optional): The file encoding. Defaults to `sys.getdefaultencoding()`.
626
631
*`format` ([`ImportFormat`](https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/workspace.html#databricks.sdk.service.workspace.ImportFormat), optional): The format of the notebook. Defaults to `ImportFormat.SOURCE`.
627
632
*`overwrite` (bool, optional): Whether to overwrite the notebook if it already exists. Defaults to `False`.
628
633
@@ -644,6 +649,32 @@ _No description yet._
644
649
See also [`ws`](#ws-fixture).
645
650
646
651
652
+
[[back to top](#python-testing-for-databricks)]
653
+
654
+
### `make_workspace_file` fixture
655
+
Returns a function to create Databricks workspace file and clean up after the test.
656
+
The function returns [`os.PathLike` object](https://github.com/databrickslabs/blueprint?tab=readme-ov-file#python-native-pathlibpath-like-interfaces).
657
+
658
+
Keyword arguments:
659
+
*`path` (str, optional): The path of the file. Defaults to `dummy-*` notebook in current user's home folder.
660
+
*`content` (str | bytes, optional): The content of the file. Defaults to `print(1)` for Python and `SELECT 1` for SQL.
661
+
*`language` ([`Language`](https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/workspace.html#databricks.sdk.service.workspace.Language), optional): The language of the notebook. Defaults to `Language.PYTHON`.
662
+
*`encoding` (`str`, optional): The file encoding. Defaults to `sys.getdefaultencoding()`.
663
+
664
+
This example creates a notebook and verifies that the workspace path is an existing file with contents `print(1)`:
665
+
```python
666
+
deftest_create_file(make_workspace_file):
667
+
workspace_file = make_workspace_file()
668
+
assert workspace_file.is_file()
669
+
assert"print(1)"in workspace_file.read_text()
670
+
```
671
+
672
+
TODO:
673
+
Merge functionality with `make_notebook` if `WorkspacePath` supports creating notebooks.
674
+
675
+
See also [`make_job`](#make_job-fixture), [`ws`](#ws-fixture), [`make_random`](#make_random-fixture), [`watchdog_purge_suffix`](#watchdog_purge_suffix-fixture).
676
+
677
+
647
678
[[back to top](#python-testing-for-databricks)]
648
679
649
680
### `make_directory` fixture
@@ -1114,7 +1145,7 @@ See also [`make_catalog`](#make_catalog-fixture), [`make_cluster`](#make_cluster
1114
1145
### `watchdog_purge_suffix` fixture
1115
1146
HEX-encoded purge time suffix for test objects.
1116
1147
1117
-
See also [`make_acc_group`](#make_acc_group-fixture), [`make_cluster_policy`](#make_cluster_policy-fixture), [`make_directory`](#make_directory-fixture), [`make_experiment`](#make_experiment-fixture), [`make_group`](#make_group-fixture), [`make_notebook`](#make_notebook-fixture), [`make_pipeline`](#make_pipeline-fixture), [`make_repo`](#make_repo-fixture), [`make_user`](#make_user-fixture), [`watchdog_remove_after`](#watchdog_remove_after-fixture).
1148
+
See also [`make_acc_group`](#make_acc_group-fixture), [`make_cluster_policy`](#make_cluster_policy-fixture), [`make_directory`](#make_directory-fixture), [`make_experiment`](#make_experiment-fixture), [`make_group`](#make_group-fixture), [`make_notebook`](#make_notebook-fixture), [`make_pipeline`](#make_pipeline-fixture), [`make_repo`](#make_repo-fixture), [`make_user`](#make_user-fixture), [`make_workspace_file`](#make_workspace_file-fixture), [`watchdog_remove_after`](#watchdog_remove_after-fixture).
0 commit comments