diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/__init__.py | 0 | ||||
| -rw-r--r-- | test/clean.jpg | bin | 0 -> 83261 bytes | |||
| -rwxr-xr-x | test/clitest.py | 73 | ||||
| -rw-r--r-- | test/dirty.jpg | bin | 0 -> 83261 bytes | |||
| -rwxr-xr-x | test/libtest.py | 64 | ||||
| -rwxr-xr-x | test/test.py | 31 |
6 files changed, 168 insertions, 0 deletions
diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/__init__.py | |||
diff --git a/test/clean.jpg b/test/clean.jpg new file mode 100644 index 0000000..09c9161 --- /dev/null +++ b/test/clean.jpg | |||
| Binary files differ | |||
diff --git a/test/clitest.py b/test/clitest.py new file mode 100755 index 0000000..da0563f --- /dev/null +++ b/test/clitest.py | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | ''' | ||
| 3 | Unit test for the CLI interface | ||
| 4 | ''' | ||
| 5 | |||
| 6 | import unittest | ||
| 7 | import subprocess | ||
| 8 | import sys | ||
| 9 | sys.path.append('..') | ||
| 10 | import cli | ||
| 11 | from lib import mat | ||
| 12 | import test | ||
| 13 | |||
| 14 | class Test_Remove_cli(test.MATTest): | ||
| 15 | def test_remove(self): | ||
| 16 | '''make sure that the cli remove all compromizing meta''' | ||
| 17 | for clean, dirty in self.file_list: | ||
| 18 | subprocess.call(['../cli.py', dirty]) | ||
| 19 | current_file = mat.create_class_file(dirty) | ||
| 20 | self.assertTrue(current_file.is_clean()) | ||
| 21 | |||
| 22 | def test_remove_empty(self): | ||
| 23 | '''Test removal with clean files''' | ||
| 24 | for clean, dirty in self.file_list: | ||
| 25 | subprocess.call(['../cli.py', clean]) | ||
| 26 | current_file = mat.create_class_file(clean) | ||
| 27 | self.assertTrue(current_file.is_clean()) | ||
| 28 | |||
| 29 | |||
| 30 | class Test_List_cli(test.MATTest): | ||
| 31 | def test_list_clean(self): | ||
| 32 | '''check if get_meta returns meta''' | ||
| 33 | for clean, dirty in self.file_list: | ||
| 34 | #fixme : a (clean|dirty).(jpg|pdf|...).out ? | ||
| 35 | proc = subprocess.Popen(['../cli.py', '-d', clean], | ||
| 36 | stdout=subprocess.PIPE) | ||
| 37 | stdout, stderr = proc.communicate() | ||
| 38 | self.assertEqual(stdout, "[+] File %s" % clean) | ||
| 39 | |||
| 40 | def test_list_dirty(self): | ||
| 41 | '''check if get_meta returns all the expected meta''' | ||
| 42 | for clean, dirty in self.file_list: | ||
| 43 | proc = subprocess.Popen(['../cli.py', '-d', dirty], | ||
| 44 | stdout=subprocess.PIPE) | ||
| 45 | stdout, stderr = proc.communicate() | ||
| 46 | self.assertNotEqual(stdout, "[+] File %s" % dirty) | ||
| 47 | |||
| 48 | |||
| 49 | class Test_isClean_cli(test.MATTest): | ||
| 50 | #FIXME : use an external file with string as const ? | ||
| 51 | def test_clean(self): | ||
| 52 | '''test is_clean on clean files''' | ||
| 53 | for clean, dirty in self.file_list: | ||
| 54 | proc = subprocess.Popen(['../cli.py', '-c', clean], | ||
| 55 | stdout=subprocess.PIPE) | ||
| 56 | stdout, stderr = proc.communicate() | ||
| 57 | self.assertEqual(stdout.strip('\n'), '[+] %s is clean' % clean) | ||
| 58 | |||
| 59 | def test_dirty(self): | ||
| 60 | '''test is_clean on dirty files''' | ||
| 61 | for clean, dirty in self.file_list: | ||
| 62 | proc = subprocess.Popen(['../cli.py', '-c', dirty], | ||
| 63 | stdout=subprocess.PIPE) | ||
| 64 | stdout, stderr = proc.communicate() | ||
| 65 | self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) | ||
| 66 | |||
| 67 | |||
| 68 | if __name__ == '__main__': | ||
| 69 | suite = unittest.TestSuite() | ||
| 70 | suite.addTest(unittest.makeSuite(Test_Remove_cli)) | ||
| 71 | suite.addTest(unittest.makeSuite(Test_List_cli)) | ||
| 72 | suite.addTest(unittest.makeSuite(Test_isClean_cli)) | ||
| 73 | unittest.TextTestRunner(verbosity=2).run(suite) | ||
diff --git a/test/dirty.jpg b/test/dirty.jpg new file mode 100644 index 0000000..09c9161 --- /dev/null +++ b/test/dirty.jpg | |||
| Binary files differ | |||
diff --git a/test/libtest.py b/test/libtest.py new file mode 100755 index 0000000..2bd1fa7 --- /dev/null +++ b/test/libtest.py | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | |||
| 3 | ''' | ||
| 4 | Unit test for the library | ||
| 5 | ''' | ||
| 6 | |||
| 7 | import unittest | ||
| 8 | import test | ||
| 9 | import sys | ||
| 10 | sys.path.append('..') | ||
| 11 | from lib import mat | ||
| 12 | |||
| 13 | class Test_Remove_lib(test.MATTest): | ||
| 14 | def test_remove(self): | ||
| 15 | '''make sure that the lib remove all compromizing meta''' | ||
| 16 | for clean, dirty in self.file_list: | ||
| 17 | current_file = mat.create_class_file(dirty) | ||
| 18 | current_file.remove_all() | ||
| 19 | self.assertTrue(current_file.is_clean()) | ||
| 20 | |||
| 21 | def test_remove_empty(self): | ||
| 22 | '''Test removal with clean files''' | ||
| 23 | for clean, dirty in self.file_list: | ||
| 24 | current_file = mat.create_class_file(clean) | ||
| 25 | current_file.remove_all() | ||
| 26 | self.assertTrue(current_file.is_clean()) | ||
| 27 | |||
| 28 | |||
| 29 | class Test_List_lib(test.MATTest): | ||
| 30 | def test_list(self): | ||
| 31 | '''check if get_meta returns all the expected meta''' | ||
| 32 | for clean, dirty in self.file_list: | ||
| 33 | current_file = mat.create_class_file(dirty) | ||
| 34 | meta_list = dict({"fixme":"please"},) | ||
| 35 | self.assertEqual(current_file.get_meta(), meta_list) | ||
| 36 | |||
| 37 | def testlist_list_empty(self): | ||
| 38 | '''check that a listing of a clean file return an empty dict''' | ||
| 39 | for clean, dirty in self.file_list: | ||
| 40 | current_file = mat.create_class_file(clean) | ||
| 41 | self.assertEqual(current_file.get_meta(), dict()) #dirty, isn't it ? | ||
| 42 | |||
| 43 | |||
| 44 | class Test_isClean_lib(test.MATTest): | ||
| 45 | def test_dirty(self): | ||
| 46 | '''test is_clean on clean files''' | ||
| 47 | for clean, dirty in self.file_list: | ||
| 48 | current_file = mat.create_class_file(dirty) | ||
| 49 | self.assertTrue(current_file.is_clean()) | ||
| 50 | |||
| 51 | def test_clean(self): | ||
| 52 | '''test is_clean on dirty files''' | ||
| 53 | for clean, dirty in self.file_list: | ||
| 54 | current_file = mat.create_class_file(clean) | ||
| 55 | self.assertFalse(current_file.is_clean()) | ||
| 56 | |||
| 57 | |||
| 58 | if __name__ == '__main__': | ||
| 59 | suite = unittest.TestSuite() | ||
| 60 | suite.addTest(unittest.makeSuite(Test_Remove_lib)) | ||
| 61 | suite.addTest(unittest.makeSuite(Test_List_lib)) | ||
| 62 | suite.addTest(unittest.makeSuite(Test_isClean_lib)) | ||
| 63 | unittest.TextTestRunner(verbosity=2).run(suite) | ||
| 64 | |||
diff --git a/test/test.py b/test/test.py new file mode 100755 index 0000000..f095157 --- /dev/null +++ b/test/test.py | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | ''' | ||
| 2 | Class for the testing suite : | ||
| 3 | - get the list of all test files | ||
| 4 | - create a copy of them on start | ||
| 5 | - remove the copy on end | ||
| 6 | ''' | ||
| 7 | |||
| 8 | import shutil | ||
| 9 | import glob | ||
| 10 | import sys | ||
| 11 | import tempfile | ||
| 12 | import unittest | ||
| 13 | sys.path.append('..') | ||
| 14 | from lib import mat | ||
| 15 | |||
| 16 | FILE_LIST = zip(glob.glob('clean*'), glob.glob('dirty*')) | ||
| 17 | |||
| 18 | class MATTest(unittest.TestCase): | ||
| 19 | def setUp(self): | ||
| 20 | '''create working copy of the clean and the dirty file in the TMP dir''' | ||
| 21 | self.file_list = [] | ||
| 22 | self.tmpdir = tempfile.mkdtemp() | ||
| 23 | |||
| 24 | for clean, dirty in FILE_LIST: | ||
| 25 | shutil.copy2(clean, self.tmpdir + clean) | ||
| 26 | shutil.copy2(dirty, self.tmpdir + dirty) | ||
| 27 | self.file_list.append((self.tmpdir + clean, self.tmpdir + dirty)) | ||
| 28 | |||
| 29 | def tearDown(self): | ||
| 30 | '''Remove the tmp folder''' | ||
| 31 | shutil.rmtree(self.tmpdir) | ||
