Skip to content

Commit 363210e

Browse files
lobislgray
andauthored
Run tests on more platforms (#93)
* bump checkout action to v6 * run tests on macos, more python versions * update old actions, use newer python version to build docs * split test setup into `conftest.py` * do not test so many python versions to avoid overloading the CI * 3.11 for full coverage * 3.13 as well - it's fine to overload the CI --------- Co-authored-by: Lindsey Gray <lindsey.gray@gmail.com>
1 parent 9fe0df4 commit 363210e

5 files changed

Lines changed: 70 additions & 58 deletions

File tree

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626

2727
steps:
28-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@v6
2929
with:
3030
fetch-depth: 0
3131

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
name: Format
2020
runs-on: ubuntu-latest
2121
steps:
22-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v6
2323
with:
2424
fetch-depth: 0
2525
- uses: actions/setup-python@v3
@@ -39,8 +39,8 @@ jobs:
3939
strategy:
4040
fail-fast: false
4141
matrix:
42-
python-version: ["3.10", "3.14"]
43-
runs-on: [ubuntu-latest]
42+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
43+
runs-on: [ubuntu-latest, macos-latest]
4444
defaults:
4545
run:
4646
shell: bash -l {0}

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
with:
1818
submodules: recursive
1919

20-
- uses: actions/setup-python@v2
20+
- uses: actions/setup-python@v6
2121
with:
22-
python-version: 3.9
22+
python-version: 3.14
2323

2424
- name: Install package
2525
run: python -m pip install -e .[docs]

tests/conftest.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Test basic IO against a xrootd server fixture"""
2+
3+
from __future__ import annotations
4+
5+
import os
6+
import shutil
7+
import socket
8+
import subprocess
9+
import time
10+
11+
import fsspec
12+
import pytest
13+
14+
XROOTD_PORT = 1094
15+
16+
17+
def require_port_availability(port: int) -> bool:
18+
"""Raise an exception if the given port is already in use."""
19+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
20+
if s.connect_ex(("localhost", port)) == 0:
21+
raise RuntimeError(f"This test requires port {port} to be available")
22+
23+
return True
24+
25+
26+
@pytest.fixture(scope="module")
27+
def localserver(tmpdir_factory):
28+
require_port_availability(XROOTD_PORT)
29+
30+
srvdir = tmpdir_factory.mktemp("srv")
31+
tempPath = os.path.join(srvdir, "Folder")
32+
os.mkdir(tempPath)
33+
cfgfile = os.path.join(srvdir, "xrd.cfg")
34+
with open(cfgfile, "w") as fout:
35+
fout.write("all.export /Folder\n")
36+
fout.write(f"oss.localroot {srvdir}\n")
37+
xrdexe = shutil.which("xrootd")
38+
proc = subprocess.Popen([xrdexe, "-p", str(XROOTD_PORT), "-c", cfgfile])
39+
time.sleep(2) # give it some startup
40+
yield "root://localhost//Folder", tempPath
41+
proc.terminate()
42+
proc.wait(timeout=10)
43+
44+
45+
@pytest.fixture()
46+
def clear_server(localserver):
47+
remoteurl, localpath = localserver
48+
fs, _, _ = fsspec.get_fs_token_paths(remoteurl)
49+
# The open file handles on client side imply an open file handle on the server,
50+
# so removing the directory doesn't actually work until the client closes its handles!
51+
fs.invalidate_cache()
52+
shutil.rmtree(localpath)
53+
os.mkdir(localpath)
54+
yield
55+
56+
57+
def test_ping(localserver, clear_server):
58+
remoteurl, localpath = localserver
59+
from XRootD import client
60+
61+
fs = client.FileSystem(remoteurl)
62+
status, _n = fs.ping()
63+
if not status.ok:
64+
raise OSError(f"Server did not run properly: {status.message}")

tests/test_basicio.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
import asyncio
66
import os
7-
import shutil
8-
import socket
9-
import subprocess
107
import time
118

129
import fsspec
@@ -18,61 +15,12 @@
1815
_vectors_to_chunks,
1916
)
2017

21-
XROOTD_PORT = 1094
2218
TESTDATA1 = "apple\nbanana\norange\ngrape"
2319
TESTDATA2 = "red\ngreen\nyellow\nblue"
2420
sleep_time = 0.2
2521
expiry_time = 0.1
2622

2723

28-
def require_port_availability(port: int) -> bool:
29-
"""Raise an exception if the given port is already in use."""
30-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
31-
if s.connect_ex(("localhost", port)) == 0:
32-
raise RuntimeError(f"This test requires port {port} to be available")
33-
34-
35-
@pytest.fixture(scope="module")
36-
def localserver(tmpdir_factory):
37-
require_port_availability(XROOTD_PORT)
38-
39-
srvdir = tmpdir_factory.mktemp("srv")
40-
tempPath = os.path.join(srvdir, "Folder")
41-
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")
46-
xrdexe = shutil.which("xrootd")
47-
proc = subprocess.Popen([xrdexe, "-p", str(XROOTD_PORT), "-c", cfgfile])
48-
time.sleep(2) # give it some startup
49-
yield "root://localhost//Folder", tempPath
50-
proc.terminate()
51-
proc.wait(timeout=10)
52-
53-
54-
@pytest.fixture()
55-
def clear_server(localserver):
56-
remoteurl, localpath = localserver
57-
fs, _, _ = fsspec.get_fs_token_paths(remoteurl)
58-
# The open file handles on client side imply an open file handle on the server,
59-
# so removing the directory doesn't actually work until the client closes its handles!
60-
fs.invalidate_cache()
61-
shutil.rmtree(localpath)
62-
os.mkdir(localpath)
63-
yield
64-
65-
66-
def test_ping(localserver, clear_server):
67-
remoteurl, localpath = localserver
68-
from XRootD import client
69-
70-
fs = client.FileSystem(remoteurl)
71-
status, _n = fs.ping()
72-
if not status.ok:
73-
raise OSError(f"Server did not run properly: {status.message}")
74-
75-
7624
def test_invalid_server():
7725
with pytest.raises(ValueError):
7826
fsspec.core.url_to_fs("root://")

0 commit comments

Comments
 (0)