Skip to content

Commit

Permalink
test: Move G4 test preparation to subprocess / fix subprocess invokat…
Browse files Browse the repository at this point in the history
…ion (#1872)
  • Loading branch information
paulgessinger committed Feb 17, 2023
1 parent bcc917d commit 1e83152
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
35 changes: 20 additions & 15 deletions Examples/Python/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import multiprocessing
from pathlib import Path
import sys
import os
Expand Down Expand Up @@ -363,14 +364,7 @@ def _factory(s):
return _factory


@pytest.fixture(scope="session")
def material_recording_session():
if not helpers.geant4Enabled:
pytest.skip("Geantino recording requested, but Geant4 is not set up")

if not helpers.dd4hepEnabled:
pytest.skip("DD4hep recording requested, but Geant4 is not set up")

def _do_material_recording(d: Path):
from material_recording import runMaterialRecording

detector, trackingGeometry, decorators = getOpenDataDetector(
Expand All @@ -381,16 +375,27 @@ def material_recording_session():
detector
)

with tempfile.TemporaryDirectory() as d:
s = acts.examples.Sequencer(events=2, numThreads=1)

runMaterialRecording(dd4hepG4Construction, str(d), tracksPerEvent=100, s=s)
s.run()

s = acts.examples.Sequencer(events=2, numThreads=1)

runMaterialRecording(dd4hepG4Construction, str(d), tracksPerEvent=100, s=s)
s.run()
@pytest.fixture(scope="session")
def material_recording_session():
if not helpers.geant4Enabled:
pytest.skip("Geantino recording requested, but Geant4 is not set up")

if not helpers.dd4hepEnabled:
pytest.skip("DD4hep recording requested, but Geant4 is not set up")

with tempfile.TemporaryDirectory() as d:

del s
del detector
del dd4hepG4Construction
p = multiprocessing.Process(target=_do_material_recording, args=(d,))
p.start()
p.join()
if p.exitcode != 0:
raise RuntimeError("Failure to exeecute material recording")

yield Path(d)

Expand Down
9 changes: 5 additions & 4 deletions Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import functools
import subprocess
import sys

import pytest

Expand Down Expand Up @@ -177,7 +178,7 @@ def test_geant4(tmp_path, assert_root_hash):
env = os.environ.copy()
env["ACTS_LOG_FAILURE_THRESHOLD"] = "WARNING"
subprocess.check_call(
[str(script)],
[sys.executable, str(script)],
cwd=tmp_path,
env=env,
stderr=subprocess.STDOUT,
Expand Down Expand Up @@ -526,7 +527,7 @@ def test_event_recording(tmp_path):
env["NEVENTS"] = "1"
env["ACTS_LOG_FAILURE_THRESHOLD"] = "WARNING"
subprocess.check_call(
[str(script)],
[sys.executable, str(script)],
cwd=tmp_path,
env=env,
stderr=subprocess.STDOUT,
Expand Down Expand Up @@ -1211,7 +1212,7 @@ def test_full_chain_odd_example(tmp_path):
env = os.environ.copy()
env["ACTS_LOG_FAILURE_THRESHOLD"] = "WARNING"
subprocess.check_call(
[str(script), "-n1"],
[sys.executable, str(script), "-n1"],
cwd=tmp_path,
env=env,
stderr=subprocess.STDOUT,
Expand Down Expand Up @@ -1239,7 +1240,7 @@ def test_full_chain_odd_example_pythia_geant4(tmp_path):
env = os.environ.copy()
env["ACTS_LOG_FAILURE_THRESHOLD"] = "WARNING"
subprocess.check_call(
[str(script), "-n1", "--geant4", "--ttbar"],
[sys.executable, str(script), "-n1", "--geant4", "--ttbar"],
cwd=tmp_path,
env=env,
stderr=subprocess.STDOUT,
Expand Down
5 changes: 3 additions & 2 deletions Examples/Python/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,15 @@ def test_root_reader_interface(reader, conf_const, tmp_path):
@pytest.mark.skipif(not geant4Enabled, reason="Geant4 not set up")
def test_root_material_track_reader(material_recording):

# recreate sequencer
input_tracks = material_recording / "geant4_material_tracks.root"
assert input_tracks.exists()

s = Sequencer(numThreads=1)

s.addReader(
RootMaterialTrackReader(
level=acts.logging.INFO,
fileList=[str(material_recording / "geant4_material_tracks.root")],
fileList=[str(input_tracks)],
)
)

Expand Down
3 changes: 2 additions & 1 deletion Examples/Python/tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect
from pathlib import Path
import shutil
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -513,7 +514,7 @@ def hepmc_data_impl(tmp_path_factory):
with tempfile.TemporaryDirectory() as tmp_path:
env = os.environ.copy()
env["NEVENTS"] = "1"
subprocess.check_call([str(script)], cwd=tmp_path, env=env)
subprocess.check_call([sys.executable, str(script)], cwd=tmp_path, env=env)

outfile = Path(tmp_path) / "hepmc3/event000000000-events.hepmc3"
# fake = Path("/scratch/pagessin/acts/hepmc3/event000000000-events.hepmc3")
Expand Down

0 comments on commit 1e83152

Please sign in to comment.