Skip to content

Commit 87f7f99

Browse files
committed
tests: reproduce http glob missing folders issue
1 parent 7700b69 commit 87f7f99

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

fsspec/implementations/tests/test_http.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import fsspec.asyn
1212
import fsspec.utils
1313
from fsspec.implementations.http import HTTPStreamFile
14-
from fsspec.tests.conftest import data, reset_files, server, win # noqa: F401
14+
from fsspec.tests.conftest import data, reset_files, server, stdlib_simple_http_server, win # noqa: F401
1515

1616

1717
def test_list(server):
@@ -129,6 +129,17 @@ def test_list_cache_with_skip_instance_cache(server):
129129
assert out == [server + "/index/realfile"]
130130

131131

132+
def test_glob_return_subfolders(stdlib_simple_http_server):
133+
h = fsspec.filesystem("http")
134+
out = h.glob(stdlib_simple_http_server + "/*", )
135+
assert out == [
136+
stdlib_simple_http_server + "/file1",
137+
stdlib_simple_http_server + "/file2",
138+
stdlib_simple_http_server + "/folder1/",
139+
stdlib_simple_http_server + "/folder2/",
140+
]
141+
142+
132143
def test_isdir(server):
133144
h = fsspec.filesystem("http")
134145
assert h.isdir(server + "/index/")

fsspec/tests/conftest.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import gzip
33
import json
44
import os
5+
import subprocess
56
import threading
7+
import time
68
from collections import ChainMap
79
from http.server import BaseHTTPRequestHandler, HTTPServer
810

@@ -173,3 +175,45 @@ def serve():
173175
def server():
174176
with serve() as s:
175177
yield s
178+
179+
180+
def _populate_test_dir(path):
181+
path.joinpath("file1").write_text("file1")
182+
path.joinpath("file2").write_text("file2")
183+
f1 = path.joinpath("folder1")
184+
f1.mkdir()
185+
f2 = path.joinpath("folder2")
186+
f2.mkdir()
187+
f1.joinpath("file3.txt").write_text("file3")
188+
f2.joinpath("file4.txt").write_text("file4")
189+
190+
191+
@pytest.fixture(scope="session")
192+
def stdlib_simple_http_server(tmp_path_factory):
193+
requests = pytest.importorskip("requests")
194+
195+
path = tmp_path_factory.mktemp("http")
196+
_populate_test_dir(path)
197+
198+
port = 9899
199+
url = f"http://127.0.0.1:{port}"
200+
pytest.importorskip("http.server")
201+
proc = subprocess.Popen(
202+
["python", "-m", "http.server", "--directory", str(path), str(port)]
203+
)
204+
timeout = 10
205+
try:
206+
while True:
207+
try:
208+
r = requests.get(url, timeout=10)
209+
if r.ok:
210+
break
211+
except Exception as e: # noqa: E722
212+
timeout -= 1
213+
if timeout < 0:
214+
raise SystemError from e
215+
time.sleep(1)
216+
yield url
217+
finally:
218+
proc.terminate()
219+
proc.wait()

0 commit comments

Comments
 (0)