libtest.py 2.81 KB
Newer Older
1
2
3
4
5
6
#!/usr/bin/python

'''
    Unit test for the library
'''

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

jvoisin's avatar
jvoisin committed
13

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

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


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

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


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

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

jvoisin's avatar
jvoisin committed
68

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

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

jvoisin's avatar
jvoisin committed
79
80

def main():
jvoisin's avatar
jvoisin committed
81
82
83
84
    Suite = unittest.TestSuite()
    Suite.addTest(unittest.makeSuite(TestRemovelib))
    Suite.addTest(unittest.makeSuite(TestListlib))
    Suite.addTest(unittest.makeSuite(TestisCleanlib))
jvoisin's avatar
jvoisin committed
85
    Suite.addTest(unittest.makeSuite(TestFileAttributes))
jvoisin's avatar
jvoisin committed
86
    test_result = unittest.TextTestRunner(verbosity=test.VERBOSITY).run(Suite)
jvoisin's avatar
jvoisin committed
87
    return len(test_result.failures)
88

jvoisin's avatar
jvoisin committed
89
90
91

if __name__ == '__main__':
    sys.exit(main())