4
# This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
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.
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.
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/>.
22
from geometry.GDMLtoMAUSModule import GDMLtomaus
24
class TestGDMLToMausModule(unittest.TestCase):#pylint:disable = C0103,R0904
26
class TestGDMLToMausModule
28
This class tests GDMLtoMAUSModule
29
to ensure it is working correctly.
31
def setUp(self): #pylint: disable = C0103
33
TestGDMLToMausModule::setUp
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.
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_' + \
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)
57
def test_constructor(self):
59
TestGDMLToMausModule::test_constructor
61
This method tests the constructor
62
by passing invalid arguments and seeing
63
if errors are raised as they should be.
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')
79
def test_convert_to_maus(self):
81
TestGDMLToMausModule::test_convert_to_maus
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.
88
self.test_conversion.convert_to_maus(self.testcase)
89
outputs = os.listdir(self.testcase)
93
if fname == 'ParentGeometryFile.dat':
95
if fname.find('Step') >= 0:
97
self.assertTrue(config_mm, 'Configuration File not converted')
98
self.assertEqual(step_files, 6, 'Step Files not converted')
100
for num in range(0, length):
101
path = self.testcase + '/' + outputs[num]
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
109
if __name__ == '__main__':