diff --git a/.travis.yml b/.travis.yml index 90f98bc9..c0dcea04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,13 +44,13 @@ install: # FIXME: Mamba causes pip install numpy to be extremely slow - if [[ "${PYVER}" = pypy* ]]; then conda create --quiet --yes -n testenv ${PYVER}; - elif [ "${PYVER}" = "2.7" ] || [ "${PYVER}" = "3.6" ] || [ "${PYVER}" = "3.7" ]; then + elif [ "${PYVER}" = "2.7" ] || [ "${PYVER}" = "3.6" ] || [ "${PYVER}" = "3.7" || [ "${PYVER}" = "3.8" ]; then conda create --quiet --yes -n testenv python=${PYVER} pip; else conda create --quiet --yes -n testenv python=${PYVER}; fi - source activate testenv - - if [ "${PYVER}" = "2.7" ] || [ "${PYVER}" = "3.6" ] || [ "${PYVER}" = "3.7" ]; then + - if [ "${PYVER}" = "2.7" ] || [ "${PYVER}" = "3.6" ] || [ "${PYVER}" = "3.7" || [ "${PYVER}" = "3.8" ]; then conda install --quiet --yes python=${PYVER} pip root; source activate testenv; fi @@ -69,6 +69,7 @@ install: conda install -c anaconda python=${PYVER} pyopenssl; fi - wget -O tests/samples/Event.root http://scikit-hep.org/uproot/examples/Event.root + - pip install git+https://github.com/chrisburr/pytest-error-for-skips.git@patch-1 addons: apt: @@ -77,7 +78,11 @@ addons: - libatlas-base-dev script: - pytest -v tests + if [ "${PYVER}" = "2.7" ] || [ "${PYVER}" = "3.6" ] || [ "${PYVER}" = "3.7" || [ "${PYVER}" = "3.8" ]; then + pytest --error-for-skips -v tests; + else + pytest -v tests; + fi notifications: slack: scikit-hep:b6cgBXwccPoaCNLn5VKFJFVy diff --git a/tests/test_cache.py b/tests/test_cache.py index 17809d3d..5752ca81 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -2,13 +2,9 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest - -from collections import namedtuple - import uproot -class Test(unittest.TestCase): +class Test(object): def test_flat_array(self): branch = uproot.open("tests/samples/sample-6.10.05-uncompressed.root")["sample"]["i8"] expectation = [-15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] diff --git a/tests/test_compression.py b/tests/test_compression.py index da755139..fbf1e928 100644 --- a/tests/test_compression.py +++ b/tests/test_compression.py @@ -2,8 +2,6 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest - try: import lzma except ImportError: @@ -13,7 +11,7 @@ import uproot -class Test(unittest.TestCase): +class Test(object): def test_compression_identity(self): assert uproot.open("tests/samples/Zmumu-zlib.root").compression.algoname == "zlib" assert uproot.open("tests/samples/Zmumu-zlib.root").compression.level == 4 diff --git a/tests/test_http.py b/tests/test_http.py index 251b74e5..e52dd02a 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -2,8 +2,6 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest - import pytest import mock from requests.exceptions import HTTPError @@ -41,7 +39,7 @@ def raise_for_status(self): return MockResponse(401) @mock.patch("requests.get", mock_get_local_instead_of_http) -class Test(unittest.TestCase): +class Test(object): def test_no_auth_needed_no_auth(self): f = uproot.open(URL) assert type(f) == uproot.rootio.ROOTDirectory diff --git a/tests/test_issues.py b/tests/test_issues.py index 28960335..44adc0cf 100644 --- a/tests/test_issues.py +++ b/tests/test_issues.py @@ -2,10 +2,6 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest - -from collections import namedtuple - import pytest import numpy @@ -16,7 +12,7 @@ import uproot_methods.classes.TLorentzVector -class Test(unittest.TestCase): +class Test(object): def test_issue21(self): t = uproot.open("tests/samples/issue21.root")["nllscan"] @@ -271,27 +267,18 @@ def test_issue213(self): ] def test_issue232(self): - try: - import pandas - except ImportError: - pass - else: - t = uproot.open("tests/samples/issue232.root")["fTreeV0"] - t.pandas.df( - ["V0Hyper.fNsigmaHe3Pos", "V0Hyper.fDcaPos2PrimaryVertex"], - flatten=True) - - @pytest.mark.skip(reason="This one takes way too long (eospublic?).") + pytest.importorskip("pandas") + t = uproot.open("tests/samples/issue232.root")["fTreeV0"] + t.pandas.df( + ["V0Hyper.fNsigmaHe3Pos", "V0Hyper.fDcaPos2PrimaryVertex"], + flatten=True) + def test_issue240(self): - try: - import pyxrootd - except ImportError: - pytest.skip("unable to import pyxrootd") - else: - t = uproot.open( - "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root" - )["Events"] - assert (abs(t.array("nMuon")) < 50).all() + pytest.importorskip("pyxrootd") + t = uproot.open( + "root://eospublic.cern.ch//eos/root-eos/cms_opendata_2012_nanoaod/Run2012B_DoubleMuParked.root" + )["Events"] + assert (abs(t.array("nMuon", entrystop=100000)) < 50).all() def test_issue243(self): t = uproot.open("tests/samples/issue243.root")["triggerList"] diff --git a/tests/test_jagged.py b/tests/test_jagged.py index 5cfe8899..9019fea0 100644 --- a/tests/test_jagged.py +++ b/tests/test_jagged.py @@ -2,35 +2,35 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest +import pytest import uproot -try: - import pandas -except ImportError: - pandas = None -class Test(unittest.TestCase): - if pandas is not None: - sample = uproot.open("tests/samples/sample-6.10.05-uncompressed.root")["sample"] + +class Test(object): + @property + def sample(self): + pytest.importorskip("pandas") + try: + self._sample + except AttributeError: + self._sample = uproot.open("tests/samples/sample-6.10.05-uncompressed.root")["sample"] + return self._sample def test_flatten_False(self): - if pandas is not None: - df = self.sample.pandas.df(flatten=False) - assert len(df.keys()) == 57 - assert "Af8" in df - assert len(df.at[0, "Af8"]) == 0 - assert len(df.at[1, "Af8"]) == 1 - assert len(df.at[2, "Af8"]) == 2 + df = self.sample.pandas.df(flatten=False) + assert len(df.keys()) == 57 + assert "Af8" in df + assert len(df.at[0, "Af8"]) == 0 + assert len(df.at[1, "Af8"]) == 1 + assert len(df.at[2, "Af8"]) == 2 def test_flatten_None(self): - if pandas is not None: - df = self.sample.pandas.df(flatten=None) - assert len(df.keys()) == 46 - assert "Af8" not in df + df = self.sample.pandas.df(flatten=None) + assert len(df.keys()) == 46 + assert "Af8" not in df def test_flatten_True(self): - if pandas is not None: - df = self.sample.pandas.df(flatten=True) - assert len(df.keys()) == 57 - assert "Af8" in df + df = self.sample.pandas.df(flatten=True) + assert len(df.keys()) == 57 + assert "Af8" in df diff --git a/tests/test_stlvector.py b/tests/test_stlvector.py index aa1c9ab3..03733e12 100644 --- a/tests/test_stlvector.py +++ b/tests/test_stlvector.py @@ -2,13 +2,9 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest - -from collections import namedtuple - import uproot -class Test(unittest.TestCase): +class Test(object): def runTest(self): pass diff --git a/tests/test_tree.py b/tests/test_tree.py index ecb4d3e0..cf4fdfcf 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -3,8 +3,6 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE import os -import unittest - from collections import namedtuple import numpy @@ -18,7 +16,7 @@ def basest(array): array = array.base return array -class Test(unittest.TestCase): +class Test(object): ###################################################### double32 def test_double32(self): @@ -594,9 +592,12 @@ def test_tree_lazy_cached(self): for i in range(len(lazy), 0, -1): assert lazy[i - 1 : i + 3].tolist() == strict[i - 1 : i + 3].tolist() - def test_hist_in_tree(self): - path = os.path.join("tests", "samples", "Event.root") - if os.path.exists(path): + @pytest.mark.parametrize("use_http", [False, True]) + def test_hist_in_tree(self, use_http): + if use_http: + path = os.path.join("tests", "samples", "Event.root") + if not os.path.exists(path): + raise pytest.skip() tree = uproot.open(path)["T"] else: tree = uproot.open("http://scikit-hep.org/uproot/examples/Event.root")["T"] @@ -610,7 +611,8 @@ def test_hist_in_tree(self): assert tree.array("fH")[20].values.tolist() == check - def test_branch_auto_interpretation(self): + @pytest.mark.parametrize("use_http", [False, True]) + def test_branch_auto_interpretation(self, use_http): # The aim is to reduce this list in a controlled manner known_branches_without_interp = [ b'event', @@ -622,8 +624,10 @@ def test_branch_auto_interpretation(self): b'fTriggerBits', b'fTriggerBits.TObject' ] - path = os.path.join("tests", "samples", "Event.root") - if os.path.exists(path): + if use_http: + path = os.path.join("tests", "samples", "Event.root") + if not os.path.exists(path): + raise pytest.skip() tree = uproot.open(path)["T"] else: tree = uproot.open("http://scikit-hep.org/uproot/examples/Event.root")["T"] @@ -650,24 +654,20 @@ def test_leaflist(self): assert a["y"].tolist() == [1, 2, 3, 4, 5] assert a["z"].tolist() == [ord("a"), ord("b"), ord("c"), ord("d"), ord("e")] - try: - import pandas - except ImportError: - pass - else: - assert tree.pandas.df()["leaflist.x"].tolist() == [1.1, 2.2, 3.3, 4.0, 5.5] - - tree = uproot.open("tests/samples/HZZ-objects.root")["events"] - tree.pandas.df("muonp4") - tree.pandas.df("muonp4", flatten=False) - df = tree.pandas.df("eventweight", entrystart=100, entrystop=200) - index = df.index.tolist() - assert min(index) == 100 - assert max(index) == 199 - df = tree.pandas.df("muonp4", entrystart=100, entrystop=200) - index = df.index.get_level_values("entry").tolist() - assert min(index) == 100 - assert max(index) == 199 + pytest.importorskip("pandas") + assert tree.pandas.df()["leaflist.x"].tolist() == [1.1, 2.2, 3.3, 4.0, 5.5] + + tree = uproot.open("tests/samples/HZZ-objects.root")["events"] + tree.pandas.df("muonp4") + tree.pandas.df("muonp4", flatten=False) + df = tree.pandas.df("eventweight", entrystart=100, entrystop=200) + index = df.index.tolist() + assert min(index) == 100 + assert max(index) == 199 + df = tree.pandas.df("muonp4", entrystart=100, entrystop=200) + index = df.index.get_level_values("entry").tolist() + assert min(index) == 100 + assert max(index) == 199 def test_mempartitions(self): t = uproot.open("tests/samples/sample-5.23.02-zlib.root")["sample"] diff --git a/tests/test_versions.py b/tests/test_versions.py index ceeff735..e31526f1 100644 --- a/tests/test_versions.py +++ b/tests/test_versions.py @@ -2,8 +2,6 @@ # BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE -import unittest - try: import lzma except ImportError: @@ -12,7 +10,7 @@ import uproot -class Test(unittest.TestCase): +class Test(object): sample = { b"n": [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4], diff --git a/uproot/source/http.py b/uproot/source/http.py index 1011359c..d9df3eff 100644 --- a/uproot/source/http.py +++ b/uproot/source/http.py @@ -40,7 +40,7 @@ def _read(self, chunkindex): while True: response = requests.get( self.path, - headers={"Range": "bytes={0}-{1}".format(chunkindex * self._chunkbytes, (chunkindex + 1) * self._chunkbytes)}, + headers={"Range": "bytes={0}-{1}".format(chunkindex * self._chunkbytes, (chunkindex + 1) * self._chunkbytes - 1)}, auth=self.auth, ) if response.status_code == 504: # timeout, try it again