From 8c07da9037270413f3140946cef96703ad53ab0b Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Thu, 25 Aug 2022 18:52:27 +0200 Subject: [PATCH 01/11] Add tests for classes LHEEventInfo, LHEParticle, LHEFile --- tests/test_classes.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_classes.py diff --git a/tests/test_classes.py b/tests/test_classes.py new file mode 100644 index 00000000..729d411a --- /dev/null +++ b/tests/test_classes.py @@ -0,0 +1,36 @@ +import pytest +import skhep_testdata + +from pylhe import LHEEventInfo, LHEParticle, LHEFile +from pylhe import read_lhe + + +TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe") + + +def test_LHEEventInfo_no_default_init(): + with pytest.raises(RuntimeError): + evt_info = LHEEventInfo() + + +def test_LHEParticle_no_default_init(): + with pytest.raises(RuntimeError): + p = LHEParticle() + + +def test_LHEFile(): + assert LHEFile() is not None + + +def test_LHEEvent(): + events = read_lhe(TEST_FILE) + event = next(events) # it contains 8 pions and a proton + + assert event.eventinfo is not None + + assert len(event.particles) == 9 + + for p in event.particles: + assert p.event == event + + assert event._graph is None From 5ea3d2658ec5c5cd1ce609591cf2c42fdb03de78 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 16:54:32 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_classes.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_classes.py b/tests/test_classes.py index 729d411a..60a8c361 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -1,9 +1,7 @@ import pytest import skhep_testdata -from pylhe import LHEEventInfo, LHEParticle, LHEFile -from pylhe import read_lhe - +from pylhe import LHEEventInfo, LHEFile, LHEParticle, read_lhe TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe") @@ -25,12 +23,12 @@ def test_LHEFile(): def test_LHEEvent(): events = read_lhe(TEST_FILE) event = next(events) # it contains 8 pions and a proton - + assert event.eventinfo is not None assert len(event.particles) == 9 for p in event.particles: assert p.event == event - + assert event._graph is None From 067aeed398bb51d78d99474c2f3271060cfc805f Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Thu, 25 Aug 2022 18:57:00 +0200 Subject: [PATCH 03/11] Avoid unused variables --- tests/test_classes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_classes.py b/tests/test_classes.py index 729d411a..120801c1 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -10,12 +10,12 @@ def test_LHEEventInfo_no_default_init(): with pytest.raises(RuntimeError): - evt_info = LHEEventInfo() + _ = LHEEventInfo() def test_LHEParticle_no_default_init(): with pytest.raises(RuntimeError): - p = LHEParticle() + _ = LHEParticle() def test_LHEFile(): From 1de5a26af0121f3282b827c3705522d59657a81a Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Fri, 26 Aug 2022 00:34:27 +0200 Subject: [PATCH 04/11] Better explanations in raise, remove redundant function --- src/pylhe/__init__.py | 9 ++------- tests/test_api.py | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pylhe/__init__.py b/src/pylhe/__init__.py index 6b83fd66..ffd684b2 100644 --- a/src/pylhe/__init__.py +++ b/src/pylhe/__init__.py @@ -16,7 +16,6 @@ "LHEInit", "LHEParticle", "LHEProcInfo", - "loads", "read_lhe", "read_lhe_init", "read_lhe_with_attributes", @@ -122,7 +121,7 @@ class LHEEventInfo: def __init__(self, **kwargs): if set(kwargs.keys()) != set(self.fieldnames): - raise RuntimeError + raise RuntimeError(f"LHEEventInfo constructor expects fields {self.fieldnames}! Got {kwargs.keys()}.") for k, v in kwargs.items(): setattr(self, k, v) @@ -150,7 +149,7 @@ class LHEParticle: def __init__(self, **kwargs): if set(kwargs.keys()) != set(self.fieldnames): - raise RuntimeError + raise RuntimeError(f"LHEParticle constructor expects fields {self.fieldnames}! Got {kwargs.keys()}.") for k, v in kwargs.items(): setattr(self, k, v) @@ -203,10 +202,6 @@ def fromstring(cls, string): return dict(zip(cls.fieldnames, map(float, string.split()))) -def loads(): - pass - - def _extract_fileobj(filepath): """ Checks to see if a file is compressed, and if so, extract it with gzip diff --git a/tests/test_api.py b/tests/test_api.py index d3b288fb..39d1f102 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -19,7 +19,6 @@ def test_top_level_api(): "LHEParticle", "LHEProcInfo", "__version__", - "loads", "read_lhe", "read_lhe_init", "read_lhe_with_attributes", From 6280b73b03abd8852f7d2d680c177f4f782256b4 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Fri, 26 Aug 2022 00:36:51 +0200 Subject: [PATCH 05/11] Basic tests for LHEInit and LHEProcInfo classes --- tests/test_classes.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/test_classes.py b/tests/test_classes.py index febc166f..4a68319c 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -1,25 +1,11 @@ import pytest import skhep_testdata -from pylhe import LHEEventInfo, LHEFile, LHEParticle, read_lhe +from pylhe import LHEEventInfo, LHEFile, LHEInit, LHEParticle, LHEProcInfo, read_lhe TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe") -def test_LHEEventInfo_no_default_init(): - with pytest.raises(RuntimeError): - _ = LHEEventInfo() - - -def test_LHEParticle_no_default_init(): - with pytest.raises(RuntimeError): - _ = LHEParticle() - - -def test_LHEFile(): - assert LHEFile() is not None - - def test_LHEEvent(): events = read_lhe(TEST_FILE) event = next(events) # it contains 8 pions and a proton @@ -32,3 +18,25 @@ def test_LHEEvent(): assert p.event == event assert event._graph is None + + +def test_LHEEventInfo_no_default_init(): + with pytest.raises(RuntimeError): + _ = LHEEventInfo() + + +def test_LHEFile_default_init(): + assert LHEFile() is not None + + +def test_LHEInit_default_init(): + assert LHEInit() is not None + + +def test_LHEParticle_no_default_init(): + with pytest.raises(RuntimeError): + _ = LHEParticle() + + +def test_LHEProcInfo_default_init(): + assert LHEProcInfo() is not None From e63c768b8c9c62981e1ed21dcf58d7576bf5dd00 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Thu, 25 Aug 2022 18:52:27 +0200 Subject: [PATCH 06/11] Add tests for classes LHEEventInfo, LHEParticle, LHEFile --- tests/test_classes.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_classes.py diff --git a/tests/test_classes.py b/tests/test_classes.py new file mode 100644 index 00000000..729d411a --- /dev/null +++ b/tests/test_classes.py @@ -0,0 +1,36 @@ +import pytest +import skhep_testdata + +from pylhe import LHEEventInfo, LHEParticle, LHEFile +from pylhe import read_lhe + + +TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe") + + +def test_LHEEventInfo_no_default_init(): + with pytest.raises(RuntimeError): + evt_info = LHEEventInfo() + + +def test_LHEParticle_no_default_init(): + with pytest.raises(RuntimeError): + p = LHEParticle() + + +def test_LHEFile(): + assert LHEFile() is not None + + +def test_LHEEvent(): + events = read_lhe(TEST_FILE) + event = next(events) # it contains 8 pions and a proton + + assert event.eventinfo is not None + + assert len(event.particles) == 9 + + for p in event.particles: + assert p.event == event + + assert event._graph is None From 104218ab44d88c3414ee82aea0bcdd2b673232af Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 16:54:32 +0000 Subject: [PATCH 07/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_classes.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_classes.py b/tests/test_classes.py index 729d411a..60a8c361 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -1,9 +1,7 @@ import pytest import skhep_testdata -from pylhe import LHEEventInfo, LHEParticle, LHEFile -from pylhe import read_lhe - +from pylhe import LHEEventInfo, LHEFile, LHEParticle, read_lhe TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe") @@ -25,12 +23,12 @@ def test_LHEFile(): def test_LHEEvent(): events = read_lhe(TEST_FILE) event = next(events) # it contains 8 pions and a proton - + assert event.eventinfo is not None assert len(event.particles) == 9 for p in event.particles: assert p.event == event - + assert event._graph is None From 61cc5c558efc9743f54daeed8eeed6fc4f1ff617 Mon Sep 17 00:00:00 2001 From: Eduardo Rodrigues Date: Thu, 25 Aug 2022 18:57:00 +0200 Subject: [PATCH 08/11] Avoid unused variables --- tests/test_classes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_classes.py b/tests/test_classes.py index 60a8c361..febc166f 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -8,12 +8,12 @@ def test_LHEEventInfo_no_default_init(): with pytest.raises(RuntimeError): - evt_info = LHEEventInfo() + _ = LHEEventInfo() def test_LHEParticle_no_default_init(): with pytest.raises(RuntimeError): - p = LHEParticle() + _ = LHEParticle() def test_LHEFile(): From ccc54c1db91baddc29e7e6e82c82032b9f014f08 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Fri, 26 Aug 2022 00:34:27 +0200 Subject: [PATCH 09/11] Better explanations in raise, remove redundant function --- src/pylhe/__init__.py | 9 ++------- tests/test_api.py | 1 - 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pylhe/__init__.py b/src/pylhe/__init__.py index 1bafcc5d..28129af8 100644 --- a/src/pylhe/__init__.py +++ b/src/pylhe/__init__.py @@ -16,7 +16,6 @@ "LHEInit", "LHEParticle", "LHEProcInfo", - "loads", "read_lhe", "read_lhe_init", "read_lhe_with_attributes", @@ -122,7 +121,7 @@ class LHEEventInfo: def __init__(self, **kwargs): if set(kwargs.keys()) != set(self.fieldnames): - raise RuntimeError + raise RuntimeError(f"LHEEventInfo constructor expects fields {self.fieldnames}! Got {kwargs.keys()}.") for k, v in kwargs.items(): setattr(self, k, v) @@ -150,7 +149,7 @@ class LHEParticle: def __init__(self, **kwargs): if set(kwargs.keys()) != set(self.fieldnames): - raise RuntimeError + raise RuntimeError(f"LHEParticle constructor expects fields {self.fieldnames}! Got {kwargs.keys()}.") for k, v in kwargs.items(): setattr(self, k, v) @@ -203,10 +202,6 @@ def fromstring(cls, string): return dict(zip(cls.fieldnames, map(float, string.split()))) -def loads(): - pass - - def _extract_fileobj(filepath): """ Checks to see if a file is compressed, and if so, extract it with gzip diff --git a/tests/test_api.py b/tests/test_api.py index d3b288fb..39d1f102 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -19,7 +19,6 @@ def test_top_level_api(): "LHEParticle", "LHEProcInfo", "__version__", - "loads", "read_lhe", "read_lhe_init", "read_lhe_with_attributes", From 06d9c5133a5defe4e5b70bae708781b3e5006dc8 Mon Sep 17 00:00:00 2001 From: eduardo-rodrigues Date: Fri, 26 Aug 2022 00:36:51 +0200 Subject: [PATCH 10/11] Basic tests for LHEInit and LHEProcInfo classes --- tests/test_classes.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/test_classes.py b/tests/test_classes.py index febc166f..4a68319c 100644 --- a/tests/test_classes.py +++ b/tests/test_classes.py @@ -1,25 +1,11 @@ import pytest import skhep_testdata -from pylhe import LHEEventInfo, LHEFile, LHEParticle, read_lhe +from pylhe import LHEEventInfo, LHEFile, LHEInit, LHEParticle, LHEProcInfo, read_lhe TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe") -def test_LHEEventInfo_no_default_init(): - with pytest.raises(RuntimeError): - _ = LHEEventInfo() - - -def test_LHEParticle_no_default_init(): - with pytest.raises(RuntimeError): - _ = LHEParticle() - - -def test_LHEFile(): - assert LHEFile() is not None - - def test_LHEEvent(): events = read_lhe(TEST_FILE) event = next(events) # it contains 8 pions and a proton @@ -32,3 +18,25 @@ def test_LHEEvent(): assert p.event == event assert event._graph is None + + +def test_LHEEventInfo_no_default_init(): + with pytest.raises(RuntimeError): + _ = LHEEventInfo() + + +def test_LHEFile_default_init(): + assert LHEFile() is not None + + +def test_LHEInit_default_init(): + assert LHEInit() is not None + + +def test_LHEParticle_no_default_init(): + with pytest.raises(RuntimeError): + _ = LHEParticle() + + +def test_LHEProcInfo_default_init(): + assert LHEProcInfo() is not None From d5ebb015ebf0732e3ca2d954bc559c9a3da1510e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Aug 2022 22:37:19 +0000 Subject: [PATCH 11/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pylhe/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pylhe/__init__.py b/src/pylhe/__init__.py index 28129af8..900d03c7 100644 --- a/src/pylhe/__init__.py +++ b/src/pylhe/__init__.py @@ -121,7 +121,9 @@ class LHEEventInfo: def __init__(self, **kwargs): if set(kwargs.keys()) != set(self.fieldnames): - raise RuntimeError(f"LHEEventInfo constructor expects fields {self.fieldnames}! Got {kwargs.keys()}.") + raise RuntimeError( + f"LHEEventInfo constructor expects fields {self.fieldnames}! Got {kwargs.keys()}." + ) for k, v in kwargs.items(): setattr(self, k, v) @@ -149,7 +151,9 @@ class LHEParticle: def __init__(self, **kwargs): if set(kwargs.keys()) != set(self.fieldnames): - raise RuntimeError(f"LHEParticle constructor expects fields {self.fieldnames}! Got {kwargs.keys()}.") + raise RuntimeError( + f"LHEParticle constructor expects fields {self.fieldnames}! Got {kwargs.keys()}." + ) for k, v in kwargs.items(): setattr(self, k, v)