1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
#
# MAUS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# MAUS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MAUS. If not, see <http://www.gnu.org/licenses/>.
#
"""Tests for MapPyCkov"""
# pylint: disable = C0103
import os
import json
import unittest
from Configuration import Configuration
import MAUS
class MapPyCkovTestCase(unittest.TestCase):# pylint: disable = R0904
"""Test for MapPyCkov"""
@classmethod
def setUpClass(cls): # pylint: disable = C0103
"""Initialize a Ckov object"""
cls.mapper = MAUS.MapPyCkov()
cls.c = Configuration()
def test_empty(self):
"""Check against empty configuration"""
result = self.mapper.birth("")
self.assertFalse(result)
result = self.mapper.process("")
doc = json.loads(result)
self.assertTrue("errors" in doc)
self.assertTrue("bad_json_document" in doc["errors"])
def test_init(self):
"""Check that birth works properly"""
success = self.mapper.birth(self.c.getConfigJSON())
self.assertTrue(success)
def test_no_data(self):
"""Check that against data stream is empty"""
test1 = ('%s/src/map/MapPyCkov/noDataTest.txt'%
os.environ.get("MAUS_ROOT_DIR"))
fin = open(test1, 'r')
data = fin.read()
#test = json.dumps({"daq_data":None, "bob":0})
#test no data.
result = self.mapper.process(data)
spill = json.loads(result)
no_ckov = True
if 'ckov' in spill:
no_ckov = False
self.assertTrue(no_ckov)
def test_process(self):
"""Check MapPyCkov process function"""
test2 = ('%s/src/map/MapPyCkov/goodmap.txt' %
os.environ.get("MAUS_ROOT_DIR"))
fin = open(test2, 'r')
data = fin.read()
#test with some events.
result = self.mapper.process(data)
spill = json.loads(result)
#print 'spill= ',spill
if "digits" not in spill:
print 'no digits'
#test the ckov output
n_part_events = int(len(spill['digits']['ckov'])) - 1
#test there are no dupilcate events
last_part_event_number = \
spill['digits']['ckov'][n_part_events]['A']['part_event_number']
self.assertEqual(last_part_event_number, n_part_events)
def tearDown(self): #pylint: disable = C0103
"""Check death works"""
success = self.mapper.death()
if not success:
raise Exception('Initialize Fail', 'Could not start worker')
#self.mapper = None
if __name__ == '__main__':
unittest.main()
|