Skip to content

Commit 4c2aafe

Browse files
committed
Add tests for {HDF5,SimTel}EventSouce filling Provenance info
1 parent 3f2855c commit 4c2aafe

4 files changed

Lines changed: 41 additions & 14 deletions

File tree

src/ctapipe/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,3 +692,17 @@ def dl1_mon_pointing_file(dl1_file, dl1_tmp_path):
692692
f.remove_node("/configuration/telescope/pointing", recursive=True)
693693

694694
return path
695+
696+
697+
@pytest.fixture
698+
def provenance(monkeypatch):
699+
from ctapipe.core import Provenance
700+
701+
# the singleton nature of Provenance messes with
702+
# the order-independence of the tests asserting
703+
# the provenance contains the correct information
704+
# so we monkeypatch back to an empty state here
705+
prov = Provenance()
706+
monkeypatch.setattr(prov, "_activities", [])
707+
monkeypatch.setattr(prov, "_finished_activities", [])
708+
return prov

src/ctapipe/core/tests/test_provenance.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
11
import json
22

3-
import pytest
4-
53
from ctapipe.core import Provenance
64
from ctapipe.core.provenance import _ActivityProvenance
75
from ctapipe.io.metadata import Reference
86

97

10-
@pytest.fixture
11-
def provenance(monkeypatch):
12-
# the singleton nature of Provenance messes with
13-
# the order-independence of the tests asserting
14-
# the provenance contains the correct information
15-
# so we monkeypatch back to an empty state here
16-
prov = Provenance()
17-
monkeypatch.setattr(prov, "_activities", [])
18-
monkeypatch.setattr(prov, "_finished_activities", [])
19-
return prov
20-
21-
228
def test_provenance_activity_names(provenance):
239
provenance.start_activity("test1")
2410
provenance.add_input_file("input.txt")

src/ctapipe/io/tests/test_hdf5eventsource.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,18 @@ def test_simulated_events_distribution(dl1_file):
270270
dist = source.simulated_shower_distributions[1]
271271
assert dist["n_entries"] == 1000
272272
assert dist["histogram"].sum() == 1000.0
273+
274+
275+
def test_provenance(dl1_file, provenance):
276+
"""Make sure that HDF5EventSource reads reference metadata and adds to provenance"""
277+
from ctapipe.io.metadata import _read_reference_metadata_hdf5
278+
279+
provenance.start_activity("test_hdf5eventsource")
280+
with HDF5EventSource(input_url=dl1_file):
281+
pass
282+
283+
inputs = provenance.current_activity.input
284+
assert len(inputs) == 1
285+
assert inputs[0]["url"] == str(dl1_file)
286+
meta = _read_reference_metadata_hdf5(dl1_file)
287+
assert inputs[0]["reference_meta"].product.id_ == meta.product.id_

src/ctapipe/io/tests/test_simteleventsource.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,15 @@ def test_shower_distribution(prod5_gamma_simtel_path):
641641
assert len(distributions) == 1
642642
distribution = distributions[source.obs_id]
643643
assert distribution.n_entries == 1000
644+
645+
646+
def test_provenance(provenance, prod5_gamma_simtel_path):
647+
provenance.start_activity("test_simteleventsource")
648+
649+
with SimTelEventSource(prod5_gamma_simtel_path):
650+
pass
651+
652+
inputs = provenance.current_activity.input
653+
assert len(inputs) == 1
654+
assert inputs[0]["url"] == str(prod5_gamma_simtel_path)
655+
assert inputs[0]["reference_meta"] is None

0 commit comments

Comments
 (0)