Skip to content

Commit a2ea123

Browse files
nsmith-maxgalli
andauthored
fix: Actually test using remote url instead of local fs (#80)
* fix: use full remote path when touching file * Test touch nonexistent * Actually have different remote and local paths * Actually use config * We don't need 10 minutes of rerun * Fix test_read_bytes_fsspec * Another test bug * fix correctly --------- Co-authored-by: Massimiliano Galli <massimiliano.galli@cern.ch>
1 parent f0ea1eb commit a2ea123

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
run: python -m pip install .[test]
6363
- name: Test package
6464
run: |
65-
python -m pytest -vv tests --reruns 10 --reruns-delay 30 --only-rerun "(?i)OSError|FileNotFoundError|timeout|expired|connection|socket"
65+
python -m pytest -vv tests --reruns 3 --reruns-delay 5 --only-rerun "(?i)OSError|FileNotFoundError|timeout|expired|connection|socket"
6666
6767
- name: Run fsspec-xrootd tests from uproot latest release
6868
run: |

src/fsspec_xrootd/xrootd.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ async def _rm_file(self, path: str, **kwargs: Any) -> None:
374374
async def _touch(self, path: str, truncate: bool = False, **kwargs: Any) -> None:
375375
if truncate or not await self._exists(path):
376376
f = client.File()
377-
status, _ = await _async_wrap(f.open)(path, OpenFlags.DELETE)
377+
remote_path = self.unstrip_protocol(path)
378+
status, _ = await _async_wrap(f.open)(remote_path, OpenFlags.DELETE)
378379
await _async_wrap(f.close)()
379380
if not status.ok:
380381
raise OSError(f"File not touched properly: {status.message}")

tests/test_basicio.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ def localserver(tmpdir_factory):
3939
srvdir = tmpdir_factory.mktemp("srv")
4040
tempPath = os.path.join(srvdir, "Folder")
4141
os.mkdir(tempPath)
42+
cfgfile = os.path.join(srvdir, "xrd.cfg")
43+
with open(cfgfile, "w") as fout:
44+
fout.write("all.export /Folder\n")
45+
fout.write(f"oss.localroot {srvdir}\n")
4246
xrdexe = shutil.which("xrootd")
43-
proc = subprocess.Popen([xrdexe, "-p", str(XROOTD_PORT), srvdir])
47+
proc = subprocess.Popen([xrdexe, "-p", str(XROOTD_PORT), "-c", cfgfile])
4448
time.sleep(2) # give it some startup
45-
yield "root://localhost/" + str(tempPath), tempPath
49+
yield "root://localhost//Folder", tempPath
4650
proc.terminate()
4751
proc.wait(timeout=10)
4852

@@ -185,10 +189,10 @@ def test_write_fsspec(localserver, clear_server):
185189

186190
def test_write_rpb_fsspec(localserver, clear_server):
187191
"""Test writing with r+b as in uproot"""
188-
remoteurl, localpath = localserver
189-
fs, _ = fsspec.core.url_to_fs(remoteurl)
192+
remoteurl, _ = localserver
193+
fs, _, (prefix,) = fsspec.get_fs_token_paths(remoteurl)
190194
filename = "test.bin"
191-
fs.touch(localpath + "/" + filename)
195+
fs.touch(prefix + "/" + filename)
192196
with fsspec.open(remoteurl + "/" + filename, "r+b") as f:
193197
f.write(b"Hello, this is a test file for r+b mode.")
194198
f.flush()
@@ -208,8 +212,8 @@ def test_read_bytes_fsspec(localserver, clear_server, start, end):
208212
with open(localpath + "/testfile.txt", "w") as fout:
209213
fout.write(TESTDATA1)
210214

211-
fs, _ = fsspec.core.url_to_fs(remoteurl)
212-
data = fs.read_bytes(localpath + "/testfile.txt", start=start, end=end)
215+
fs, _, (prefix,) = fsspec.get_fs_token_paths(remoteurl)
216+
data = fs.read_bytes(prefix + "/testfile.txt", start=start, end=end)
213217
assert data == TESTDATA1.encode("utf-8")[start:end]
214218

215219

@@ -296,6 +300,16 @@ def test_touch_modified(localserver, clear_server):
296300
assert t1 < t2 and t2 < t3
297301

298302

303+
def test_touch_nonexistent(localserver, clear_server):
304+
remoteurl, localpath = localserver
305+
fs, token, path = fsspec.get_fs_token_paths(
306+
remoteurl, "rt", storage_options={"listings_expiry_time": expiry_time}
307+
)
308+
filename = path[0] + "/non-existent-file.bin"
309+
fs.touch(filename)
310+
assert fs.exists(filename)
311+
312+
299313
def test_dir_cache(localserver, clear_server):
300314
remoteurl, localpath = localserver
301315
fs, token, path = fsspec.get_fs_token_paths(

0 commit comments

Comments
 (0)