Skip to content

Commit

Permalink
Add version checks to compare documentation and plugin code
Browse files Browse the repository at this point in the history
  • Loading branch information
HenningSE committed Feb 9, 2024
1 parent adf34d4 commit a804814
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/source/plugins/detector_physics/ElectronDrift.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Technical Details
depends_on = ("microphysics_summary")
provides = "drifted_electrons"
data_kind = "interactions_in_roi"
__version__ = "0.1.5"
Provided Columns
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Technical Details
depends_on = ("microphysics_summary", "drifted_electrons")
provides = "extracted_electrons"
data_kind = "interactions_in_roi"
__version__ = "0.1.3"
Provided Columns
================
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/detector_physics/ElectronTiming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Technical Details
depends_on = ("drifted_electrons", "extracted_electrons")
provides = "electron_time"
data_kind = "individual_electrons"
__version__ = "0.1.1"
Provided Columns
================
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/detector_physics/S1PhotonHits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Technical Details
depends_on = ("microphysics_summary")
provides = "s1_photons"
data_kind = "interactions_in_roi"
__version__ = "0.1.3"
Provided Columns
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Technical Details
depends_on = ("s1_photons", "microphysics_summary")
provides = "propagated_s1_photons"
data_kind = "S1_photons"
__version__ = "0.1.0"
Provided Columns
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Technical Details
depends_on = ("electron_time","s2_photons", "extracted_electrons", "drifted_electrons", "s2_photons_sum")
provides = "propagated_s2_photons"
data_kind = "S2_photons"
__version__ = "0.1.0"
Provided Columns
================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Technical Details
data_kind = {"s2_photons": "individual_electrons",
"s2_photons_sum" : "interactions_in_roi"
}
__version__ = "0.1.3"
Provided Columns
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/ChunkInput.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Technical Details
depends_on = ()
provides = "geant4_interactions"
data_kind = "geant4_interactions"
__version__ = "0.1.2"
Provided Columns
================
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/ElectricField.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Technical Details
depends_on = ("interactions_in_roi")
provides = "electric_field_values"
data_kind = "interactions_in_roi"
__version__ = "0.1.0"
Provided Columns
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/FindCluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Technical Details
depends_on = ("geant4_interactions")
provides = "cluster_index"
data_kind = "geant4_interactions"
__version__ = "0.1.2"
Provided Columns
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/MergeCluster.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Technical Details
depends_on = ("geant4_interactions", "cluster_index")
provides = "clustered_interactions"
data_kind = "clustered_interactions"
__version__ = "0.1.1"
Provided Columns
================
Expand Down
3 changes: 2 additions & 1 deletion docs/source/plugins/micro_physics/MicrophysicsSummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Technical Details
.. code-block:: python
depends_on = ("interactions_in_roi", "quanta", "electric_field_values")
provides = "microphysics_summary"
provides = "microphysics_summary"
__version__ = "0.1.0"
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/NestYields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Technical Details
depends_on = ("interactions_in_roi", "electric_field_values")
provides = "quanta"
data_kind = "interactions_in_roi"
__version__ = "0.1.2"
Provided Columns
Expand Down
3 changes: 2 additions & 1 deletion docs/source/plugins/micro_physics/VolumesMerger.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Technical Details
depends_on = ("tpc_interactions", "below_cathode_interactions")
provides = "interactions_in_roi"
data_kind = "interactions_in_roi"
data_kind = "interactions_in_roi"
__version__ = "0.1.0"
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/XENONnT_BelowCathode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Technical Details
depends_on = ("clustered_interactions")
provides = "below_cathode_interactions"
data_kind = "below_cathode_interactions"
__version__ = "0.1.1"
Provided Columns
================
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/micro_physics/XENONnT_TPC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Technical Details
depends_on = ("clustered_interactions")
provides = "tpc_interactions"
data_kind = "tpc_interactions"
__version__ = "0.1.1"
Provided Columns
================
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/pmt_and_daq/PMTAfterPulses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Technical Details
depends_on = ("propagated_s2_photons", "propagated_s1_photons")
provides = "pmt_afterpulses"
data_kind = "AP_photons"
__version__ = "0.1.2"
Provided Columns
================
Expand Down
1 change: 1 addition & 0 deletions docs/source/plugins/pmt_and_daq/PMTResponseAndDAQ.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Technical Details
depends_on = ("photon_summary", "pulse_ids", "pulse_windows")
provides = "raw_records"
data_kind = "raw_records"
__version__ = "0.1.3"
Provided Columns
================
Expand Down
3 changes: 2 additions & 1 deletion docs/source/plugins/pmt_and_daq/PhotonSummary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Technical Details
depends_on = ("propagated_s2_photons", "propagated_s1_photons", "pmt_afterpulses")
provides = "photon_summary"
data_kind = "propagated_photons"
data_kind = "propagated_photons"
__version__ = "0.1.0"
1 change: 1 addition & 0 deletions docs/source/plugins/pmt_and_daq/PulseWindow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Technical Details
data_kind = {"pulse_windows": "pulse_windows",
"pulse_ids" : "propagated_photons"
}
__version__ = "0.1.2"
Provided Columns
================
Expand Down
2 changes: 1 addition & 1 deletion fuse/plugins/detector_physics/s1_photon_hits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class S1PhotonHits(FuseBasePlugin):
"""Plugin to simulate the number of detected S1 photons using
a S1 light collection efficiency map."""

__version__ = '0.1.3'
__version__ = "0.1.3"

depends_on = ("microphysics_summary")
provides = "s1_photons"
Expand Down
2 changes: 1 addition & 1 deletion fuse/plugins/micro_physics/microphysics_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class MicroPhysicsSummary(strax.MergeOnlyPlugin):
]
save_when = strax.SaveWhen.ALWAYS
provides = 'microphysics_summary'
__version__ = '0.1.0'
__version__ = "0.1.0"
2 changes: 1 addition & 1 deletion fuse/plugins/pmt_and_daq/photon_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ class PhotonSummary(VerticalMergerPlugin):

provides = 'photon_summary'
data_kind = 'propagated_photons'
__version__ = '0.1.0'
__version__ = "0.1.0"
104 changes: 104 additions & 0 deletions tests/test_plugin_versions_in_doc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import os
import unittest
import tempfile
import timeout_decorator
import fuse

TIMEOUT = 240

def read_version_from_documentation(plugin_name, path_to_micrphysics_doc):

doc_version = None

with open(f'{path_to_micrphysics_doc}/{plugin_name}.rst', 'r') as file:
for line in file:
if '__version__' in line:
doc_version = line.split('=')[1].strip('"\n ').lstrip()
break

if not doc_version:
raise ValueError(f"Could not find version for plugin {plugin_name} in the documentation!")

return doc_version

microphysics_name_dict = {
'ChunkInput': 'geant4_interactions',
'FindCluster': 'cluster_index',
'MergeCluster': 'clustered_interactions',
'ElectricField': 'electric_field_values',
'VolumesMerger': 'interactions_in_roi',
'XENONnT_TPC': 'tpc_interactions',
'XENONnT_BelowCathode': 'below_cathode_interactions',
'MicroPhysicsSummary': 'microphysics_summary',
'NestYields': 'quanta',
}

detector_physics_name_dict = {
"ElectronDrift": "drifted_electrons",
"ElectronExtraction": "extracted_electrons",
"ElectronTiming": "electron_time",
"SecondaryScintillation": "s2_photons",
"S1PhotonHits": "s1_photons",
"S2PhotonPropagation": "propagated_s2_photons",
"S1PhotonPropagation": "propagated_s1_photons",
}

pmt_and_daq_name_dict = {
"PulseWindow": "pulse_windows",
"PhotonSummary": "photon_summary",
"PMTAfterPulses": "pmt_afterpulses",
"PMTResponseAndDAQ": "raw_records",
}


class TestPluginVersionsInDocumentation(unittest.TestCase):
"""Test clas to check if the plugin version in the documentation are the same as the in the code"""

@classmethod
def setUpClass(cls):

cls.temp_dir = tempfile.TemporaryDirectory()

test_context = fuse.context.full_chain_context(output_folder = cls.temp_dir.name)
cls.plugin_registry = test_context._plugin_class_registry

cls.this_dir = os.path.dirname(os.path.realpath(__file__))

@timeout_decorator.timeout(TIMEOUT, exception_message='Microphysics version tests timed out')
def test_microphysics_versions(self):
for plugin_name, plugin_provides in microphysics_name_dict.items():

plugin_version = self.plugin_registry[plugin_provides].__version__

path_to_micrphysics_doc = os.path.join(self.this_dir, "..", "docs", "source", "plugins", "micro_physics")
doc_version = read_version_from_documentation(plugin_name, path_to_micrphysics_doc)

self.assertEqual(plugin_version, doc_version,
msg=f"Plugin {plugin_name} version in the documentation is {doc_version} and in the code is \
{plugin_version}! Remember to update the documentation!")

@timeout_decorator.timeout(TIMEOUT, exception_message='Detector physics version tests timed out')
def test_detector_physics_versions(self):
for plugin_name, plugin_provides in detector_physics_name_dict.items():

plugin_version = self.plugin_registry[plugin_provides].__version__

path_to_detector_physics_doc = os.path.join(self.this_dir, "..", "docs", "source", "plugins", "detector_physics")
doc_version = read_version_from_documentation(plugin_name, path_to_detector_physics_doc)

self.assertEqual(plugin_version, doc_version,
msg=f"Plugin {plugin_name} version in the documentation is {doc_version} and in the code is \
{plugin_version}! Remember to update the documentation!")

@timeout_decorator.timeout(TIMEOUT, exception_message='PMT response version tests timed out')
def test_pmt_response_versions(self):
for plugin_name, plugin_provides in pmt_and_daq_name_dict.items():

plugin_version = self.plugin_registry[plugin_provides].__version__

path_to_pmt_response_doc = os.path.join(self.this_dir, "..", "docs", "source", "plugins", "pmt_and_daq")
doc_version = read_version_from_documentation(plugin_name, path_to_pmt_response_doc)

self.assertEqual(plugin_version, doc_version,
msg=f"Plugin {plugin_name} version in the documentation is {doc_version} and in the code is \
{plugin_version}! Remember to update the documentation!")

0 comments on commit a804814

Please sign in to comment.