aboutsummaryrefslogtreecommitdiff
path: root/tests/docx/files_tests.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-09-06 18:08:58 +0100
committerMichael Williamson <mike@zwobble.org>2015-09-06 18:08:58 +0100
commit256806a3dd10ccdfb1295181d09af7655c05fa29 (patch)
tree682532ac1eaf1718c03430e5b61e20dfe6b03d7d /tests/docx/files_tests.py
parentcff7a81ce9c49971ca94fc8fe74430338e563836 (diff)
Capture errors on trying to open file URIs
Diffstat (limited to 'tests/docx/files_tests.py')
-rw-r--r--tests/docx/files_tests.py23
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)