~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppKLDigits/test_MapCppKLDigits.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:
18
18
# pylint: disable = C0103
19
19
 
20
20
import os
21
 
import json
22
21
import unittest
23
22
from Configuration import Configuration
 
23
import maus_cpp.converter
24
24
import MAUS
25
25
 
26
26
class MapCppKLDigitsTestCase(unittest.TestCase): # pylint: disable = R0904
33
33
 
34
34
    def test_empty(self):
35
35
        """Check can handle empty configuration"""
36
 
        result = self.mapper.birth("")
37
 
        self.assertFalse(result)
 
36
        self.assertRaises(ValueError, self.mapper.birth, "")
38
37
        result = self.mapper.process("")
39
 
        doc = json.loads(result)
 
38
        doc = maus_cpp.converter.json_repr(result)
40
39
        self.assertTrue("errors" in doc)
41
 
        self.assertTrue("bad_json_document" in doc["errors"])
 
40
        self.assertTrue("MapCppKLDigits" in doc["errors"])
42
41
 
43
42
    def test_init(self):
44
43
        """Check birth with default configuration"""
45
 
        success = self.mapper.birth(self. c.getConfigJSON())
46
 
        self.assertTrue(success)
 
44
        self.mapper.birth(self. c.getConfigJSON())
47
45
 
48
46
    def test_no_data(self):
49
47
        """Check that nothing happens in absence of data"""
53
51
        data = fin.read()
54
52
        # test with no data.
55
53
        result = self.mapper.process(data)
56
 
        spill_out = json.loads(result)
 
54
        spill_out = maus_cpp.converter.json_repr(result)
57
55
        self.assertFalse('digits' in spill_out)
58
56
 
59
57
    def __test_process_kl_digits(self, spill_in, spill_out):
84
82
        data = fin.read()
85
83
        # test with some crazy events.
86
84
        result = self.mapper.process(data)
87
 
        spill_in = json.loads(data)
88
 
        spill_out = json.loads(result)
 
85
        spill_in = maus_cpp.converter.json_repr(data)
 
86
        spill_out = maus_cpp.converter.json_repr(result)
89
87
 
90
88
        # test the outputs
91
89
        self.__test_process_kl_digits(spill_in, spill_out)
93
91
    @classmethod
94
92
    def tearDownClass(cls): # pylint: disable = C0103
95
93
        """Check that we can death() MapCppKLDigits"""
96
 
        success = cls.mapper.death()
97
 
        if not success:
98
 
            raise Exception('InitializeFail', 'Could not start worker')
99
 
        cls.mapper = None
 
94
        cls.mapper.death()
100
95
 
101
96
if __name__ == '__main__':
102
97
    unittest.main()