1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!/usr/bin/python
'''
Unit test for the library
'''
import unittest
import test
import sys
sys.path.append('..')
from lib import mat
class TestRemovelib(test.MATTest):
'''
test the remove_all() method
'''
def test_remove(self):
'''make sure that the lib remove all compromizing meta'''
for _, dirty in self.file_list:
current_file = mat.create_class_file(dirty, False, True)
current_file.remove_all()
current_file2 = mat.create_class_file(dirty, False, True)
self.assertTrue(current_file2.is_clean())
def test_remove_empty(self):
'''Test removal with clean files'''
for clean, _ in self.file_list:
current_file = mat.create_class_file(clean, False, True)
current_file.remove_all()
self.assertTrue(current_file.is_clean())
class TestListlib(test.MATTest):
'''
test the get_meta() method
'''
def test_list(self):
'''check if get_meta returns all the expected meta'''
for _, dirty in self.file_list:
current_file = mat.create_class_file(dirty, False, True)
#FIXME assertisNotNone() : python 2.7
self.assertTrue(current_file.get_meta())
def testlist_list_empty(self):
'''check that a listing of a clean file return an empty dict'''
for clean, _ in self.file_list:
current_file = mat.create_class_file(clean, False, True)
self.assertEqual(current_file.get_meta(), dict())
class TestisCleanlib(test.MATTest):
'''
test the is_clean() method
'''
def test_dirty(self):
'''test is_clean on clean files'''
for _, dirty in self.file_list:
current_file = mat.create_class_file(dirty, False, True)
self.assertFalse(current_file.is_clean())
def test_clean(self):
'''test is_clean on dirty files'''
for clean, _ in self.file_list:
current_file = mat.create_class_file(clean, False, True)
self.assertTrue(current_file.is_clean())
class TestFileAttributes(unittest.TestCase):
'''
test various stuffs about files (readable, writable, exist, ...)
'''
def test_not_readable(self):
self.assertFalse(mat.create_class_file('not_readable', False, True))
def test_not_writtable(self):
self.assertFalse(mat.create_class_file('not_writtable', False, True))
def test_not_exist(self):
self.assertFalse(mat.create_class_file('ilikecookies', False, True))
def main():
Suite = unittest.TestSuite()
Suite.addTest(unittest.makeSuite(TestRemovelib))
Suite.addTest(unittest.makeSuite(TestListlib))
Suite.addTest(unittest.makeSuite(TestisCleanlib))
Suite.addTest(unittest.makeSuite(TestFileAttributes))
test_result = unittest.TextTestRunner(verbosity=test.VERBOSITY).run(Suite)
return len(test_result.failures)
if __name__ == '__main__':
sys.exit(main())
|