libtest.py 3.12 KB
Newer Older
jvoisin's avatar
jvoisin committed
1
2
#!/usr/bin/env python
# -*- coding: utf-8 -*
3
4
5
6
7

'''
    Unit test for the library
'''

8
9
import unittest
import test
jvoisin's avatar
jvoisin committed
10
11
import sys
sys.path.append('..')
12
from MAT import mat
13

jvoisin's avatar
jvoisin committed
14

jvoisin's avatar
jvoisin committed
15
16
17
18
class TestRemovelib(test.MATTest):
    '''
        test the remove_all() method
    '''
19
20
    def test_remove(self):
        '''make sure that the lib remove all compromizing meta'''
jvoisin's avatar
jvoisin committed
21
        for _, dirty in self.file_list:
jvoisin's avatar
jvoisin committed
22
            current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
23
            current_file.remove_all()
jvoisin's avatar
jvoisin committed
24
            current_file2 = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
jvoisin's avatar
Bugfix  
jvoisin committed
25
            self.assertTrue(current_file2.is_clean())
26
27
28

    def test_remove_empty(self):
        '''Test removal with clean files'''
jvoisin's avatar
jvoisin committed
29
        for clean, _ in self.file_list:
jvoisin's avatar
jvoisin committed
30
            current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
31
32
33
34
            current_file.remove_all()
            self.assertTrue(current_file.is_clean())


jvoisin's avatar
jvoisin committed
35
36
37
38
class TestListlib(test.MATTest):
    '''
        test the get_meta() method
    '''
39
40
    def test_list(self):
        '''check if get_meta returns all the expected meta'''
jvoisin's avatar
jvoisin committed
41
        for _, dirty in self.file_list:
jvoisin's avatar
jvoisin committed
42
            current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
jvoisin's avatar
jvoisin committed
43
44
            #FIXME assertisNotNone() : python 2.7
            self.assertTrue(current_file.get_meta())
45
46
47

    def testlist_list_empty(self):
        '''check that a listing of a clean file return an empty dict'''
jvoisin's avatar
jvoisin committed
48
        for clean, _ in self.file_list:
jvoisin's avatar
jvoisin committed
49
            current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
jvoisin's avatar
jvoisin committed
50
            self.assertEqual(current_file.get_meta(), dict())
51
52


jvoisin's avatar
jvoisin committed
53
54
55
56
class TestisCleanlib(test.MATTest):
    '''
        test the is_clean() method
    '''
57
    def test_dirty(self):
58
        '''test is_clean on clean files'''
jvoisin's avatar
jvoisin committed
59
        for _, dirty in self.file_list:
jvoisin's avatar
jvoisin committed
60
            current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True)
jvoisin's avatar
jvoisin committed
61
            self.assertFalse(current_file.is_clean())
62
63
64

    def test_clean(self):
        '''test is_clean on dirty files'''
jvoisin's avatar
jvoisin committed
65
        for clean, _ in self.file_list:
jvoisin's avatar
jvoisin committed
66
            current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True)
jvoisin's avatar
jvoisin committed
67
            self.assertTrue(current_file.is_clean())
68

jvoisin's avatar
jvoisin committed
69

jvoisin's avatar
jvoisin committed
70
71
72
73
74
class TestFileAttributes(unittest.TestCase):
    '''
        test various stuffs about files (readable, writable, exist, ...)
    '''
    def test_not_writtable(self):
jvoisin's avatar
jvoisin committed
75
        self.assertFalse(mat.create_class_file('not_writtable', False, add2archive=True, low_pdf_quality=True))
jvoisin's avatar
jvoisin committed
76
77

    def test_not_exist(self):
jvoisin's avatar
jvoisin committed
78
        self.assertFalse(mat.create_class_file('ilikecookies', False, add2archive=True, low_pdf_quality=True))
79

jvoisin's avatar
jvoisin committed
80

81
def get_tests():
jvoisin's avatar
jvoisin committed
82
83
84
85
86
87
88
    ''' Return every libtests'''
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestRemovelib))
    suite.addTest(unittest.makeSuite(TestListlib))
    suite.addTest(unittest.makeSuite(TestisCleanlib))
    suite.addTest(unittest.makeSuite(TestFileAttributes))
    return suite
89

jvoisin's avatar
jvoisin committed
90
91

if __name__ == '__main__':
92
    unittest.TextTestRunner(verbosity=test.VERBOSITY).run(get_tests())