More testing

This commit is contained in:
hugovk 2014-04-13 23:16:01 +03:00
parent be201bf4f3
commit f40cf7870f
2 changed files with 77 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from __future__ import print_function from __future__ import print_function
from tester import * from tester import *
import datetime
import PIL.OleFileIO as OleFileIO import PIL.OleFileIO as OleFileIO
@ -36,6 +37,7 @@ def test_exists_worddocument():
# Assert # Assert
assert_true(exists) assert_true(exists)
ole.close()
def test_exists_no_vba_macros(): def test_exists_no_vba_macros():
@ -48,6 +50,7 @@ def test_exists_no_vba_macros():
# Assert # Assert
assert_false(exists) assert_false(exists)
ole.close()
def test_get_type(): def test_get_type():
@ -60,6 +63,7 @@ def test_get_type():
# Assert # Assert
assert_equal(type, OleFileIO.STGTY_STREAM) assert_equal(type, OleFileIO.STGTY_STREAM)
ole.close()
def test_get_size(): def test_get_size():
@ -72,6 +76,7 @@ def test_get_size():
# Assert # Assert
assert_greater(size, 0) assert_greater(size, 0)
ole.close()
def test_get_rootentry_name(): def test_get_rootentry_name():
@ -84,6 +89,7 @@ def test_get_rootentry_name():
# Assert # Assert
assert_equal(root, "Root Entry") assert_equal(root, "Root Entry")
ole.close()
def test_meta(): def test_meta():
@ -97,5 +103,56 @@ def test_meta():
# Assert # Assert
assert_equal(meta.author, b"Laurence Ipsum") assert_equal(meta.author, b"Laurence Ipsum")
assert_equal(meta.num_pages, 1) 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 # End of file

View File

@ -98,28 +98,44 @@ def assert_greater(a, b, msg=None):
if a > b: if a > b:
success() success()
else: 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): def assert_greater_equal(a, b, msg=None):
if a >= b: if a >= b:
success() success()
else: 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): def assert_less(a, b, msg=None):
if a < b: if a < b:
success() success()
else: 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): def assert_less_equal(a, b, msg=None):
if a <= b: if a <= b:
success() success()
else: 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): def assert_match(v, pattern, msg=None):