diff options
Diffstat (limited to 'tests/docx')
| -rw-r--r-- | tests/docx/files_tests.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/docx/files_tests.py b/tests/docx/files_tests.py index c1e15dc..56dc69a 100644 --- a/tests/docx/files_tests.py +++ b/tests/docx/files_tests.py @@ -1,7 +1,7 @@ from nose.tools import istest, assert_equal -from mammoth.docx.files import Files -from ..testing import test_path +from mammoth.docx.files import Files, InvalidFileReferenceError +from ..testing import test_path, assert_raises @istest @@ -23,3 +23,22 @@ def can_open_files_with_relative_uri(): assert_equal(bytes, type(contents)) with open(test_path("tiny-picture.png"), "rb") as source_file: assert_equal(source_file.read(), contents) + + +@istest +def error_is_raised_if_relative_uri_cannot_be_opened(): + files = Files("/tmp") + error = assert_raises(InvalidFileReferenceError, lambda: files.open("not-a-real-file.png")) + expected_message = ( + "could not open external image: 'not-a-real-file.png' (document directory: '/tmp')\n" + + "[Errno 2] No such file or directory: '/tmp/not-a-real-file.png'" + ) + assert_equal(expected_message, str(error)) + + +@istest +def error_is_raised_if_file_uri_cannot_be_opened(): + files = Files("/tmp") + error = assert_raises(InvalidFileReferenceError, lambda: files.open("file:///not-a-real-file.png")) + expected_message = "could not open external image: 'file:///not-a-real-file.png' (document directory: '/tmp')\n" + assert str(error).startswith(expected_message) |
