Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add tests for LHEEventInfo, LHEParticle, LHEFile classes #136

Merged
merged 13 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/pylhe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"LHEInit",
"LHEParticle",
"LHEProcInfo",
"loads",
"read_lhe",
"read_lhe_init",
"read_lhe_with_attributes",
Expand Down Expand Up @@ -122,7 +121,9 @@ 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)

Expand Down Expand Up @@ -150,7 +151,9 @@ 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)

Expand Down Expand Up @@ -203,10 +206,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
Expand Down
1 change: 0 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def test_top_level_api():
"LHEParticle",
"LHEProcInfo",
"__version__",
"loads",
"read_lhe",
"read_lhe_init",
"read_lhe_with_attributes",
Expand Down
42 changes: 42 additions & 0 deletions tests/test_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import pytest
import skhep_testdata

from pylhe import LHEEventInfo, LHEFile, LHEInit, LHEParticle, LHEProcInfo, read_lhe

TEST_FILE = skhep_testdata.data_path("pylhe-testfile-pr29.lhe")


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


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