Commit 7c83ad38c134414e5eb89ed14a4ad295a970146e
1 parent
ecd49a76
Add unit tests for msodde return codes
The test documents supplied here may contain DDE links but these only start calc.exe. No links to web pages there.
Showing
7 changed files
with
59 additions
and
0 deletions
tests/msodde_doc/__init__.py
0 → 100644
tests/msodde_doc/test_basic.py
0 → 100644
| 1 | +""" Test some basic behaviour of msodde.py | ||
| 2 | + | ||
| 3 | +Ensure that | ||
| 4 | +- doc and docx are read without error | ||
| 5 | +- garbage returns error return status | ||
| 6 | +- dde-links are found where appropriate | ||
| 7 | +""" | ||
| 8 | + | ||
| 9 | +import unittest | ||
| 10 | +from oletools import msodde | ||
| 11 | +import shlex | ||
| 12 | +from os.path import join, dirname, normpath | ||
| 13 | + | ||
| 14 | +BASE_DIR = normpath(join(dirname(__file__), '..', 'test-data')) | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +class TestReturnCode(unittest.TestCase): | ||
| 18 | + | ||
| 19 | + def test_valid_doc(self): | ||
| 20 | + """ check that a valid doc file leads to 0 exit status """ | ||
| 21 | + print(join(BASE_DIR, 'msodde-doc/test_document.doc')) | ||
| 22 | + self.do_test_validity(join(BASE_DIR, 'msodde-doc/test_document.doc')) | ||
| 23 | + | ||
| 24 | + def test_valid_docx(self): | ||
| 25 | + """ check that a valid docx file leads to 0 exit status """ | ||
| 26 | + self.do_test_validity(join(BASE_DIR, 'msodde-doc/test_document.docx')) | ||
| 27 | + | ||
| 28 | + def test_invalid_none(self): | ||
| 29 | + """ check that no file argument leads to non-zero exit status """ | ||
| 30 | + self.do_test_validity('', True) | ||
| 31 | + | ||
| 32 | + def test_invalid_empty(self): | ||
| 33 | + """ check that empty file argument leads to non-zero exit status """ | ||
| 34 | + self.do_test_validity(join(BASE_DIR, 'basic/empty'), True) | ||
| 35 | + | ||
| 36 | + def test_invalid_text(self): | ||
| 37 | + """ check that text file argument leads to non-zero exit status """ | ||
| 38 | + self.do_test_validity(join(BASE_DIR, 'basic/text'), True) | ||
| 39 | + | ||
| 40 | + def do_test_validity(self, args, expect_error=False): | ||
| 41 | + """ helper for test_valid_doc[x] """ | ||
| 42 | + args = shlex.split(args) | ||
| 43 | + return_code = -1 | ||
| 44 | + have_exception = False | ||
| 45 | + try: | ||
| 46 | + return_code = msodde.main(args) | ||
| 47 | + except Exception: | ||
| 48 | + have_exception = True | ||
| 49 | + except SystemExit as se: # sys.exit() was called | ||
| 50 | + return_code = se.code | ||
| 51 | + if se.code is None: | ||
| 52 | + return_code = 0 | ||
| 53 | + | ||
| 54 | + self.assertEqual(expect_error, have_exception or (return_code != 0)) | ||
| 55 | + | ||
| 56 | + | ||
| 57 | +if __name__ == '__main__': | ||
| 58 | + unittest.main() |
tests/test-data/basic/empty
0 → 100644
tests/test-data/basic/text
0 → 100644
| 1 | +bla |
tests/test-data/msodde-doc/dde-test.doc
0 → 100644
No preview for this file type
tests/test-data/msodde-doc/test_document.doc
0 → 100644
No preview for this file type
tests/test-data/msodde-doc/test_document.docx
0 → 100644
No preview for this file type