From f40cf7870f7c030bafe49d6a8ec536010d8cdf87 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sun, 13 Apr 2014 23:16:01 +0300 Subject: [PATCH] More testing --- Tests/test_olefileio.py | 57 +++++++++++++++++++++++++++++++++++++++++ Tests/tester.py | 24 ++++++++++++++--- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/Tests/test_olefileio.py b/Tests/test_olefileio.py index 3d65d9018..d21b704e3 100644 --- a/Tests/test_olefileio.py +++ b/Tests/test_olefileio.py @@ -1,5 +1,6 @@ from __future__ import print_function from tester import * +import datetime import PIL.OleFileIO as OleFileIO @@ -36,6 +37,7 @@ def test_exists_worddocument(): # Assert assert_true(exists) + ole.close() def test_exists_no_vba_macros(): @@ -48,6 +50,7 @@ def test_exists_no_vba_macros(): # Assert assert_false(exists) + ole.close() def test_get_type(): @@ -60,6 +63,7 @@ def test_get_type(): # Assert assert_equal(type, OleFileIO.STGTY_STREAM) + ole.close() def test_get_size(): @@ -72,6 +76,7 @@ def test_get_size(): # Assert assert_greater(size, 0) + ole.close() def test_get_rootentry_name(): @@ -84,6 +89,7 @@ def test_get_rootentry_name(): # Assert assert_equal(root, "Root Entry") + ole.close() def test_meta(): @@ -97,5 +103,56 @@ def test_meta(): # Assert assert_equal(meta.author, b"Laurence Ipsum") assert_equal(meta.num_pages, 1) + ole.close() + +def test_gettimes(): + # Arrange + ole_file = "Tests/images/test-ole-file.doc" + ole = OleFileIO.OleFileIO(ole_file) + root_entry = ole.direntries[0] + + # Act + ctime = root_entry.getmtime() + mtime = root_entry.getmtime() + + # Assert + assert_is_instance(ctime, datetime.datetime) + assert_is_instance(mtime, datetime.datetime) + assert_equal(ctime.year, 2014) + ole.close() + + +def test_listdir(): + # Arrange + ole_file = "Tests/images/test-ole-file.doc" + ole = OleFileIO.OleFileIO(ole_file) + + # Act + dirlist = ole.listdir() + + # Assert + assert_in(['WordDocument'], dirlist) + ole.close() + + +def test_debug(): + # Arrange + ole_file = "Tests/images/test-ole-file.doc" + ole = OleFileIO.OleFileIO(ole_file) + meta = ole.get_metadata() + + # Act + OleFileIO.set_debug_mode(True) + ole.dumpdirectory() + meta.dump() + + OleFileIO.set_debug_mode(False) + ole.dumpdirectory() + meta.dump() + + # Assert + # No assert, just check they run ok + ole.close() + # End of file diff --git a/Tests/tester.py b/Tests/tester.py index 41f27e4ff..32da48e98 100644 --- a/Tests/tester.py +++ b/Tests/tester.py @@ -98,28 +98,44 @@ def assert_greater(a, b, msg=None): if a > b: success() else: - failure(msg or "got %r, expected %r" % (a, b)) + failure(msg or "%r unexpectedly not greater than %r" % (a, b)) def assert_greater_equal(a, b, msg=None): if a >= b: success() else: - failure(msg or "got %r, expected %r" % (a, b)) + failure( + msg or "%r unexpectedly not greater than or equal to %r" % (a, b)) def assert_less(a, b, msg=None): if a < b: success() else: - failure(msg or "got %r, expected %r" % (a, b)) + failure(msg or "%r unexpectedly not less than %r" % (a, b)) def assert_less_equal(a, b, msg=None): if a <= b: success() else: - failure(msg or "got %r, expected %r" % (a, b)) + failure( + msg or "%r unexpectedly not less than or equal to %r" % (a, b)) + + +def assert_is_instance(a, b, msg=None): + if isinstance(a, b): + success() + else: + failure(msg or "got %r, expected %r" % (type(a), b)) + + +def assert_in(a, b, msg=None): + if a in b: + success() + else: + failure(msg or "%r unexpectedly not in %r" % (a, b)) def assert_match(v, pattern, msg=None):