libtest.py 2.83 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:
22
            current_file = mat.create_class_file(dirty, False, True)
23
            current_file.remove_all()
jvoisin's avatar
Bugfix  
jvoisin committed
24
25
            current_file2 = mat.create_class_file(dirty, False, True)
            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:
30
            current_file = mat.create_class_file(clean, False, 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:
42
            current_file = mat.create_class_file(dirty, False, 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:
49
            current_file = mat.create_class_file(clean, False, 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:
60
            current_file = mat.create_class_file(dirty, False, 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:
66
            current_file = mat.create_class_file(clean, False, 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
75
76
77
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
78
        self.assertFalse(mat.create_class_file('ilikecookies', False, True))
79

jvoisin's avatar
jvoisin committed
80
81

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

jvoisin's avatar
jvoisin committed
90
91
92

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