8
8
import os
9
9
10
10
import pytest
11
-
12
- files = {
13
- "LICENSE" : (
14
- b" Apache License\n "
15
- b" Version 2.0, January 2004\n "
16
- b" http://www.apache.org/licenses/\n "
17
- ),
18
- "number" : (b"1234567890\n " ),
19
- }
20
-
21
- glob_files = {"file.dat" : b"" , "filexdat" : b"" }
11
+ from conftest import LICENSE_PATH , NUMBERS
22
12
23
13
24
14
def test_simple (ossfs , test_path ):
@@ -62,35 +52,36 @@ def test_seek(ossfs, test_path):
62
52
assert f .seek (i ) == i
63
53
64
54
65
- def test_read_small (ossfs , test_bucket_name ):
66
- fn = test_bucket_name + "/number"
67
- with ossfs .open (fn , "rb" , block_size = 3 ) as f :
55
+ def test_read_small (ossfs , number_file ):
56
+ with ossfs .open (number_file , "rb" , block_size = 3 ) as f :
68
57
out = []
69
58
while True :
70
59
data = f .read (2 )
71
60
if data == b"" :
72
61
break
73
62
out .append (data )
74
- assert ossfs .cat (fn ) == b"" .join (out )
63
+ assert ossfs .cat (number_file ) == b"" .join (out )
75
64
76
65
77
- def test_read_ossfs_block (ossfs , test_bucket_name ):
78
- data = files ["LICENSE" ]
66
+ def test_read_ossfs_block (ossfs , license_file , number_file ):
67
+ with open (LICENSE_PATH , "rb" ) as f_r :
68
+ data = f_r .read ()
79
69
lines = io .BytesIO (data ).readlines ()
80
- path = test_bucket_name + "/LICENSE"
81
- assert ossfs .read_block (path , 0 , 10 , b"\n " ) == lines [0 ]
82
- assert ossfs .read_block (path , 40 , 10 , b"\n " ) == lines [1 ]
83
- assert ossfs .read_block (path , 0 , 80 , b"\n " ) == lines [0 ] + lines [1 ]
84
- assert ossfs .read_block (path , 0 , 120 , b"\n " ) == data
70
+ assert ossfs .read_block (license_file , 0 , 10 , b"\n " ) == lines [0 ]
71
+ assert ossfs .read_block (license_file , 40 , 10 , b"\n " ) == lines [1 ]
72
+ assert ossfs .read_block (license_file , 0 , 80 , b"\n " ) == lines [0 ] + lines [1 ]
73
+ assert ossfs .read_block (license_file , 0 , 120 , b"\n " ) == b"" .join (
74
+ [lines [0 ], lines [1 ], lines [2 ]]
75
+ )
85
76
86
- data = files ["number" ]
87
- lines = io .BytesIO (data ).readlines ()
88
- path = test_bucket_name + "/number"
89
- assert len (ossfs .read_block (path , 0 , 5 )) == 5
90
- assert len (ossfs .read_block (path , 4 , 150 )) == len (data ) - 4
91
- assert ossfs .read_block (path , 20 , 25 ) == b""
77
+ lines = io .BytesIO (NUMBERS ).readlines ()
78
+ assert len (ossfs .read_block (number_file , 0 , 5 )) == 5
79
+ assert len (ossfs .read_block (number_file , 4 , 150 )) == len (NUMBERS ) - 4
80
+ assert ossfs .read_block (number_file , 20 , 25 ) == b""
92
81
93
- assert ossfs .read_block (path , 5 , None ) == ossfs .read_block (path , 5 , 25 )
82
+ assert ossfs .read_block (number_file , 5 , None ) == ossfs .read_block (
83
+ number_file , 5 , 25
84
+ )
94
85
95
86
96
87
@pytest .mark .parametrize ("size" , [2 ** 10 , 2 ** 20 , 10 * 2 ** 20 ])
@@ -134,15 +125,18 @@ def test_write_blocks(ossfs, test_path):
134
125
assert ossfs .info (file )["Size" ] == 15 * 2 ** 20
135
126
136
127
137
- def test_readline (ossfs , test_bucket_name ):
138
- all_items = files .items ()
139
- for k , data in all_items :
140
- with ossfs .open ("/" .join ([test_bucket_name , k ]), "rb" ) as f :
141
- result = f .readline ()
142
- expected = data .split (b"\n " )[0 ] + (
143
- b"\n " if data .count (b"\n " ) else b""
144
- )
145
- assert result == expected
128
+ def test_readline (ossfs , number_file , license_file ):
129
+ with ossfs .open ("/" .join ([number_file ]), "rb" ) as f_r :
130
+ result = f_r .readline ()
131
+ expected = NUMBERS
132
+ assert result == expected
133
+
134
+ with ossfs .open ("/" .join ([license_file ]), "rb" ) as f_r , open (
135
+ LICENSE_PATH , "rb"
136
+ ) as f_l :
137
+ result = f_r .readline ()
138
+ expected = f_l .readline ()
139
+ assert result == expected
146
140
147
141
148
142
def test_readline_empty (ossfs , test_path ):
@@ -174,10 +168,10 @@ def test_readline_blocksize(ossfs, test_path):
174
168
assert result == expected
175
169
176
170
177
- def test_next (ossfs , test_bucket_name ):
178
- expected = files [ "LICENSE" ]. split ( b" \n " )[ 0 ] + b" \n "
179
- with ossfs . open ( test_bucket_name + "/LICENSE" ) as f :
180
- result = next (f )
171
+ def test_next (ossfs , license_file ):
172
+ with open ( LICENSE_PATH , "rb" ) as f_l , ossfs . open ( license_file ) as f_r :
173
+ expected = f_l . readline ()
174
+ result = next (f_r )
181
175
assert result == expected
182
176
183
177
@@ -219,7 +213,7 @@ def test_file_status(ossfs, test_path):
219
213
@pytest .mark .parametrize ("data_size" , [0 , 20 , 10 * 2 ** 20 ])
220
214
@pytest .mark .parametrize ("append_size" , [0 , 20 , 10 * 2 ** 20 ])
221
215
def test_append (ossfs , test_path , data_size , append_size ):
222
- file = test_path + "/test_append/file_{}_{}" . format ( data_size , append_size )
216
+ file = test_path + f "/test_append/file_{ data_size } _{ append_size } "
223
217
data = os .urandom (data_size )
224
218
extra = os .urandom (append_size )
225
219
with ossfs .open (file , "wb" ) as f :
@@ -230,8 +224,8 @@ def test_append(ossfs, test_path, data_size, append_size):
230
224
assert ossfs .cat (file ) == data + extra
231
225
232
226
233
- def test_bigger_than_block_read (ossfs , test_bucket_name ):
234
- with ossfs .open (test_bucket_name + "/number" , "rb" , block_size = 3 ) as f :
227
+ def test_bigger_than_block_read (ossfs , number_file ):
228
+ with ossfs .open (number_file , "rb" , block_size = 3 ) as f :
235
229
out = []
236
230
while True :
237
231
data = f .read (4 )
0 commit comments