Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Jan 26, 2024
1 parent 30b27ef commit 93a9b2f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/databricks/labs/blueprint/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io
import json
import logging
import os.path
import threading
import types
import typing
Expand Down Expand Up @@ -194,7 +195,8 @@ def upload(self, filename: str, raw: bytes):
try:
attempt()
except NotFound:
self._ws.workspace.mkdirs(self.install_folder())
parent_folder = os.path.dirname(dst)
self._ws.workspace.mkdirs(parent_folder)
attempt()
return dst

Expand All @@ -209,7 +211,8 @@ def upload_dbfs(self, filename: str, raw: bytes) -> str:
try:
attempt()
except NotFound:
self._ws.dbfs.mkdirs(self.install_folder())
parent_folder = os.path.dirname(dst)
self._ws.dbfs.mkdirs(parent_folder)
attempt()
return dst

Expand Down
29 changes: 28 additions & 1 deletion tests/unit/test_installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ def test_save_typed_file():
ws.current_user.me().user_name = "foo"
state = Installation(ws, "blueprint")

state.save(WorkspaceConfig(inventory_database="some_blueprint"))
target = state.save(WorkspaceConfig(
inventory_database="some_blueprint",
include_group_names=["foo", "bar"],
))
assert "/Users/foo/.blueprint/config.yml" == target

ws.workspace.upload.assert_called_with(
"/Users/foo/.blueprint/config.yml",
Expand All @@ -46,6 +50,7 @@ def test_save_typed_file():
"$version": 2,
"num_threads": 10,
"inventory_database": "some_blueprint",
"include_group_names": ["foo", "bar"],
"workspace_start_path": "/",
"log_level": "INFO",
}
Expand All @@ -54,6 +59,7 @@ def test_save_typed_file():
overwrite=True,
)


def test_creates_missing_folders():
ws = create_autospec(WorkspaceClient)
ws.current_user.me().user_name = "foo"
Expand All @@ -65,6 +71,27 @@ def test_creates_missing_folders():
ws.workspace.mkdirs.assert_called_with("/Users/foo/.blueprint")


def test_upload_dbfs():
ws = create_autospec(WorkspaceClient)
ws.current_user.me().user_name = "foo"
state = Installation(ws, "blueprint")

target = state.upload_dbfs("wheels/foo.whl", b"abc")
assert "/Users/foo/.blueprint/wheels/foo.whl" == target


def test_upload_dbfs_mkdirs():
ws = create_autospec(WorkspaceClient)
ws.current_user.me().user_name = "foo"
ws.dbfs.upload.side_effect = [NotFound(...), None]
state = Installation(ws, "blueprint")

target = state.upload_dbfs("wheels/foo.whl", b"abc")
assert "/Users/foo/.blueprint/wheels/foo.whl" == target

ws.dbfs.mkdirs.assert_called_with("/Users/foo/.blueprint/wheels")


def test_save_typed_file_array_csv():
ws = create_autospec(WorkspaceClient)
ws.current_user.me().user_name = "foo"
Expand Down

0 comments on commit 93a9b2f

Please sign in to comment.