4
from geometry.GDMLPacker import Packer
5
from geometry.GDMLPacker import Unpacker
8
class Test_Packer(unittest.TestCase):
10
self.constructor_test = None
11
testcase = os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases/testPacker/FileList.txt'
12
self.gdml_test_case = Packer(testcase)
14
def test_constructor(self):
16
this test will check the constructor raises appropriate errors.
19
self.constructor_test = Packer("geometry.not_txt")
20
self.asserttrue(False, "should have raised an exception, test_GDMLPacker::test_constructor")
25
blank_txt = os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases/testPacker/test.txt'
26
self.constructor_test = Packer(blank_txt)
27
self.assertTrue(False, "should have raised an exception, test_GDMLPacker::test_constructor")
31
def test_zipfile(self):
33
this test checks to see if the outputted zip file has been written
35
zippath = os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases/testPacker'
36
self.gdml_test_case.zipfile(path = zippath)
37
output = os.listdir(zippath)
39
if fname[-4:] == '.zip':
40
zfile = zippath + '/' + fname
41
self.assertTrue(os.path.getsize(zfile) != 0, "zipped file size is zero, test_GDMLPacker::test_zipfile")
44
self.GDML_test_case = None
46
class Test_Unpacker(unittest.TestCase):
49
self.constructor_test = None
50
zippath = os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases/testPacker'
51
output = os.listdir(zippath)
53
if fname[-4:] == '.zip':
54
zfile = zippath + '/' + fname
55
testpath = os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases'
56
self.extraction_test = Unpacker(zfile, testpath)
58
def test_constructor(self):
60
self.constructor_test = Unpacker('Geometry.not_zip', testpath)
61
self.assertTrue(False, 'Should have raised an error, Test_Unpacker::test_constructor')
66
self.constructor_test = Unpacker(testcase, 'Not_a_path')
67
self.assertTrue(False, 'Should have raised an error, Test_Unpacker::test_constructor')
71
def test_unzip_file(self):
72
self.extraction_test.unzip_file()
73
output = os.listdir(self.extraction_test.extract_path)
75
if fname != 'FileList.txt' and fname[-5:] == '.gdml':
76
fname = self.extraction_test.extract_path + '/' + fname
78
if fname != 'FileList.txt' and fname[-4:] == '.xml':
79
fname = self.extraction_test.extract_path + '/' + fname
81
if fname == 'FileList.txt':
82
fname = self.extraction_test.extract_path + '/' + fname
84
self.assertEqual(text_file, os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases/FileList.txt', 'File not unzipped, Test_Unpakcer::test_unzip_file')
85
os.remove(self.extraction_test.input_file)
88
if __name__ == '__main__':
b'\\ No newline at end of file'