From 661cd5eb8c6f4fd5476b024be3ee03a6e8471dfd Mon Sep 17 00:00:00 2001 From: Samir Aguiar Date: Fri, 20 Oct 2017 13:22:56 -0200 Subject: [PATCH] Initial support for unit tests (#201) --- .travis.yml | 7 +++++++ README.md | 1 + setup.py | 1 + tests/__init__.py | 0 tests/rtfobj/__init__.py | 0 tests/rtfobj/test_issue_185.py | 16 ++++++++++++++++ tests/test-data/rtfobj/issue_185.rtf | 1 + tests/testdata_reader.py | 6 ++++++ 8 files changed, 32 insertions(+), 0 deletions(-) create mode 100644 .travis.yml create mode 100644 tests/__init__.py create mode 100644 tests/rtfobj/__init__.py create mode 100644 tests/rtfobj/test_issue_185.py create mode 100644 tests/test-data/rtfobj/issue_185.rtf create mode 100644 tests/testdata_reader.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b3e3ee0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: python + +python: + - "2.7" +cache: pip +script: + - python setup.py test diff --git a/README.md b/README.md index 669be41..9ca3156 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ python-oletools =============== [![PyPI](https://img.shields.io/pypi/v/oletools.svg)](https://pypi.python.org/pypi/oletools) +![Build](https://travis-ci.org/samiraguiar/oletools.svg?branch=add-unit-tests) [oletools](http://www.decalage.info/python/oletools) is a package of python tools to analyze [Microsoft OLE2 files](http://en.wikipedia.org/wiki/Compound_File_Binary_Format) diff --git a/setup.py b/setup.py index 4842dd4..9264cee 100644 --- a/setup.py +++ b/setup.py @@ -314,6 +314,7 @@ def main(): download_url=download_url, # data_files=data_files, entry_points=entry_points, + test_suite="tests", # scripts=scripts, ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/rtfobj/__init__.py b/tests/rtfobj/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/rtfobj/__init__.py diff --git a/tests/rtfobj/test_issue_185.py b/tests/rtfobj/test_issue_185.py new file mode 100644 index 0000000..cf8358e --- /dev/null +++ b/tests/rtfobj/test_issue_185.py @@ -0,0 +1,16 @@ +import unittest, sys, os + +from .. import testdata_reader +from oletools import rtfobj + +class TestRtfObjIssue185(unittest.TestCase): + def test_skip_space_after_bin_control_word(self): + data = testdata_reader.read('rtfobj/issue_185.rtf') + rtfp = rtfobj.RtfObjParser(data) + rtfp.parse() + objects = rtfp.objects + + self.assertTrue(len(objects) == 1) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test-data/rtfobj/issue_185.rtf b/tests/test-data/rtfobj/issue_185.rtf new file mode 100644 index 0000000..3a1da01 --- /dev/null +++ b/tests/test-data/rtfobj/issue_185.rtf @@ -0,0 +1 @@ +{\rt{\object\objautlink\objupdate\rsltpict\objw37542\objh829\objscalex59286\objscaley86308{\*\objclass \'77}{\*\objdata 32\bin6 FF}}} \ No newline at end of file diff --git a/tests/testdata_reader.py b/tests/testdata_reader.py new file mode 100644 index 0000000..e474141 --- /dev/null +++ b/tests/testdata_reader.py @@ -0,0 +1,6 @@ +import os + +def read(relative_path): + test_data = os.path.dirname(os.path.abspath(__file__)) + '/test-data/' + return open(test_data + relative_path, 'rb').read() + -- libgit2 0.21.4