diff options
Diffstat (limited to 'test/clitest.py')
| -rw-r--r-- | test/clitest.py | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/test/clitest.py b/test/clitest.py index 0a29c02..c913bdf 100644 --- a/test/clitest.py +++ b/test/clitest.py | |||
| @@ -11,9 +11,15 @@ import subprocess | |||
| 11 | import sys | 11 | import sys |
| 12 | import tarfile | 12 | import tarfile |
| 13 | 13 | ||
| 14 | sys.path.append('..') | ||
| 15 | from libmat import mat | ||
| 16 | import test | 14 | import test |
| 15 | MAT_PATH = 'mat' | ||
| 16 | if test.IS_LOCAL is True: | ||
| 17 | # Are we testing the _local_ version of MAT? | ||
| 18 | sys.path.insert(0, '..') | ||
| 19 | MAT_PATH = '../mat' | ||
| 20 | # else it will be in the path | ||
| 21 | |||
| 22 | from libmat import mat | ||
| 17 | 23 | ||
| 18 | 24 | ||
| 19 | class TestRemovecli(test.MATTest): | 25 | class TestRemovecli(test.MATTest): |
| @@ -24,14 +30,14 @@ class TestRemovecli(test.MATTest): | |||
| 24 | def test_remove(self): | 30 | def test_remove(self): |
| 25 | """make sure that the cli remove all compromizing meta""" | 31 | """make sure that the cli remove all compromizing meta""" |
| 26 | for _, dirty in self.file_list: | 32 | for _, dirty in self.file_list: |
| 27 | subprocess.call(['../mat', '--add2archive', dirty]) | 33 | subprocess.call([MAT_PATH, '--add2archive', dirty]) |
| 28 | current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) | 34 | current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) |
| 29 | self.assertTrue(current_file.is_clean()) | 35 | self.assertTrue(current_file.is_clean()) |
| 30 | 36 | ||
| 31 | def test_remove_empty(self): | 37 | def test_remove_empty(self): |
| 32 | """Test removal with clean files\n""" | 38 | """Test removal with clean files\n""" |
| 33 | for clean, _ in self.file_list: | 39 | for clean, _ in self.file_list: |
| 34 | subprocess.call(['../mat', '--add2archive', clean]) | 40 | subprocess.call([MAT_PATH, '--add2archive', clean]) |
| 35 | current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) | 41 | current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) |
| 36 | self.assertTrue(current_file.is_clean()) | 42 | self.assertTrue(current_file.is_clean()) |
| 37 | 43 | ||
| @@ -44,7 +50,7 @@ class TestListcli(test.MATTest): | |||
| 44 | def test_list_clean(self): | 50 | def test_list_clean(self): |
| 45 | """check if get_meta returns meta""" | 51 | """check if get_meta returns meta""" |
| 46 | for clean, _ in self.file_list: | 52 | for clean, _ in self.file_list: |
| 47 | proc = subprocess.Popen(['../mat', '-d', clean], | 53 | proc = subprocess.Popen([MAT_PATH, '-d', clean], |
| 48 | stdout=subprocess.PIPE) | 54 | stdout=subprocess.PIPE) |
| 49 | stdout, _ = proc.communicate() | 55 | stdout, _ = proc.communicate() |
| 50 | self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ | 56 | self.assertEqual(str(stdout).strip('\n'), "[+] File %s \ |
| @@ -53,7 +59,7 @@ class TestListcli(test.MATTest): | |||
| 53 | def test_list_dirty(self): | 59 | def test_list_dirty(self): |
| 54 | """check if get_meta returns all the expected meta""" | 60 | """check if get_meta returns all the expected meta""" |
| 55 | for _, dirty in self.file_list: | 61 | for _, dirty in self.file_list: |
| 56 | proc = subprocess.Popen(['../mat', '-d', dirty], | 62 | proc = subprocess.Popen([MAT_PATH, '-d', dirty], |
| 57 | stdout=subprocess.PIPE) | 63 | stdout=subprocess.PIPE) |
| 58 | stdout, _ = proc.communicate() | 64 | stdout, _ = proc.communicate() |
| 59 | self.assertNotEqual(str(stdout), "[+] File %s :\n No\ | 65 | self.assertNotEqual(str(stdout), "[+] File %s :\n No\ |
| @@ -68,7 +74,7 @@ class TestisCleancli(test.MATTest): | |||
| 68 | def test_clean(self): | 74 | def test_clean(self): |
| 69 | """test is_clean on clean files""" | 75 | """test is_clean on clean files""" |
| 70 | for clean, _ in self.file_list: | 76 | for clean, _ in self.file_list: |
| 71 | proc = subprocess.Popen(['../mat', '-c', clean], | 77 | proc = subprocess.Popen([MAT_PATH, '-c', clean], |
| 72 | stdout=subprocess.PIPE) | 78 | stdout=subprocess.PIPE) |
| 73 | stdout, _ = proc.communicate() | 79 | stdout, _ = proc.communicate() |
| 74 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) | 80 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is clean' % clean) |
| @@ -76,7 +82,7 @@ class TestisCleancli(test.MATTest): | |||
| 76 | def test_dirty(self): | 82 | def test_dirty(self): |
| 77 | """test is_clean on dirty files""" | 83 | """test is_clean on dirty files""" |
| 78 | for _, dirty in self.file_list: | 84 | for _, dirty in self.file_list: |
| 79 | proc = subprocess.Popen(['../mat', '-c', dirty], | 85 | proc = subprocess.Popen([MAT_PATH, '-c', dirty], |
| 80 | stdout=subprocess.PIPE) | 86 | stdout=subprocess.PIPE) |
| 81 | stdout, _ = proc.communicate() | 87 | stdout, _ = proc.communicate() |
| 82 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) | 88 | self.assertEqual(str(stdout).strip('\n'), '[+] %s is not clean' % dirty) |
| @@ -89,21 +95,21 @@ class TestFileAttributes(unittest.TestCase): | |||
| 89 | 95 | ||
| 90 | def test_not_writtable(self): | 96 | def test_not_writtable(self): |
| 91 | """ test MAT's behaviour on non-writable file""" | 97 | """ test MAT's behaviour on non-writable file""" |
| 92 | proc = subprocess.Popen(['../mat', 'not_writtable'], | 98 | proc = subprocess.Popen([MAT_PATH, 'not_writtable'], |
| 93 | stdout=subprocess.PIPE) | 99 | stdout=subprocess.PIPE) |
| 94 | stdout, _ = proc.communicate() | 100 | stdout, _ = proc.communicate() |
| 95 | self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable') | 101 | self.assertEqual(str(stdout).strip('\n'), '[-] %s is not writable' % 'not_writtable') |
| 96 | 102 | ||
| 97 | def test_not_exist(self): | 103 | def test_not_exist(self): |
| 98 | """ test MAT's behaviour on non-existent file""" | 104 | """ test MAT's behaviour on non-existent file""" |
| 99 | proc = subprocess.Popen(['../mat', 'ilikecookies'], | 105 | proc = subprocess.Popen([MAT_PATH, 'ilikecookies'], |
| 100 | stdout=subprocess.PIPE) | 106 | stdout=subprocess.PIPE) |
| 101 | stdout, _ = proc.communicate() | 107 | stdout, _ = proc.communicate() |
| 102 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') | 108 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') |
| 103 | 109 | ||
| 104 | def test_empty(self): | 110 | def test_empty(self): |
| 105 | """ test MAT's behaviour on empty file""" | 111 | """ test MAT's behaviour on empty file""" |
| 106 | proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) | 112 | proc = subprocess.Popen([MAT_PATH, 'empty_file'], stdout=subprocess.PIPE) |
| 107 | stdout, _ = proc.communicate() | 113 | stdout, _ = proc.communicate() |
| 108 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') | 114 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') |
| 109 | 115 | ||
| @@ -114,13 +120,13 @@ class TestUnsupported(test.MATTest): | |||
| 114 | """ | 120 | """ |
| 115 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") | 121 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") |
| 116 | tar = tarfile.open(tarpath, "w") | 122 | tar = tarfile.open(tarpath, "w") |
| 117 | for f in ('../mat.desktop', '../README.security', '../setup.py'): | 123 | for f in ('libtest.py', 'test.py', 'clitest.py'): |
| 118 | tar.add(f, f[3:]) # trim '../' | 124 | tar.add(f, f) |
| 119 | tar.close() | 125 | tar.close() |
| 120 | proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) | 126 | proc = subprocess.Popen([MAT_PATH, tarpath], stdout=subprocess.PIPE) |
| 121 | stdout, _ = proc.communicate() | 127 | stdout, _ = proc.communicate() |
| 122 | self.assertTrue('It contains unsupported filetypes:' \ | 128 | self.assertTrue('It contains unsupported filetypes:' \ |
| 123 | '\n- mat.desktop\n- README.security\n- setup.py\n' | 129 | '\n- libtest.py\n- test.py\n- clitest.py\n' |
| 124 | in str(stdout)) | 130 | in str(stdout)) |
| 125 | 131 | ||
| 126 | 132 | ||
