~durga/maus/rel709

« back to all changes in this revision

Viewing changes to src/reduce/ReducePyTofCalib/test_ReducePyTofCalib.py

  • Committer: Durga Rajaram
  • Date: 2013-10-01 00:19:57 UTC
  • mfrom: (659.1.74 rc)
  • Revision ID: durga@fnal.gov-20131001001957-iswih60vis9rodw0
Tags: MAUS-v0.7.1
MAUS-v0.7.1

Show diffs side-by-side

added added

removed removed

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