Skip to content

Commit

Permalink
attempt to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Oct 25, 2023
1 parent 85bc0d7 commit 5d721df
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 38 deletions.
59 changes: 36 additions & 23 deletions tests/test_0001-source-class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/uproot5/blob/main/LICENSE

import os
import platform
import queue
import sys
from io import StringIO
import contextlib

import numpy
import pytest
Expand Down Expand Up @@ -29,8 +33,9 @@ def use_threads(request):


@pytest.mark.parametrize(
"use_threads, num_workers",
"use_threads,num_workers",
[(True, 1), (True, 2), (False, 0)],
indirect=["use_threads"],
)
def test_file(use_threads, num_workers, tmp_path):
filename = tmp_path / "tmp.raw"
Expand Down Expand Up @@ -58,8 +63,9 @@ def test_file(use_threads, num_workers, tmp_path):


@pytest.mark.parametrize(
"use_threads, num_workers",
"use_threads,num_workers",
[(True, 1), (True, 2), (False, 0)],
indirect=["use_threads"],
)
def test_file_fail(use_threads, num_workers, tmp_path):
filename = tmp_path / "tmp.raw"
Expand Down Expand Up @@ -117,11 +123,12 @@ def test_memmap_fail(use_threads, tmp_path):
...


@pytest.mark.parametrize("use_threads", [True, False])
def test_http(server, use_threads):
url = f"{server}/uproot-issue121.root"
@pytest.mark.skip(reason="RECHECK: example.com is flaky, too")
@pytest.mark.parametrize("use_threads", [True, False], indirect=True)
@pytest.mark.network
def test_http(use_threads):
with uproot.source.http.HTTPSource(
url,
"https://example.com",
timeout=10,
num_fallback_workers=1,
use_threads=use_threads,
Expand All @@ -135,7 +142,7 @@ def test_http(server, use_threads):
assert tmp.fallback is None

with uproot.source.http.MultithreadedHTTPSource(
url, num_workers=1, timeout=10, use_threads=use_threads
"https://example.com", num_workers=1, timeout=10, use_threads=use_threads
) as tmp:
notifications = queue.Queue()
chunks = tmp.chunks([(0, 100), (50, 55), (200, 400)], notifications)
Expand Down Expand Up @@ -184,19 +191,19 @@ def test_http_port(use_threads):
assert [tobytes(x.raw_data) for x in chunks] == [one, two, three]


@pytest.mark.parametrize("use_threads", [True, False])
def test_http_size(server, use_threads):
url = f"{server}/uproot-issue121.root"
@pytest.mark.parametrize("use_threads", [True, False], indirect=True)
@pytest.mark.network
def test_http_size(use_threads):
with uproot.source.http.HTTPSource(
url,
"https://scikit-hep.org/uproot3/examples/Zmumu.root",
timeout=10,
num_fallback_workers=1,
use_threads=use_threads,
) as source:
size1 = source.num_bytes

with uproot.source.http.MultithreadedHTTPSource(
url,
"https://scikit-hep.org/uproot3/examples/Zmumu.root",
num_workers=1,
timeout=10,
use_threads=use_threads,
Expand Down Expand Up @@ -237,15 +244,16 @@ def test_http_fail(use_threads):
num_fallback_workers=1,
use_threads=use_threads,
)
with pytest.raises(Exception):
with pytest.raises(Exception) as err:
notifications = queue.Queue()
chunks = source.chunks([(0, 100), (50, 55), (200, 400)], notifications)
chunks[0].raw_data


@pytest.mark.parametrize(
"use_threads, num_workers",
"use_threads,num_workers",
[(True, 1), (True, 2), (False, 0)],
indirect=["use_threads"],
)
@pytest.mark.network
def test_no_multipart(use_threads, num_workers):
Expand All @@ -265,8 +273,9 @@ def test_no_multipart(use_threads, num_workers):


@pytest.mark.parametrize(
"use_threads, num_workers",
"use_threads,num_workers",
[(True, 1), (True, 2), (False, 0)],
indirect=["use_threads"],
)
@pytest.mark.network
def test_no_multipart_fail(use_threads, num_workers):
Expand All @@ -276,17 +285,21 @@ def test_no_multipart_fail(use_threads, num_workers):
timeout=0.1,
use_threads=use_threads,
)
with pytest.raises(Exception):
with pytest.raises(Exception) as err:
notifications = queue.Queue()
chunks = source.chunks([(0, 100), (50, 55), (200, 400)], notifications)
chunks[0].raw_data


@pytest.mark.parametrize("use_threads, num_workers", [(True, 1), (True, 2), (False, 0)])
def test_fallback(server, use_threads, num_workers):
url = f"{server}/uproot-issue121.root"
@pytest.mark.parametrize(
"use_threads,num_workers",
[(True, 1), (True, 2), (False, 0)],
indirect=["use_threads"],
)
@pytest.mark.network
def test_fallback(use_threads, num_workers):
with uproot.source.http.HTTPSource(
url,
"https://scikit-hep.org/uproot3/examples/Zmumu.root",
timeout=10,
num_fallback_workers=num_workers,
use_threads=use_threads,
Expand Down Expand Up @@ -331,7 +344,7 @@ def test_xrootd(use_threads):
@pytest.mark.parametrize("use_threads", [True, False], indirect=True)
def test_xrootd_deadlock(use_threads):
pytest.importorskip("XRootD")
# Attach this file to the "test_xrootd_deadlock" function, so it leaks
# Attach this file to the "test_xrootd_deadlock" function so it leaks
pytest.uproot_test_xrootd_deadlock_f = uproot.source.xrootd.XRootDResource(
"root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root",
timeout=20,
Expand All @@ -344,7 +357,7 @@ def test_xrootd_deadlock(use_threads):
@pytest.mark.parametrize("use_threads", [True, False], indirect=True)
def test_xrootd_fail(use_threads):
pytest.importorskip("XRootD")
with pytest.raises(Exception):
with pytest.raises(Exception) as err:
uproot.source.xrootd.MultithreadedXRootDSource(
"root://wonky.cern/does-not-exist",
num_workers=1,
Expand Down Expand Up @@ -435,7 +448,7 @@ def get_chunk(Source, **kwargs):
@pytest.mark.parametrize("use_threads", [True, False], indirect=True)
def test_xrootd_vectorread_fail(use_threads):
pytest.importorskip("XRootD")
with pytest.raises(Exception):
with pytest.raises(Exception) as err:
uproot.source.xrootd.XRootDSource(
"root://wonky.cern/does-not-exist",
timeout=1,
Expand Down
37 changes: 22 additions & 15 deletions tests/test_0006-notify-when-downloaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import os
import queue
import sys
from io import StringIO

import numpy
import pytest

import uproot
Expand Down Expand Up @@ -64,11 +68,12 @@ def test_memmap(tmpdir):
expected.pop((chunk.start, chunk.stop))


def test_http_multipart(server):
url = f"{server}/uproot-issue121.root"
@pytest.mark.skip(reason="RECHECK: example.com is flaky, too")
@pytest.mark.network
def test_http_multipart():
notifications = queue.Queue()
with uproot.source.http.HTTPSource(
url, timeout=10, num_fallback_workers=1, use_threads=True
"https://example.com", timeout=10, num_fallback_workers=1, use_threads=True
) as source:
chunks = source.chunks(
[(0, 100), (50, 55), (200, 400)], notifications=notifications
Expand All @@ -79,11 +84,12 @@ def test_http_multipart(server):
expected.pop((chunk.start, chunk.stop))


def test_http(server):
url = f"{server}/uproot-issue121.root"
@pytest.mark.skip(reason="RECHECK: example.com is flaky, too")
@pytest.mark.network
def test_http():
notifications = queue.Queue()
with uproot.source.http.MultithreadedHTTPSource(
url, timeout=10, num_workers=1, use_threads=True
"https://example.com", timeout=10, num_workers=1, use_threads=True
) as source:
chunks = source.chunks(
[(0, 100), (50, 55), (200, 400)], notifications=notifications
Expand All @@ -94,11 +100,12 @@ def test_http(server):
expected.pop((chunk.start, chunk.stop))


def test_http_workers(server):
url = f"{server}/uproot-issue121.root"
@pytest.mark.skip(reason="RECHECK: example.com is flaky, too")
@pytest.mark.network
def test_http_workers():
notifications = queue.Queue()
with uproot.source.http.MultithreadedHTTPSource(
url, timeout=10, num_workers=2, use_threads=True
"https://example.com", timeout=10, num_workers=2, use_threads=True
) as source:
chunks = source.chunks(
[(0, 100), (50, 55), (200, 400)], notifications=notifications
Expand All @@ -109,11 +116,11 @@ def test_http_workers(server):
expected.pop((chunk.start, chunk.stop))


def test_http_fallback(server):
url = f"{server}/uproot-issue121.root"
@pytest.mark.network
def test_http_fallback():
notifications = queue.Queue()
with uproot.source.http.HTTPSource(
url,
"https://scikit-hep.org/uproot3/examples/Zmumu.root",
timeout=10,
num_fallback_workers=1,
use_threads=True,
Expand All @@ -127,11 +134,11 @@ def test_http_fallback(server):
expected.pop((chunk.start, chunk.stop))


def test_http_fallback_workers(server):
url = f"{server}/uproot-issue121.root"
@pytest.mark.network
def test_http_fallback_workers():
notifications = queue.Queue()
with uproot.source.http.HTTPSource(
url,
"https://scikit-hep.org/uproot3/examples/Zmumu.root",
timeout=10,
num_fallback_workers=5,
use_threads=True,
Expand Down

0 comments on commit 5d721df

Please sign in to comment.