diff --git a/tests/msodde_doc/__init__.py b/tests/msodde_doc/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/msodde_doc/__init__.py diff --git a/tests/msodde_doc/test_basic.py b/tests/msodde_doc/test_basic.py new file mode 100644 index 0000000..9156f85 --- /dev/null +++ b/tests/msodde_doc/test_basic.py @@ -0,0 +1,58 @@ +""" Test some basic behaviour of msodde.py + +Ensure that +- doc and docx are read without error +- garbage returns error return status +- dde-links are found where appropriate +""" + +import unittest +from oletools import msodde +import shlex +from os.path import join, dirname, normpath + +BASE_DIR = normpath(join(dirname(__file__), '..', 'test-data')) + + +class TestReturnCode(unittest.TestCase): + + def test_valid_doc(self): + """ check that a valid doc file leads to 0 exit status """ + print(join(BASE_DIR, 'msodde-doc/test_document.doc')) + self.do_test_validity(join(BASE_DIR, 'msodde-doc/test_document.doc')) + + def test_valid_docx(self): + """ check that a valid docx file leads to 0 exit status """ + self.do_test_validity(join(BASE_DIR, 'msodde-doc/test_document.docx')) + + def test_invalid_none(self): + """ check that no file argument leads to non-zero exit status """ + self.do_test_validity('', True) + + def test_invalid_empty(self): + """ check that empty file argument leads to non-zero exit status """ + self.do_test_validity(join(BASE_DIR, 'basic/empty'), True) + + def test_invalid_text(self): + """ check that text file argument leads to non-zero exit status """ + self.do_test_validity(join(BASE_DIR, 'basic/text'), True) + + def do_test_validity(self, args, expect_error=False): + """ helper for test_valid_doc[x] """ + args = shlex.split(args) + return_code = -1 + have_exception = False + try: + return_code = msodde.main(args) + except Exception: + have_exception = True + except SystemExit as se: # sys.exit() was called + return_code = se.code + if se.code is None: + return_code = 0 + + self.assertEqual(expect_error, have_exception or (return_code != 0)) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test-data/basic/empty b/tests/test-data/basic/empty new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/test-data/basic/empty diff --git a/tests/test-data/basic/text b/tests/test-data/basic/text new file mode 100644 index 0000000..a7f8d9e --- /dev/null +++ b/tests/test-data/basic/text @@ -0,0 +1 @@ +bla diff --git a/tests/test-data/msodde-doc/dde-test.doc b/tests/test-data/msodde-doc/dde-test.doc new file mode 100644 index 0000000..da5562c --- /dev/null +++ b/tests/test-data/msodde-doc/dde-test.doc diff --git a/tests/test-data/msodde-doc/test_document.doc b/tests/test-data/msodde-doc/test_document.doc new file mode 100644 index 0000000..2c1768f --- /dev/null +++ b/tests/test-data/msodde-doc/test_document.doc diff --git a/tests/test-data/msodde-doc/test_document.docx b/tests/test-data/msodde-doc/test_document.docx new file mode 100644 index 0000000..4dd2265 --- /dev/null +++ b/tests/test-data/msodde-doc/test_document.docx