~christopher-hunt08/maus/maus_integrated_kalman

« back to all changes in this revision

Viewing changes to tests/py_unit/test_geometry/test_GDMLPacker.py

moved the tests around and added an __init__ as there was an import error in the build

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import os.path
 
3
import unittest
 
4
from geometry.GDMLPacker import Packer
 
5
from geometry.GDMLPacker import Unpacker
 
6
 
 
7
 
 
8
class  Test_Packer(unittest.TestCase):
 
9
    def setUp(self):
 
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)
 
13
    
 
14
    def test_constructor(self):
 
15
        """
 
16
        this test will check the constructor raises appropriate errors.
 
17
        """
 
18
        try:
 
19
            self.constructor_test = Packer("geometry.not_txt")
 
20
            self.asserttrue(False, "should have raised an exception, test_GDMLPacker::test_constructor")
 
21
        except:
 
22
            pass
 
23
 
 
24
        try:
 
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")
 
28
        except:
 
29
            pass
 
30
 
 
31
    def test_zipfile(self):
 
32
        """
 
33
        this test checks to see if the outputted zip file has been written
 
34
        """
 
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)
 
38
        for fname in output:
 
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")
 
42
 
 
43
    def tearDown(self):
 
44
        self.GDML_test_case = None
 
45
        
 
46
class Test_Unpacker(unittest.TestCase):
 
47
    
 
48
    def setUp(self):
 
49
        self.constructor_test = None
 
50
        zippath = os.environ['MAUS_ROOT_DIR'] + '/src/common_py/geometry/testCases/testPacker'
 
51
        output = os.listdir(zippath)
 
52
        for fname in output:
 
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)
 
57
        
 
58
    def test_constructor(self):
 
59
        try:
 
60
            self.constructor_test = Unpacker('Geometry.not_zip', testpath)
 
61
            self.assertTrue(False, 'Should have raised an error, Test_Unpacker::test_constructor')
 
62
        except:
 
63
            pass
 
64
        
 
65
        try: 
 
66
            self.constructor_test = Unpacker(testcase, 'Not_a_path')
 
67
            self.assertTrue(False, 'Should have raised an error, Test_Unpacker::test_constructor')
 
68
        except:
 
69
            pass
 
70
        
 
71
    def test_unzip_file(self):
 
72
        self.extraction_test.unzip_file()
 
73
        output = os.listdir(self.extraction_test.extract_path)
 
74
        for fname in output:
 
75
            if fname != 'FileList.txt' and fname[-5:] == '.gdml':
 
76
                fname = self.extraction_test.extract_path + '/' + fname
 
77
                os.remove(fname)
 
78
            if fname != 'FileList.txt' and fname[-4:] == '.xml':
 
79
                fname = self.extraction_test.extract_path + '/' + fname
 
80
                os.remove(fname)
 
81
            if fname == 'FileList.txt':
 
82
                fname = self.extraction_test.extract_path + '/' + fname
 
83
                text_file = 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)
 
86
        os.remove(text_file)         
 
87
 
 
88
if __name__ == '__main__':
 
89
    unittest.main()
 
 
b'\\ No newline at end of file'