|
| 1 | +import pytest |
| 2 | +from pathlib import Path |
| 3 | +import numpy as np |
| 4 | +from pint import UnitRegistry |
| 5 | + |
| 6 | +ureg = UnitRegistry() |
| 7 | + |
| 8 | +from ...runner.pipeline import Pipeline |
| 9 | +from ...dataclasses.process_step import ProcessStep |
| 10 | +from ...dataclasses.process_step_describer import ProcessStepDescriber |
| 11 | +from ...dataclasses.databundle import DataBundle |
| 12 | +from ...dataclasses.basedata import BaseData |
| 13 | +from ...io.io_sources import IoSources |
| 14 | + |
| 15 | +from ...modules.base_modules.poisson_uncertainties import PoissonUncertainties |
| 16 | + |
| 17 | +TEST_IO_SOURCES = IoSources() |
| 18 | +TEST_DATA = DataBundle() |
| 19 | + |
| 20 | +@pytest.fixture |
| 21 | +def flat_data(): |
| 22 | + data = DataBundle() |
| 23 | + data["signal"] = BaseData( |
| 24 | + ingest_units=ureg.counts, |
| 25 | + internal_units=ureg.counts, |
| 26 | + display_units=ureg.counts, |
| 27 | + signal=100 * np.ones((10, 10)), |
| 28 | + ) |
| 29 | + return data |
| 30 | + |
| 31 | + |
| 32 | +class DummyProcessStep(ProcessStep): |
| 33 | + def calculate(self, data): |
| 34 | + return {"test": 0} |
| 35 | + |
| 36 | + |
| 37 | +def test_processstep_pipeline(): |
| 38 | + "tests execution of a linear processstep pipeline (not actually doing anything)" |
| 39 | + steps = [DummyProcessStep(TEST_IO_SOURCES, step_id=i) for i in range(3)] |
| 40 | + graph = {steps[i]: {steps[i + 1]} for i in range(len(steps) - 1)} |
| 41 | + |
| 42 | + pipeline = Pipeline(graph=graph) |
| 43 | + pipeline.prepare() |
| 44 | + sequence = [] |
| 45 | + while pipeline.is_active(): |
| 46 | + for node in pipeline.get_ready(): |
| 47 | + sequence.append(node) |
| 48 | + node.execute(data=TEST_DATA) |
| 49 | + pipeline.done(node) |
| 50 | + assert pipeline._nfinished == len(steps) |
| 51 | + |
| 52 | + |
| 53 | +def test_actual_processstep(flat_data): |
| 54 | + "test running the PoissonUncertainties Process step" |
| 55 | + graph = {PoissonUncertainties(TEST_IO_SOURCES): {}} |
| 56 | + |
| 57 | + pipeline = Pipeline(graph=graph) |
| 58 | + pipeline.prepare() |
| 59 | + while pipeline.is_active(): |
| 60 | + for node in pipeline.get_ready(): |
| 61 | + node.execute(data=flat_data) |
| 62 | + pipeline.done(node) |
| 63 | + assert node.produced_outputs["signal"].variances["Poisson"].mean().astype(int) == 100 |
0 commit comments