1
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
3
# MAUS is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# MAUS is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
16
"""Tests for MapCppEMRPlaneHits"""
21
from Configuration import Configuration
24
class TestMapCppEMRPlaneHits(unittest.TestCase): #pylint: disable=R0904
25
"""Tests for MapCppEMRPlaneHits"""
27
def setUpClass(cls): # pylint: disable = C0103
28
"""Sets a mapper and configuration"""
29
cls.mapper = MAUS.MapCppEMRPlaneHits()
30
cls.c = Configuration()
33
"""Check can handle empty configuration"""
34
result = self.mapper.birth("")
35
self.assertFalse(result)
36
result = self.mapper.process("")
37
doc = json.loads(result)
38
self.assertTrue("errors" in doc)
39
self.assertTrue("bad_json_document" in doc["errors"] or
40
"no_channel_map" in doc["errors"])
43
"""Check birth with default configuration"""
44
success = self.mapper.birth(self. c.getConfigJSON())
45
self.assertTrue(success)
47
def test_no_data(self):
48
"""Check that nothing happens in absence of data"""
49
test1 = ('%s/src/map/MapCppEMRPlaneHits/noDataTest.json' %
50
os.environ.get("MAUS_ROOT_DIR"))
54
result = self.mapper.process(data)
55
spill_out = json.loads(result)
56
n_ev = len(spill_out['recon_events'])
57
#print spill_out["errors"]
58
self.assertEqual(0, n_ev)
59
self.assertFalse("bad_json_document" in spill_out["errors"])
60
self.assertFalse("bad_cpp_data" in spill_out["errors"])
62
def test_process(self):
63
"""Test MapCppEMRPlaneHits process method"""
64
test2 = ('%s/src/map/MapCppEMRPlaneHits/processTest.json' %
65
os.environ.get("MAUS_ROOT_DIR"))
68
# test with some crazy events.
69
result = self.mapper.process(data)
70
#spill_in = json.loads(data)
71
spill_out = json.loads(result)
72
#print spill_out["errors"]
73
self.assertFalse("bad_json_document" in spill_out["errors"])
74
self.assertFalse("bad_cpp_data" in spill_out["errors"])
75
n_ev = len(spill_out['recon_events'])
76
self.assertEqual(3, n_ev)
77
n_hits_0 = len(spill_out['recon_events'][0]['emr_event']\
79
self.assertEqual(1, n_hits_0)
80
n_hits_1 = len(spill_out['recon_events'][1]['emr_event']\
82
self.assertEqual(2, n_hits_1)
83
n_hits_2 = len(spill_out['recon_events'][2]['emr_event']\
85
self.assertEqual(1, n_hits_2)
87
if __name__ == "__main__":