Skip to content

Commit

Permalink
Add tests for {HDF5,SimTel}EventSouce filling Provenance info
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Nov 13, 2024
1 parent 3f2855c commit 4c2aafe
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
14 changes: 14 additions & 0 deletions src/ctapipe/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,17 @@ def dl1_mon_pointing_file(dl1_file, dl1_tmp_path):
f.remove_node("/configuration/telescope/pointing", recursive=True)

return path


@pytest.fixture
def provenance(monkeypatch):
from ctapipe.core import Provenance

# the singleton nature of Provenance messes with
# the order-independence of the tests asserting
# the provenance contains the correct information
# so we monkeypatch back to an empty state here
prov = Provenance()
monkeypatch.setattr(prov, "_activities", [])
monkeypatch.setattr(prov, "_finished_activities", [])
return prov
14 changes: 0 additions & 14 deletions src/ctapipe/core/tests/test_provenance.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import json

import pytest

from ctapipe.core import Provenance
from ctapipe.core.provenance import _ActivityProvenance
from ctapipe.io.metadata import Reference


@pytest.fixture
def provenance(monkeypatch):
# the singleton nature of Provenance messes with
# the order-independence of the tests asserting
# the provenance contains the correct information
# so we monkeypatch back to an empty state here
prov = Provenance()
monkeypatch.setattr(prov, "_activities", [])
monkeypatch.setattr(prov, "_finished_activities", [])
return prov


def test_provenance_activity_names(provenance):
provenance.start_activity("test1")
provenance.add_input_file("input.txt")
Expand Down
15 changes: 15 additions & 0 deletions src/ctapipe/io/tests/test_hdf5eventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,18 @@ def test_simulated_events_distribution(dl1_file):
dist = source.simulated_shower_distributions[1]
assert dist["n_entries"] == 1000
assert dist["histogram"].sum() == 1000.0


def test_provenance(dl1_file, provenance):
"""Make sure that HDF5EventSource reads reference metadata and adds to provenance"""
from ctapipe.io.metadata import _read_reference_metadata_hdf5

provenance.start_activity("test_hdf5eventsource")
with HDF5EventSource(input_url=dl1_file):
pass

Check warning on line 281 in src/ctapipe/io/tests/test_hdf5eventsource.py

View check run for this annotation

CTAO-DPPS-SonarQube / ctapipe Sonarqube Results

src/ctapipe/io/tests/test_hdf5eventsource.py#L281

Either remove or fill this block of code.

inputs = provenance.current_activity.input
assert len(inputs) == 1
assert inputs[0]["url"] == str(dl1_file)
meta = _read_reference_metadata_hdf5(dl1_file)
assert inputs[0]["reference_meta"].product.id_ == meta.product.id_
12 changes: 12 additions & 0 deletions src/ctapipe/io/tests/test_simteleventsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,15 @@ def test_shower_distribution(prod5_gamma_simtel_path):
assert len(distributions) == 1
distribution = distributions[source.obs_id]
assert distribution.n_entries == 1000


def test_provenance(provenance, prod5_gamma_simtel_path):
provenance.start_activity("test_simteleventsource")

with SimTelEventSource(prod5_gamma_simtel_path):
pass

Check warning on line 650 in src/ctapipe/io/tests/test_simteleventsource.py

View check run for this annotation

CTAO-DPPS-SonarQube / ctapipe Sonarqube Results

src/ctapipe/io/tests/test_simteleventsource.py#L650

Either remove or fill this block of code.

inputs = provenance.current_activity.input
assert len(inputs) == 1
assert inputs[0]["url"] == str(prod5_gamma_simtel_path)
assert inputs[0]["reference_meta"] is None

0 comments on commit 4c2aafe

Please sign in to comment.