2
2
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
3
3
#
4
4
5
- import os
6
5
import random
7
- import shutil
8
6
import string
9
7
import tempfile
8
+ from pathlib import Path
10
9
11
10
import pytest
12
11
@@ -26,18 +25,14 @@ def test_multi_chunk_upload(multipart_threshold):
26
25
[random .choice (string .ascii_letters ) for _ in range (300 )]
27
26
).encode ()
28
27
file_name = "test_file"
29
- stage_dir = tempfile .mkdtemp ()
30
- stage_file = os .path .join (stage_dir , file_name )
31
- local_dir = tempfile .mkdtemp ()
32
- local_file = os .path .join (local_dir , file_name )
33
-
34
- try :
35
- with open (local_file , "wb+" ) as fd :
36
- fd .write (file_content )
28
+ with tempfile .TemporaryDirectory () as stage_dir , tempfile .TemporaryDirectory () as local_dir :
29
+ stage_file = Path (stage_dir ) / file_name
30
+ local_file = Path (local_dir ) / file_name
31
+ Path (local_file ).write_bytes (file_content )
37
32
38
33
meta = SnowflakeFileMeta (
39
34
name = file_name ,
40
- src_file_name = local_file ,
35
+ src_file_name = str ( local_file ) ,
41
36
stage_location_type = LOCAL_FS ,
42
37
dst_file_name = file_name ,
43
38
multipart_threshold = multipart_threshold ,
@@ -47,11 +42,7 @@ def test_multi_chunk_upload(multipart_threshold):
47
42
for chunk_id in range (client .num_of_chunks ):
48
43
client .upload_chunk (chunk_id )
49
44
50
- with open (stage_file , "rb" ) as fd :
51
- assert fd .read () == file_content
52
- finally :
53
- shutil .rmtree (stage_dir , ignore_errors = True )
54
- shutil .rmtree (local_dir , ignore_errors = True )
45
+ assert Path (stage_file ).read_bytes () == file_content
55
46
56
47
57
48
@pytest .mark .parametrize ("multipart_threshold" , [0 , 67108864 ])
@@ -60,18 +51,14 @@ def test_multi_chunk_download(multipart_threshold):
60
51
[random .choice (string .ascii_letters ) for _ in range (300 )]
61
52
).encode ()
62
53
file_name = "test_file"
63
- stage_dir = tempfile .mkdtemp ()
64
- stage_file = os .path .join (stage_dir , file_name )
65
- local_dir = tempfile .mkdtemp ()
66
- local_file = os .path .join (local_dir , file_name )
67
-
68
- try :
69
- with open (stage_file , "wb+" ) as fd :
70
- fd .write (file_content )
54
+ with tempfile .TemporaryDirectory () as stage_dir , tempfile .TemporaryDirectory () as local_dir :
55
+ stage_file = Path (stage_dir ) / file_name
56
+ local_file = Path (local_dir ) / file_name
57
+ Path (stage_file ).write_bytes (file_content )
71
58
72
59
meta = SnowflakeFileMeta (
73
60
name = file_name ,
74
- src_file_name = stage_file ,
61
+ src_file_name = str ( stage_file ) ,
75
62
stage_location_type = LOCAL_FS ,
76
63
dst_file_name = file_name ,
77
64
local_location = local_dir ,
@@ -83,8 +70,4 @@ def test_multi_chunk_download(multipart_threshold):
83
70
client .download_chunk (chunk_id )
84
71
client .finish_download ()
85
72
86
- with open (local_file , "rb" ) as fd :
87
- assert fd .read () == file_content
88
- finally :
89
- shutil .rmtree (stage_dir , ignore_errors = True )
90
- shutil .rmtree (local_dir , ignore_errors = True )
73
+ assert Path (local_file ).read_bytes () == file_content
0 commit comments