~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to tests/py_unit/test_geometry/test_gdml_to_maus_module.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
"""
 
2
M. Littlefield
 
3
"""
 
4
#  This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
 
5
 
6
#  MAUS is free software: you can redistribute it and/or modify
 
7
#  it under the terms of the GNU General Public License as published by
 
8
#  the Free Software Foundation, either version 3 of the License, or
 
9
#  (at your option) any later version.
 
10
 
11
#  MAUS is distributed in the hope that it will be useful,
 
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#  GNU General Public License for more details.
 
15
 
16
#  You should have received a copy of the GNU General Public License
 
17
#  along with MAUS.  If not, see <http://www.gnu.org/licenses/>.
 
18
 
 
19
import os
 
20
import unittest
 
21
import shutil
 
22
from geometry.GDMLtoMAUSModule import GDMLtomaus
 
23
 
 
24
class  TestGDMLToMausModule(unittest.TestCase):#pylint:disable = C0103,R0904
 
25
    """
 
26
    class TestGDMLToMausModule
 
27
    
 
28
    This class tests GDMLtoMAUSModule 
 
29
    to ensure it is working correctly.
 
30
    """    
 
31
    def setUp(self): #pylint: disable = C0103
 
32
        """
 
33
        TestGDMLToMausModule::setUp
 
34
        
 
35
        This method sets up a GDMLtomaus object
 
36
        ready for testing. It also has to move
 
37
        some files around because calling the methods
 
38
        from the module overwrites the original files. 
 
39
        Therefore copies of the testGeometry are made,
 
40
        tested and then removed.
 
41
        """
 
42
        test_cases_dir = os.environ['MAUS_ROOT_DIR'] + \
 
43
                                       '/tests/py_unit/test_geometry/testCases/'
 
44
        self.constructor = None
 
45
        self.file_source = os.environ['MAUS_ROOT_DIR'] + '/tmp'
 
46
        self.copy_files = GDMLtomaus(self.file_source)
 
47
        config_file = test_cases_dir+'/testGDMLtoMAUSModule/fastradModel.gdml'
 
48
        shutil.copyfile(self.copy_files.config_file, config_file)
 
49
        length = len(self.copy_files.step_files)
 
50
        for num in range (0, length):
 
51
            step_file = test_cases_dir+'/testGDMLtoMAUSModule/Step_' + \
 
52
                                                              str(num) + '.gdml'
 
53
            shutil.copyfile(self.copy_files.step_files[num], step_file)
 
54
        self.testcase = test_cases_dir+'/testGDMLtoMAUSModule'
 
55
        self.test_conversion = GDMLtomaus(self.testcase)
 
56
        
 
57
    def test_constructor(self):
 
58
        """
 
59
        TestGDMLToMausModule::test_constructor
 
60
        
 
61
        This method tests the constructor
 
62
        by passing invalid arguments and seeing
 
63
        if errors are raised as they should be.
 
64
        """
 
65
        try:
 
66
            self.constructor = GDMLtomaus('this path doesnt exist')
 
67
            self.assertTrue(False, 'should have raised and error')
 
68
        except: #pylint: disable = W0702
 
69
            pass #pylint: disable = W0702
 
70
        #This next section ensures the constructor has set
 
71
        #up the variables correctly.
 
72
        config_file = self.testcase + '/fastradModel.gdml'
 
73
        self.assertEqual(self.test_conversion.config_file, config_file, \
 
74
        'Config file wasnt found, test_GDML_to_MAUSModule::test_constructor')
 
75
        num_of_step_files = len(self.test_conversion.step_files)
 
76
        self.assertEqual(num_of_step_files, 6, \
 
77
        'Step files wasnt found, test_GDML_to_MAUSModule::test_constructor')
 
78
        
 
79
    def test_convert_to_maus(self):
 
80
        """
 
81
        TestGDMLToMausModule::test_convert_to_maus
 
82
        
 
83
        This method tests the convert_to_maus
 
84
        method which should convert the files to maus
 
85
        modules. It tests this be converting the files and
 
86
        checking the maus modules exist.
 
87
        """
 
88
        self.test_conversion.convert_to_maus(self.testcase)
 
89
        outputs = os.listdir(self.testcase)
 
90
        config_mm = False
 
91
        step_files = 0
 
92
        for fname in outputs:
 
93
            if fname == 'ParentGeometryFile.dat':
 
94
                config_mm = True
 
95
            if fname.find('Step') >= 0:
 
96
                step_files += 1
 
97
        self.assertTrue(config_mm, 'Configuration File not converted')
 
98
        self.assertEqual(step_files, 6, 'Step Files not converted')
 
99
        length = len(outputs)
 
100
        for num in range(0, length):
 
101
            path = self.testcase + '/' + outputs[num]
 
102
            os.remove(path)
 
103
        #NB: once the schema and XSLT scripts 
 
104
        #are finalised more test can be created here
 
105
        #These test can open the files  
 
106
        #and make sure the maus modules are written
 
107
        #correctly.
 
108
        
 
109
if __name__ == '__main__':
 
110
    unittest.main()
 
111