diff options
| author | jvoisin | 2012-12-13 22:40:31 +0100 |
|---|---|---|
| committer | jvoisin | 2012-12-13 22:40:31 +0100 |
| commit | ffcb08763dcdaeef0caabc3fcb4d1442fce404ef (patch) | |
| tree | 2e8057e8e59e99df1a4f6bbf6ae0e1d0b8f837f6 | |
| parent | 614b07d5166a1718ac4d492384490d33c4087f49 (diff) | |
| parent | dae41c8e7d2cfce4e7f6a6a2bd27e0c018cd6a60 (diff) | |
Merge branch 'test_suite'
| -rw-r--r-- | test/clitest.py | 24 | ||||
| -rw-r--r-- | test/libtest.py | 18 | ||||
| -rw-r--r-- | test/test.py | 23 |
3 files changed, 30 insertions, 35 deletions
diff --git a/test/clitest.py b/test/clitest.py index a818b5d..0b041b9 100644 --- a/test/clitest.py +++ b/test/clitest.py | |||
| @@ -43,8 +43,8 @@ class TestListcli(test.MATTest): | |||
| 43 | proc = subprocess.Popen(['../mat', '-d', clean], | 43 | proc = subprocess.Popen(['../mat', '-d', clean], |
| 44 | stdout=subprocess.PIPE) | 44 | stdout=subprocess.PIPE) |
| 45 | stdout, _ = proc.communicate() | 45 | stdout, _ = proc.communicate() |
| 46 | self.assertEqual(stdout.strip('\n'), "[+] File %s :\nNo harmful \ | 46 | self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ |
| 47 | metadata found" % clean) | 47 | :\nNo harmful metadata found" % clean) |
| 48 | 48 | ||
| 49 | def test_list_dirty(self): | 49 | def test_list_dirty(self): |
| 50 | '''check if get_meta returns all the expected meta''' | 50 | '''check if get_meta returns all the expected meta''' |
| @@ -52,7 +52,7 @@ metadata found" % clean) | |||
| 52 | proc = subprocess.Popen(['../mat', '-d', dirty], | 52 | proc = subprocess.Popen(['../mat', '-d', dirty], |
| 53 | stdout=subprocess.PIPE) | 53 | stdout=subprocess.PIPE) |
| 54 | stdout, _ = proc.communicate() | 54 | stdout, _ = proc.communicate() |
| 55 | self.assertNotEqual(stdout, "[+] File %s" % dirty) | 55 | self.assertNotEqual(str(stdout), "[+] File %s" % dirty) |
| 56 | 56 | ||
| 57 | 57 | ||
| 58 | class TestisCleancli(test.MATTest): | 58 | class TestisCleancli(test.MATTest): |
| @@ -65,7 +65,7 @@ class TestisCleancli(test.MATTest): | |||
| 65 | proc = subprocess.Popen(['../mat', '-c', clean], | 65 | proc = subprocess.Popen(['../mat', '-c', clean], |
| 66 | stdout=subprocess.PIPE) | 66 | stdout=subprocess.PIPE) |
| 67 | stdout, _ = proc.communicate() | 67 | stdout, _ = proc.communicate() |
| 68 | self.assertEqual(stdout.strip('\n'), '[+] %s is clean' % clean) | 68 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) |
| 69 | 69 | ||
| 70 | def test_dirty(self): | 70 | def test_dirty(self): |
| 71 | '''test is_clean on dirty files''' | 71 | '''test is_clean on dirty files''' |
| @@ -73,7 +73,7 @@ class TestisCleancli(test.MATTest): | |||
| 73 | proc = subprocess.Popen(['../mat', '-c', dirty], | 73 | proc = subprocess.Popen(['../mat', '-c', dirty], |
| 74 | stdout=subprocess.PIPE) | 74 | stdout=subprocess.PIPE) |
| 75 | stdout, _ = proc.communicate() | 75 | stdout, _ = proc.communicate() |
| 76 | self.assertEqual(stdout.strip('\n'), '[+] %s is not clean' % dirty) | 76 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) |
| 77 | 77 | ||
| 78 | 78 | ||
| 79 | class TestFileAttributes(unittest.TestCase): | 79 | class TestFileAttributes(unittest.TestCase): |
| @@ -81,26 +81,28 @@ class TestFileAttributes(unittest.TestCase): | |||
| 81 | test various stuffs about files (readable, writable, exist, ...) | 81 | test various stuffs about files (readable, writable, exist, ...) |
| 82 | ''' | 82 | ''' |
| 83 | def test_not_writtable(self): | 83 | def test_not_writtable(self): |
| 84 | ''' test MAT's behaviour on non-writable file''' | ||
| 84 | proc = subprocess.Popen(['../mat', 'not_writtable'], | 85 | proc = subprocess.Popen(['../mat', 'not_writtable'], |
| 85 | stdout=subprocess.PIPE) | 86 | stdout=subprocess.PIPE) |
| 86 | stdout, _ = proc.communicate() | 87 | stdout, _ = proc.communicate() |
| 87 | self.assertEqual(stdout.strip('\n'), 'Unable to pocess %s' % 'not_writtable') | 88 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'not_writtable') |
| 88 | 89 | ||
| 89 | def test_not_exist(self): | 90 | def test_not_exist(self): |
| 91 | ''' test MAT's behaviour on non-existent file''' | ||
| 90 | proc = subprocess.Popen(['../mat', 'ilikecookies'], | 92 | proc = subprocess.Popen(['../mat', 'ilikecookies'], |
| 91 | stdout=subprocess.PIPE) | 93 | stdout=subprocess.PIPE) |
| 92 | stdout, _ = proc.communicate() | 94 | stdout, _ = proc.communicate() |
| 93 | self.assertEqual(stdout.strip('\n'), 'Unable to pocess %s' % 'ilikecookies') | 95 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') |
| 94 | 96 | ||
| 95 | 97 | ||
| 96 | def main(): | 98 | def get_tests(): |
| 99 | ''' Return every clitests''' | ||
| 97 | suite = unittest.TestSuite() | 100 | suite = unittest.TestSuite() |
| 98 | suite.addTest(unittest.makeSuite(TestRemovecli)) | 101 | suite.addTest(unittest.makeSuite(TestRemovecli)) |
| 99 | suite.addTest(unittest.makeSuite(TestListcli)) | 102 | suite.addTest(unittest.makeSuite(TestListcli)) |
| 100 | suite.addTest(unittest.makeSuite(TestisCleancli)) | 103 | suite.addTest(unittest.makeSuite(TestisCleancli)) |
| 101 | test_result = unittest.TextTestRunner(verbosity=test.VERBOSITY).run(suite) | 104 | return suite |
| 102 | return len(test_result.failures) | ||
| 103 | 105 | ||
| 104 | 106 | ||
| 105 | if __name__ == '__main__': | 107 | if __name__ == '__main__': |
| 106 | sys.exit(main()) | 108 | unittest.TextTestRunner(verbosity=test.VERBOSITY).run(get_tests()) |
diff --git a/test/libtest.py b/test/libtest.py index 9a833f1..2f0ee8f 100644 --- a/test/libtest.py +++ b/test/libtest.py | |||
| @@ -78,15 +78,15 @@ class TestFileAttributes(unittest.TestCase): | |||
| 78 | self.assertFalse(mat.create_class_file('ilikecookies', False, True)) | 78 | self.assertFalse(mat.create_class_file('ilikecookies', False, True)) |
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | def main(): | 81 | def get_tests(): |
| 82 | Suite = unittest.TestSuite() | 82 | ''' Return every libtests''' |
| 83 | Suite.addTest(unittest.makeSuite(TestRemovelib)) | 83 | suite = unittest.TestSuite() |
| 84 | Suite.addTest(unittest.makeSuite(TestListlib)) | 84 | suite.addTest(unittest.makeSuite(TestRemovelib)) |
| 85 | Suite.addTest(unittest.makeSuite(TestisCleanlib)) | 85 | suite.addTest(unittest.makeSuite(TestListlib)) |
| 86 | Suite.addTest(unittest.makeSuite(TestFileAttributes)) | 86 | suite.addTest(unittest.makeSuite(TestisCleanlib)) |
| 87 | test_result = unittest.TextTestRunner(verbosity=test.VERBOSITY).run(Suite) | 87 | suite.addTest(unittest.makeSuite(TestFileAttributes)) |
| 88 | return len(test_result.failures) | 88 | return suite |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | if __name__ == '__main__': | 91 | if __name__ == '__main__': |
| 92 | sys.exit(main()) | 92 | unittest.TextTestRunner(verbosity=test.VERBOSITY).run(get_tests()) |
diff --git a/test/test.py b/test/test.py index f09e1c5..675c4f9 100644 --- a/test/test.py +++ b/test/test.py | |||
| @@ -14,7 +14,6 @@ import glob | |||
| 14 | import tempfile | 14 | import tempfile |
| 15 | import unittest | 15 | import unittest |
| 16 | import subprocess | 16 | import subprocess |
| 17 | import sys | ||
| 18 | 17 | ||
| 19 | VERBOSITY = 3 | 18 | VERBOSITY = 3 |
| 20 | 19 | ||
| @@ -29,18 +28,18 @@ try: # PDF render processing | |||
| 29 | import poppler | 28 | import poppler |
| 30 | import cairo | 29 | import cairo |
| 31 | import pdfrw | 30 | import pdfrw |
| 32 | except: | 31 | except ImportError: |
| 33 | FILE_LIST.remove(('clean é.pdf', 'dirty é.pdf')) | 32 | FILE_LIST.remove(('clean é.pdf', 'dirty é.pdf')) |
| 34 | 33 | ||
| 35 | try: # python-mutagen : audio file format | 34 | try: # python-mutagen : audio file format |
| 36 | import mutagen | 35 | import mutagen |
| 37 | except: | 36 | except ImportError: |
| 38 | pass # since wr don't have any ogg for now | 37 | pass # since wr don't have any ogg for now |
| 39 | #FILE_LIST.remove(('clean.ogg', 'dirty.ogg')) | 38 | #FILE_LIST.remove(('clean.ogg', 'dirty.ogg')) |
| 40 | 39 | ||
| 41 | try: # file format exclusively managed by exiftool | 40 | try: # file format exclusively managed by exiftool |
| 42 | subprocess.Popen('exiftool', stdout=open('/dev/null')) | 41 | subprocess.Popen('exiftool', stdout=open('/dev/null')) |
| 43 | except: | 42 | except OSError: |
| 44 | pass # None for now | 43 | pass # None for now |
| 45 | 44 | ||
| 46 | 45 | ||
| @@ -68,18 +67,12 @@ class MATTest(unittest.TestCase): | |||
| 68 | shutil.rmtree(self.tmpdir) | 67 | shutil.rmtree(self.tmpdir) |
| 69 | 68 | ||
| 70 | 69 | ||
| 71 | def main(): | 70 | if __name__ == '__main__': |
| 72 | import clitest | 71 | import clitest |
| 73 | import libtest | 72 | import libtest |
| 74 | 73 | ||
| 75 | failed_tests = 0 | 74 | SUITE = unittest.TestSuite() |
| 76 | 75 | SUITE.addTests(clitest.get_tests()) | |
| 77 | print('Running cli related tests:\n') | 76 | SUITE.addTests(libtest.get_tests()) |
| 78 | failed_tests += clitest.main() | ||
| 79 | print('\nRunning library related tests:\n') | ||
| 80 | failed_tests += libtest.main() | ||
| 81 | print('\nTotal failed tests: ' + str(failed_tests)) | ||
| 82 | return failed_tests | ||
| 83 | 77 | ||
| 84 | if __name__ == '__main__': | 78 | unittest.TextTestRunner(verbosity=VERBOSITY).run(SUITE) |
| 85 | sys.exit(main()) | ||
