88import pytest
99
1010from databricks .sdk .databricks .core import DatabricksError
11-
11+ from databricks . sdk . files . v2 . client import DbfsClient
1212
1313def test_local_io (random ):
1414 if platform .system () == "Windows" :
@@ -28,20 +28,19 @@ def test_local_io(random):
2828def test_dbfs_io (w , random ):
2929 dummy_file = f"/tmp/{ random ()} "
3030 to_write = random (1024 * 1024 * 1.5 ).encode ()
31- with w .dbfs .open (dummy_file , write = True ) as f :
31+ dc = DbfsClient (config = w )
32+ with dc .open (dummy_file , write = True ) as f :
3233 written = f .write (to_write )
3334 assert len (to_write ) == written
3435
35- f = w . dbfs .open (dummy_file , read = True )
36+ f = dc .open (dummy_file , read = True )
3637 from_dbfs = f .read ()
3738 assert from_dbfs == to_write
3839 f .close ()
3940
4041
4142@pytest .fixture
4243def junk (w , random ):
43- from databricks .sdk .files .v2 .client import DbfsClient
44-
4544 dc = DbfsClient (config = w )
4645
4746 def inner (path : str , size = 256 ) -> bytes :
@@ -56,8 +55,6 @@ def inner(path: str, size=256) -> bytes:
5655
5756@pytest .fixture
5857def ls (w ):
59- from databricks .sdk .files .v2 .client import DbfsClient
60-
6158 dc = DbfsClient (config = w )
6259
6360 def inner (root : str , recursive = False ) -> List [str ]:
@@ -88,8 +85,6 @@ def test_cp_dbfs_folder_to_folder_non_recursive(w, random, junk, ls):
8885 junk (f"{ root } /a/b/03" )
8986 new_root = f"/tmp/{ random ()} "
9087
91- from databricks .sdk .files .v2 .client import DbfsClient
92-
9388 dc = DbfsClient (config = w )
9489
9590 dc .copy (root , new_root )
@@ -104,8 +99,6 @@ def test_cp_dbfs_folder_to_folder_recursive(w, random, junk, ls):
10499 junk (f"{ root } /a/b/03" )
105100 new_root = f"/tmp/{ random ()} "
106101
107- from databricks .sdk .files .v2 .client import DbfsClient
108-
109102 dc = DbfsClient (config = w )
110103
111104 dc .copy (root , new_root , recursive = True , overwrite = True )
@@ -120,8 +113,6 @@ def test_cp_dbfs_folder_to_existing_folder_recursive(w, random, junk, ls):
120113 junk (f"{ root } /a/b/03" )
121114 new_root = f"/tmp/{ random ()} "
122115
123- from databricks .sdk .files .v2 .client import DbfsClient
124-
125116 dc = DbfsClient (config = w )
126117
127118 dc .mkdirs (new_root )
@@ -136,8 +127,6 @@ def test_cp_dbfs_file_to_non_existing_location(w, random, junk):
136127 payload = junk (f"{ root } /01" )
137128 copy_destination = f"{ root } /{ random ()} "
138129
139- from databricks .sdk .files .v2 .client import DbfsClient
140-
141130 dc = DbfsClient (config = w )
142131
143132 dc .copy (f"{ root } /01" , copy_destination )
@@ -150,8 +139,6 @@ def test_cp_dbfs_file_to_existing_folder(w, random, junk):
150139 root = f"/tmp/{ random ()} "
151140 payload = junk (f"{ root } /01" )
152141
153- from databricks .sdk .files .v2 .client import DbfsClient
154-
155142 dc = DbfsClient (config = w )
156143
157144 dc .mkdirs (f"{ root } /02" )
@@ -166,8 +153,6 @@ def test_cp_dbfs_file_to_existing_location(w, random, junk):
166153 junk (f"{ root } /01" )
167154 junk (f"{ root } /02" )
168155
169- from databricks .sdk .files .v2 .client import DbfsClient
170-
171156 dc = DbfsClient (config = w )
172157
173158 with pytest .raises (DatabricksError ) as ei :
@@ -180,8 +165,6 @@ def test_cp_dbfs_file_to_existing_location_with_overwrite(w, random, junk):
180165 payload = junk (f"{ root } /01" )
181166 junk (f"{ root } /02" )
182167
183- from databricks .sdk .files .v2 .client import DbfsClient
184-
185168 dc = DbfsClient (config = w )
186169
187170 dc .copy (f"{ root } /01" , f"{ root } /02" , overwrite = True )
@@ -194,8 +177,6 @@ def test_move_within_dbfs(w, random, junk):
194177 root = f"/tmp/{ random ()} "
195178 payload = junk (f"{ root } /01" )
196179
197- from databricks .sdk .files .v2 .client import DbfsClient
198-
199180 dc = DbfsClient (config = w )
200181
201182 dc .move_ (f"{ root } /01" , f"{ root } /02" )
@@ -211,8 +192,6 @@ def test_move_from_dbfs_to_local(w, random, junk, tmp_path):
211192 payload_02 = junk (f"{ root } /a/02" )
212193 payload_03 = junk (f"{ root } /a/b/03" )
213194
214- from databricks .sdk .files .v2 .client import DbfsClient
215-
216195 dc = DbfsClient (config = w )
217196
218197 dc .move_ (root , f"file:{ tmp_path } " , recursive = True )
@@ -230,8 +209,6 @@ def test_dbfs_upload_download(w, random, junk, tmp_path):
230209 root = pathlib .Path (f"/tmp/{ random ()} " )
231210
232211 f = io .BytesIO (b"some text data" )
233- from databricks .sdk .files .v2 .client import DbfsClient
234-
235212 dc = DbfsClient (config = w )
236213
237214 dc .upload (f"{ root } /01" , f )
0 commit comments