~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppGlobalReconImport/test_MapCppGlobalReconImport.py

  • Committer: Durga Rajaram
  • Date: 2014-07-16 15:13:05 UTC
  • mfrom: (659.1.92 cand)
  • Revision ID: durga@fnal.gov-20140716151305-q27rv1y9p03v9lks
Tags: MAUS-v0.9, MAUS-v0.9.0
MAUS-v0.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
"""Tests for MapCppGlobalReconImport"""
17
17
 
18
18
# pylint: disable = C0103
 
19
# pylint: disable = W0611
19
20
 
20
21
import os
21
22
import json
22
23
import unittest
23
24
from Configuration import Configuration
24
 
import MAUS
 
25
import maus_cpp.converter
 
26
from _MapCppGlobalReconImport import MapCppGlobalReconImport
25
27
 
26
 
class MapCppGlobalReconImport(unittest.TestCase): # pylint: disable = R0904
 
28
class MapCppGlobalImportTestCase(unittest.TestCase): # pylint: disable = R0904
27
29
    """Tests for MapCppGlobalReconImport"""
28
30
    @classmethod
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()
33
 
    
 
35
 
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"])
42
43
 
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)
47
 
    
 
46
        self.mapper.birth(self. c.getConfigJSON())
 
47
 
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')
53
53
        data = fin.read()
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)
58
59
 
59
60
    def test_invalid_json_birth(self):
62
63
                 os.environ.get("MAUS_ROOT_DIR"))
63
64
        fin1 = open(test2,'r')
64
65
        data = fin1.read()
65
 
        # test with no data.
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')
73
72
        fin2.readline()
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"])
79
77
 
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')
87
84
        data = fin.read()
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"])
92
88
 
93
 
   
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')
101
95
        line = fin.read()
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']))
123
117
 
124
118
    @classmethod
125
119
    def tearDownClass(cls): # pylint: disable = C0103
126
120
        """Check that we can death() MapCppGlobalReconImport"""
127
 
        success = cls.mapper.death()
128
 
        if not success:
129
 
            raise Exception('InitializeFail', 'Could not start worker')
130
 
        cls.mapper = None
 
121
        cls.mapper.death()
131
122
 
132
123
if __name__ == '__main__':
133
124
    unittest.main()