diff --git a/tests/test_0001-source-class.py b/tests/test_0001-source-class.py index 0429f5f9b..616f7f627 100644 --- a/tests/test_0001-source-class.py +++ b/tests/test_0001-source-class.py @@ -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 @@ -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" @@ -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" @@ -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, @@ -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) @@ -184,11 +191,11 @@ 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, @@ -196,7 +203,7 @@ def test_http_size(server, use_threads): 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, @@ -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): @@ -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): @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests/test_0006-notify-when-downloaded.py b/tests/test_0006-notify-when-downloaded.py index aea1a96da..527983642 100644 --- a/tests/test_0006-notify-when-downloaded.py +++ b/tests/test_0006-notify-when-downloaded.py @@ -2,6 +2,10 @@ import os import queue +import sys +from io import StringIO + +import numpy import pytest import uproot @@ -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 @@ -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 @@ -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 @@ -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, @@ -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,