Skip to content

Commit 75b5700

Browse files
black format
1 parent 98896ea commit 75b5700

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

databricks/sdk/mixins/files.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from datetime import timedelta
1717
from io import BytesIO
1818
from types import TracebackType
19-
from typing import (TYPE_CHECKING, AnyStr, BinaryIO, Callable, Generator,
20-
Iterable, Optional, Type, Union)
19+
from typing import TYPE_CHECKING, AnyStr, BinaryIO, Callable, Generator, Iterable, Optional, Type, Union
2120
from urllib import parse
2221

2322
import requests
@@ -576,6 +575,7 @@ def delete(self, *, recursive=False):
576575
def __repr__(self) -> str:
577576
return f"<_DbfsPath {self._path}>"
578577

578+
579579
class _RetryableException(Exception):
580580
"""Base class for retryable exceptions in DBFS operations."""
581581

@@ -596,6 +596,7 @@ def make_error(response: requests.Response) -> "_RetryableException":
596596
http_status_code=response.status_code,
597597
)
598598

599+
599600
class DbfsExt(files.DbfsAPI):
600601
__doc__ = files.DbfsAPI.__doc__
601602

tests/test_files.py

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020

2121
from databricks.sdk import WorkspaceClient
2222
from databricks.sdk.core import Config
23-
from databricks.sdk.errors.platform import (AlreadyExists, BadRequest,
24-
InternalError, PermissionDenied,
25-
TooManyRequests)
23+
from databricks.sdk.errors.platform import AlreadyExists, BadRequest, InternalError, PermissionDenied, TooManyRequests
2624

2725
logger = logging.getLogger(__name__)
2826

@@ -57,7 +55,7 @@ def __init__(
5755
self.expected_requested_offsets = expected_requested_offsets
5856

5957
@staticmethod
60-
def to_string(test_case: 'DownloadTestCase') -> str:
58+
def to_string(test_case: "DownloadTestCase") -> str:
6159
return test_case.name
6260

6361
def run(self, config: Config) -> None:
@@ -115,7 +113,7 @@ def request(
115113
verify=None,
116114
cert=None,
117115
json=None,
118-
) -> 'MockResponse':
116+
) -> "MockResponse":
119117
assert method == "GET"
120118
assert stream == True
121119

@@ -167,7 +165,7 @@ def __init__(self, session: MockSession, offset: int, request: MockRequest):
167165
self.ok = True
168166
self.url = request.url
169167

170-
def iter_content(self, chunk_size: int, decode_unicode: bool) -> 'MockIterator':
168+
def iter_content(self, chunk_size: int, decode_unicode: bool) -> "MockIterator":
171169
assert decode_unicode == False
172170
return MockIterator(self, chunk_size)
173171

@@ -415,7 +413,7 @@ def __init__(self, length: int, checksum: str):
415413
self.checksum = checksum
416414

417415
@classmethod
418-
def from_bytes(cls, data: bytes) -> 'FileContent':
416+
def from_bytes(cls, data: bytes) -> "FileContent":
419417
sha256 = hashlib.sha256()
420418
sha256.update(data)
421419
return FileContent(len(data), sha256.hexdigest())
@@ -666,14 +664,12 @@ def __init__(
666664
def customize_config(self, config: Config) -> None:
667665
pass
668666

669-
def create_multipart_upload_server_state(self)\
670-
-> Union[MultipartUploadServerState, 'ResumableUploadServerState']:
667+
def create_multipart_upload_server_state(self) -> Union[MultipartUploadServerState, "ResumableUploadServerState"]:
671668
raise NotImplementedError
672669

673-
def match_request_to_response(self,
674-
request: requests.Request,
675-
server_state: Union[MultipartUploadServerState, 'ResumableUploadServerState']
676-
) -> Optional[requests.Response]:
670+
def match_request_to_response(
671+
self, request: requests.Request, server_state: Union[MultipartUploadServerState, "ResumableUploadServerState"]
672+
) -> Optional[requests.Response]:
677673
raise NotImplementedError
678674

679675
def run(self, config: Config) -> None:
@@ -842,10 +838,9 @@ def customize_config(self, config: Config) -> None:
842838
def create_multipart_upload_server_state(self) -> MultipartUploadServerState:
843839
return MultipartUploadServerState()
844840

845-
def match_request_to_response(self,
846-
request: requests.Request,
847-
server_state: MultipartUploadServerState
848-
) -> Optional[requests.Response]:
841+
def match_request_to_response(
842+
self, request: requests.Request, server_state: MultipartUploadServerState
843+
) -> Optional[requests.Response]:
849844
request_url = urlparse(request.url)
850845
request_query = parse_qs(request_url.query)
851846

@@ -904,8 +899,7 @@ def processor() -> list:
904899
return self.custom_response_on_create_multipart_url.generate_response(request, processor)
905900

906901
# multipart upload, uploading part
907-
elif request.url.startswith(MultipartUploadServerState.upload_part_url_prefix)\
908-
and request.method == "PUT":
902+
elif request.url.startswith(MultipartUploadServerState.upload_part_url_prefix) and request.method == "PUT":
909903

910904
assert not UploadTestCase.is_auth_header_present(request)
911905

@@ -946,8 +940,7 @@ def processor() -> list:
946940
return self.custom_response_on_complete.generate_response(request, processor)
947941

948942
# create abort URL
949-
elif request.url == "http://localhost/api/2.0/fs/create-abort-upload-url"\
950-
and request.method == "POST":
943+
elif request.url == "http://localhost/api/2.0/fs/create-abort-upload-url" and request.method == "POST":
951944
assert UploadTestCase.is_auth_header_present(request)
952945
request_json = request.json()
953946
assert request_json["path"] == self.path
@@ -965,8 +958,7 @@ def processor() -> list:
965958
return self.custom_response_on_create_abort_url.generate_response(request, processor)
966959

967960
# abort upload
968-
elif request.url.startswith(MultipartUploadServerState.abort_upload_url_prefix)\
969-
and request.method == "DELETE":
961+
elif request.url.startswith(MultipartUploadServerState.abort_upload_url_prefix) and request.method == "DELETE":
970962
assert not UploadTestCase.is_auth_header_present(request)
971963
assert request.url[len(MultipartUploadServerState.abort_upload_url_prefix) :] == self.path
972964

@@ -991,7 +983,7 @@ def __str__(self) -> str:
991983
return self.name
992984

993985
@staticmethod
994-
def to_string(test_case: 'MultipartUploadTestCase') -> str:
986+
def to_string(test_case: "MultipartUploadTestCase") -> str:
995987
return str(test_case)
996988

997989

@@ -1002,7 +994,7 @@ def to_string(test_case: 'MultipartUploadTestCase') -> str:
1002994
MultipartUploadTestCase(
1003995
"Initiate: 400 response is not retried",
1004996
stream_size=1024 * 1024,
1005-
multipart_upload_min_stream_size = 1024 * 1024, # still multipart upload is used
997+
multipart_upload_min_stream_size=1024 * 1024, # still multipart upload is used
1006998
custom_response_on_initiate=CustomResponse(code=400, only_invocation=1),
1007999
expected_exception_type=BadRequest,
10081000
expected_multipart_upload_aborted=False, # upload didn't start
@@ -1157,7 +1149,8 @@ def to_string(test_case: 'MultipartUploadTestCase') -> str:
11571149
"Create upload URL: intermittent retryable exception 3",
11581150
stream_size=1024 * 1024,
11591151
multipart_upload_chunk_size=10 * 1024 * 1024,
1160-
custom_response_on_create_multipart_url=CustomResponse(code=500,
1152+
custom_response_on_create_multipart_url=CustomResponse(
1153+
code=500,
11611154
first_invocation=4,
11621155
last_invocation=6,
11631156
),
@@ -1354,9 +1347,9 @@ def to_string(test_case: 'MultipartUploadTestCase') -> str:
13541347
MultipartUploadTestCase(
13551348
"Small stream, single-shot upload used",
13561349
stream_size=1024 * 1024,
1357-
multipart_upload_min_stream_size = 1024 * 1024 + 1,
1350+
multipart_upload_min_stream_size=1024 * 1024 + 1,
13581351
expected_multipart_upload_aborted=False,
1359-
expected_single_shot_upload=True
1352+
expected_single_shot_upload=True,
13601353
),
13611354
],
13621355
ids=MultipartUploadTestCase.to_string,
@@ -1519,7 +1512,9 @@ def __init__(
15191512
def create_multipart_upload_server_state(self) -> ResumableUploadServerState:
15201513
return ResumableUploadServerState(self.unconfirmed_delta)
15211514

1522-
def match_request_to_response(self, request: requests.Request, server_state: ResumableUploadServerState) -> Optional[requests.Response]:
1515+
def match_request_to_response(
1516+
self, request: requests.Request, server_state: ResumableUploadServerState
1517+
) -> Optional[requests.Response]:
15231518
request_url = urlparse(request.url)
15241519
request_query = parse_qs(request_url.query)
15251520

@@ -1627,7 +1622,7 @@ def __str__(self) -> str:
16271622
return self.name
16281623

16291624
@staticmethod
1630-
def to_string(test_case: 'ResumableUploadTestCase') -> str:
1625+
def to_string(test_case: "ResumableUploadTestCase") -> str:
16311626
return str(test_case)
16321627

16331628

@@ -1827,9 +1822,9 @@ def to_string(test_case: 'ResumableUploadTestCase') -> str:
18271822
ResumableUploadTestCase(
18281823
"Small stream, single-shot upload used",
18291824
stream_size=1024 * 1024,
1830-
multipart_upload_min_stream_size = 1024 * 1024 + 1,
1825+
multipart_upload_min_stream_size=1024 * 1024 + 1,
18311826
expected_multipart_upload_aborted=False,
1832-
expected_single_shot_upload=True
1827+
expected_single_shot_upload=True,
18331828
),
18341829
],
18351830
ids=ResumableUploadTestCase.to_string,

0 commit comments

Comments
 (0)