4
4
import sys
5
5
import threading
6
6
import time
7
+ from collections import ChainMap
7
8
from http .server import BaseHTTPRequestHandler , HTTPServer
8
9
9
10
import pytest
25
26
26
27
27
28
class HTTPTestHandler (BaseHTTPRequestHandler ):
28
- files = {
29
+ static_files = {
29
30
"/index/realfile" : data ,
30
31
"/index/otherfile" : data ,
31
32
"/index" : index ,
32
33
"/data/20020401" : listing ,
33
34
}
35
+ dynamic_files = {}
36
+
37
+ files = ChainMap (dynamic_files , static_files )
34
38
35
39
def __init__ (self , * args , ** kwargs ):
36
40
super ().__init__ (* args , ** kwargs )
@@ -81,6 +85,8 @@ def do_POST(self):
81
85
self .files [file_path ] = self .rfile .read (length )
82
86
self ._respond (200 )
83
87
88
+ do_PUT = do_POST
89
+
84
90
def read_chunks (self ):
85
91
length = - 1
86
92
while length != 0 :
@@ -142,6 +148,15 @@ def server():
142
148
yield s
143
149
144
150
151
+ @pytest .fixture
152
+ def reset_files ():
153
+ yield
154
+
155
+ # Reset the newly added files after the
156
+ # test is completed.
157
+ HTTPTestHandler .dynamic_files .clear ()
158
+
159
+
145
160
def test_list (server ):
146
161
h = fsspec .filesystem ("http" )
147
162
out = h .glob (server + "/index/*" )
@@ -432,7 +447,8 @@ def test_info(server):
432
447
assert info ["ETag" ] == "xxx"
433
448
434
449
435
- def test_put_file (server , tmp_path ):
450
+ @pytest .mark .parametrize ("method" , ["POST" , "PUT" ])
451
+ def test_put_file (server , tmp_path , method , reset_files ):
436
452
src_file = tmp_path / "file_1"
437
453
src_file .write_bytes (data )
438
454
@@ -442,7 +458,7 @@ def test_put_file(server, tmp_path):
442
458
with pytest .raises (FileNotFoundError ):
443
459
fs .info (server + "/hey" )
444
460
445
- fs .put_file (src_file , server + "/hey" )
461
+ fs .put_file (src_file , server + "/hey" , method = method )
446
462
assert fs .info (server + "/hey" )["size" ] == len (data )
447
463
448
464
fs .get_file (server + "/hey" , dwl_file )
0 commit comments