Pillow/Tests/test_olefileio.py

163 lines
3.0 KiB
Python
Raw Normal View History

2014-04-11 15:53:33 +04:00
from __future__ import print_function
from tester import *
2014-04-14 00:16:01 +04:00
import datetime
2014-04-11 15:53:33 +04:00
import PIL.OleFileIO as OleFileIO
def test_isOleFile_false():
# Arrange
non_ole_file = "Tests/images/flower.jpg"
# Act
is_ole = OleFileIO.isOleFile(non_ole_file)
# Assert
assert_false(is_ole)
def test_isOleFile_true():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
# Act
is_ole = OleFileIO.isOleFile(ole_file)
# Assert
assert_true(is_ole)
def test_exists_worddocument():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
# Act
exists = ole.exists('worddocument')
# Assert
assert_true(exists)
2014-04-14 00:16:01 +04:00
ole.close()
2014-04-11 15:53:33 +04:00
def test_exists_no_vba_macros():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
# Act
exists = ole.exists('macros/vba')
# Assert
assert_false(exists)
2014-04-14 00:16:01 +04:00
ole.close()
2014-04-11 15:53:33 +04:00
def test_get_type():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
# Act
type = ole.get_type('worddocument')
# Assert
assert_equal(type, OleFileIO.STGTY_STREAM)
2014-04-14 00:16:01 +04:00
ole.close()
2014-04-11 15:53:33 +04:00
def test_get_size():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
# Act
size = ole.get_size('worddocument')
# Assert
assert_greater(size, 0)
2014-04-14 00:16:01 +04:00
ole.close()
2014-04-11 15:53:33 +04:00
def test_get_rootentry_name():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
# Act
root = ole.get_rootentry_name()
# Assert
assert_equal(root, "Root Entry")
2014-04-14 00:16:01 +04:00
ole.close()
2014-04-11 15:53:33 +04:00
def test_meta():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
# Act
meta = ole.get_metadata()
# Assert
2014-04-11 16:02:42 +04:00
assert_equal(meta.author, b"Laurence Ipsum")
2014-04-11 15:53:33 +04:00
assert_equal(meta.num_pages, 1)
2014-04-14 00:16:01 +04:00
ole.close()
2014-04-14 01:27:08 +04:00
2014-04-14 00:16:01 +04:00
def test_gettimes():
# Arrange
ole_file = "Tests/images/test-ole-file.doc"
ole = OleFileIO.OleFileIO(ole_file)
root_entry = ole.direntries[0]
# Act
2014-04-14 01:27:08 +04:00
ctime = root_entry.getctime()
2014-04-14 00:16:01 +04:00
mtime = root_entry.getmtime()
# Assert
2014-04-14 01:27:08 +04:00
assert_is_instance(ctime, type(None))
2014-04-14 00:16:01 +04:00
assert_is_instance(mtime, datetime.datetime)
2014-04-14 01:27:08 +04:00
assert_equal(ctime, None)
assert_equal(mtime.year, 2014)
2014-04-14 00:16:01 +04:00
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
print("ignore_all_except_last_line")
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
print("ok")
ole.close()
2014-04-11 15:53:33 +04:00
# End of file