diff options
Diffstat (limited to 'test/clitest.py')
| -rw-r--r-- | test/clitest.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/test/clitest.py b/test/clitest.py index 312822f..ad895f5 100644 --- a/test/clitest.py +++ b/test/clitest.py | |||
| @@ -5,9 +5,11 @@ | |||
| 5 | Unit test for the CLI interface | 5 | Unit test for the CLI interface |
| 6 | ''' | 6 | ''' |
| 7 | 7 | ||
| 8 | import os | ||
| 8 | import unittest | 9 | import unittest |
| 9 | import subprocess | 10 | import subprocess |
| 10 | import sys | 11 | import sys |
| 12 | import tarfile | ||
| 11 | 13 | ||
| 12 | sys.path.append('..') | 14 | sys.path.append('..') |
| 13 | from MAT import mat | 15 | from MAT import mat |
| @@ -21,14 +23,14 @@ class TestRemovecli(test.MATTest): | |||
| 21 | def test_remove(self): | 23 | def test_remove(self): |
| 22 | '''make sure that the cli remove all compromizing meta''' | 24 | '''make sure that the cli remove all compromizing meta''' |
| 23 | for _, dirty in self.file_list: | 25 | for _, dirty in self.file_list: |
| 24 | subprocess.call(['../mat', dirty]) | 26 | subprocess.call(['../mat', '--add2archive', dirty]) |
| 25 | current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) | 27 | current_file = mat.create_class_file(dirty, False, add2archive=True, low_pdf_quality=True) |
| 26 | self.assertTrue(current_file.is_clean()) | 28 | self.assertTrue(current_file.is_clean()) |
| 27 | 29 | ||
| 28 | def test_remove_empty(self): | 30 | def test_remove_empty(self): |
| 29 | '''Test removal with clean files''' | 31 | '''Test removal with clean files\n''' |
| 30 | for clean, _ in self.file_list: | 32 | for clean, _ in self.file_list: |
| 31 | subprocess.call(['../mat', clean]) | 33 | subprocess.call(['../mat', '--add2archive', clean]) |
| 32 | current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) | 34 | current_file = mat.create_class_file(clean, False, add2archive=True, low_pdf_quality=True) |
| 33 | self.assertTrue(current_file.is_clean()) | 35 | self.assertTrue(current_file.is_clean()) |
| 34 | 36 | ||
| @@ -97,11 +99,24 @@ class TestFileAttributes(unittest.TestCase): | |||
| 97 | 99 | ||
| 98 | def test_empty(self): | 100 | def test_empty(self): |
| 99 | ''' test MAT's behaviour on empty file''' | 101 | ''' test MAT's behaviour on empty file''' |
| 100 | proc = subprocess.Popen(['../mat', 'empty_file'], | 102 | proc = subprocess.Popen(['../mat', 'empty_file'], stdout=subprocess.PIPE) |
| 101 | stdout=subprocess.PIPE) | ||
| 102 | stdout, _ = proc.communicate() | 103 | stdout, _ = proc.communicate() |
| 103 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') | 104 | self.assertEqual(str(stdout).strip('\n'), 'Unable to process %s' % 'ilikecookies') |
| 104 | 105 | ||
| 106 | class TestUnsupported(test.MATTest): | ||
| 107 | def test_abort_unsupported(self): | ||
| 108 | ''' test if the cli aborts on unsupported files | ||
| 109 | ''' | ||
| 110 | tarpath = os.path.join(self.tmpdir, "test.tar.bz2") | ||
| 111 | tar = tarfile.open(tarpath, "w") | ||
| 112 | for f in ('../mat.desktop', '../README.security', '../setup.py'): | ||
| 113 | tar.add(f, f[3:]) # trim '../' | ||
| 114 | tar.close() | ||
| 115 | proc = subprocess.Popen(['../mat', tarpath], stdout=subprocess.PIPE) | ||
| 116 | stdout, _ = proc.communicate() | ||
| 117 | self.assertTrue('It contains unsupported filetypes:'\ | ||
| 118 | '\n- mat.desktop\n- README.security\n- setup.py\n' | ||
| 119 | in str(stdout)) | ||
| 105 | 120 | ||
| 106 | def get_tests(): | 121 | def get_tests(): |
| 107 | ''' Return every clitests''' | 122 | ''' Return every clitests''' |
| @@ -109,4 +124,5 @@ def get_tests(): | |||
| 109 | suite.addTest(unittest.makeSuite(TestRemovecli)) | 124 | suite.addTest(unittest.makeSuite(TestRemovecli)) |
| 110 | suite.addTest(unittest.makeSuite(TestListcli)) | 125 | suite.addTest(unittest.makeSuite(TestListcli)) |
| 111 | suite.addTest(unittest.makeSuite(TestisCleancli)) | 126 | suite.addTest(unittest.makeSuite(TestisCleancli)) |
| 127 | suite.addTest(unittest.makeSuite(TestUnsupported)) | ||
| 112 | return suite | 128 | return suite |
