~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to src/map/MapCppKLMCDigitizer/test_MapCppKLMCDigitizer.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:
 
1
#pylint: disable = C0103
 
2
""" 
 
3
basic test of KLDigitizer to see if digits come out on real spills
 
4
and if errors come out on empty
 
5
""" 
 
6
import json
 
7
import unittest
 
8
import os
 
9
import maus_cpp.converter
 
10
import MAUS
 
11
 
 
12
from Configuration import Configuration
 
13
 
 
14
class MapCppKLMCDigitizer(unittest.TestCase):  #pylint: disable = R0904
 
15
    """ basic MapCppKLMCDigitizer test to check
 
16
    if we get digits on good evts and errors on bad
 
17
    """
 
18
    @classmethod
 
19
    def setUpClass(cls):  # pylint: disable-msg=C0103
 
20
        """ Class Initializer.
 
21
            The set up is called before each test function
 
22
            is called.
 
23
        """
 
24
        cls.mapper = MAUS.MapCppKLMCDigitizer()
 
25
        conf_json = json.loads(Configuration().getConfigJSON())
 
26
        conf_json["simulation_geometry_filename"] = "Stage6.dat"
 
27
        # Test whether the configuration files were loaded correctly at birth
 
28
        cls.mapper.birth(json.dumps(conf_json))
 
29
 
 
30
 
 
31
    def test_death(self):
 
32
        """ Test to make sure death occurs """
 
33
        self.mapper.death()
 
34
 
 
35
    def test_process(self):
 
36
        """ Test of the process function """
 
37
        root_dir = os.environ.get("MAUS_ROOT_DIR")
 
38
        assert root_dir != None
 
39
        assert os.path.isdir(root_dir)
 
40
        _filename = \
 
41
        '%s/src/map/MapCppKLMCDigitizer/mc_test.dat' % root_dir
 
42
        assert os.path.isfile(_filename)
 
43
        _file = open(_filename, 'r')
 
44
        # File is open.
 
45
        # Spill 1 is corrupted.
 
46
        spill = "{}"
 
47
        output = self.mapper.process(spill)
 
48
        self.assertTrue("errors" in maus_cpp.converter.json_repr(output))
 
49
        # a real spill
 
50
        spill = _file.readline().rstrip()
 
51
        output = self.mapper.process(spill)
 
52
        doc = maus_cpp.converter.json_repr(output)
 
53
        self.assertTrue("kl_digits" in \
 
54
                             doc["recon_events"][0]["kl_event"])
 
55
        _file.close()
 
56
 
 
57
    @classmethod
 
58
    def tear_down_class(cls):
 
59
        """___"""
 
60
        cls.mapper.death()
 
61
        cls.mapper = None
 
62
 
 
63
if __name__ == '__main__':
 
64
    unittest.main()