Coverage for tests/test_hist_median.py: 41%
28 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-11 04:37 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-11 04:37 -0700
1# This file is part of faro.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Unit tests for the metrics measurement system.
23"""
25import unittest
26import numpy as np
27import astropy.units as u
29from lsst.faro.measurement import HistMedianTask
30from lsst.pex.config import Config
33class MockMeas:
34 def __init__(self, extras):
35 self.extras = extras
38class MockExtra:
39 def __init__(self, quantity):
40 self.quantity = quantity
43class HistMedianTest(unittest.TestCase):
45 def test_hist_mode(self):
46 """Test the aggregator that takes the mode of a histogram."""
47 task = HistMedianTask(config=Config())
48 values = np.array([0, 2, 4, 6, 8, 10, 14, 12, 16, 12, 8, 4, 0])*u.count
49 bins = np.array([(i+1)*0.3 for i in range(len(values)+1)])*u.m
50 expected = 2.5*u.m
51 mock_meas_arr = []
52 for i in range(37):
53 extras = {}
54 extras['values'] = MockExtra(values*np.random.randint(1, 29))
55 extras['bins'] = MockExtra(bins)
56 mock_meas_arr.append(MockMeas(extras))
57 result = task.run(mock_meas_arr, 'test', 'info', 'mock')
58 self.assertEqual(expected, result.measurement.quantity)
61if __name__ == "__main__": 61 ↛ 62line 61 didn't jump to line 62, because the condition on line 61 was never true
62 unittest.main()