16
16
"""Tests for MapCppGlobalReconImport"""
18
18
# pylint: disable = C0103
19
# pylint: disable = W0611
23
24
from Configuration import Configuration
25
import maus_cpp.converter
26
from _MapCppGlobalReconImport import MapCppGlobalReconImport
26
class MapCppGlobalReconImport(unittest.TestCase): # pylint: disable = R0904
28
class MapCppGlobalImportTestCase(unittest.TestCase): # pylint: disable = R0904
27
29
"""Tests for MapCppGlobalReconImport"""
29
31
def setUpClass(cls): # pylint: disable = C0103
30
32
"""Sets a mapper and configuration"""
31
cls.mapper = MAUS.MapCppGlobalReconImport()
33
cls.mapper = MapCppGlobalReconImport()
32
34
cls.c = Configuration()
34
36
def test_empty(self):
35
37
"""Check can handle empty configuration"""
36
result = self.mapper.birth("")
37
self.assertFalse(result)
38
self.assertRaises(ValueError, self.mapper.birth, "",)
38
39
result = self.mapper.process("")
39
doc = json.loads(result)
40
doc = maus_cpp.converter.json_repr(result)
40
41
self.assertTrue("errors" in doc)
41
self.assertTrue("bad_json_document" in doc["errors"])
42
self.assertTrue("MapCppGlobalReconImport" in doc["errors"])
43
44
def test_init(self):
44
45
"""Check birth with default configuration"""
45
success = self.mapper.birth(self. c.getConfigJSON())
46
self.assertTrue(success)
46
self.mapper.birth(self. c.getConfigJSON())
48
48
def test_no_data(self):
49
49
"""Check that nothing happens in absence of data"""
50
50
test1 = ('%s/src/map/MapCppGlobalReconImport/noDataTest.txt' %
52
52
fin = open(test1,'r')
54
54
# test with no data.
55
self.mapper.birth(self.c.getConfigJSON())
55
56
result = self.mapper.process(data)
56
spill_out = json.loads(result)
57
spill_out = maus_cpp.converter.json_repr(result)
57
58
self.assertFalse('global_event' in spill_out)
59
60
def test_invalid_json_birth(self):
62
63
os.environ.get("MAUS_ROOT_DIR"))
63
64
fin1 = open(test2,'r')
66
result = self.mapper.birth(data)
67
self.assertFalse(result)
66
self.assertRaises(ValueError, self.mapper.birth, data)
68
67
test3 = ('%s/src/map/MapCppGlobalReconImport/Global_Import_test.json' %
69
68
os.environ.get("MAUS_ROOT_DIR"))
70
69
fin2 = open(test3,'r')
74
73
line = fin2.readline()
75
74
result = self.mapper.process(line)
76
doc = json.loads(result)
77
self.assertTrue("errors" in doc)
78
self.assertTrue("bad_json_document" in doc["errors"])
75
doc = maus_cpp.converter.json_repr(result)
76
self.assertTrue("MapCppGlobalReconImport" in doc["errors"])
80
78
def test_invalid_json_process(self):
81
79
"""Check process with an invalid json input"""
82
birthresult = self.mapper.birth(self. c.getConfigJSON())
83
self.assertTrue(birthresult)
80
self.mapper.birth(self. c.getConfigJSON())
84
81
test4 = ('%s/src/map/MapCppGlobalReconImport/invalid.json' %
85
82
os.environ.get("MAUS_ROOT_DIR"))
86
83
fin = open(test4,'r')
88
85
result = self.mapper.process(data)
89
doc = json.loads(result)
90
self.assertTrue("errors" in doc)
91
self.assertTrue("bad_json_document" in doc["errors"])
86
doc = maus_cpp.converter.json_repr(result)
87
self.assertTrue("MapCppGlobalReconImport" in doc["errors"])
94
89
def test_fill_Global_Event(self):
95
"""Check that process fills global events from TOF data"""
90
"""Check that process fills global events from TOF and scifi data"""
96
91
test5 = ('%s/src/map/MapCppGlobalReconImport/global_import_test.json' %
97
92
os.environ.get("MAUS_ROOT_DIR"))
98
birthresult = self.mapper.birth(self. c.getConfigJSON())
99
self.assertTrue(birthresult)
93
self.mapper.birth(self.c.getConfigJSON())
100
94
fin = open(test5,'r')
102
96
result = self.mapper.process(line)
103
spill_out = json.loads(result)
97
spill_out = maus_cpp.converter.json_repr(result)
104
98
self.assertTrue('recon_events' in spill_out)
105
99
revtarray = spill_out['recon_events']
106
100
self.assertEqual(1, len(revtarray))
117
111
self.assertTrue('mapper_name' in i)
118
112
self.assertEqual(i['mapper_name'],'MapCppGlobalReconImport')
119
113
self.assertTrue('space_points' in revt['global_event'])
120
self.assertEqual(33, len(revt['global_event']['space_points']))
114
self.assertEqual(34, len(revt['global_event']['space_points']))
121
115
self.assertTrue('primary_chains' in revt['global_event'])
122
116
self.assertEqual(0, len(revt['global_event']['primary_chains']))
125
119
def tearDownClass(cls): # pylint: disable = C0103
126
120
"""Check that we can death() MapCppGlobalReconImport"""
127
success = cls.mapper.death()
129
raise Exception('InitializeFail', 'Could not start worker')
132
123
if __name__ == '__main__':