Skip to content

Commit ddb2569

Browse files
tests/test_general.py: fixup tests to match new Document open code.
1 parent a06a587 commit ddb2569

1 file changed

Lines changed: 11 additions & 17 deletions

File tree

tests/test_general.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,12 @@ def test_pdfstring():
141141

142142

143143
def test_open_exceptions():
144-
try:
145-
pymupdf.open(filename, filetype="xps")
146-
except RuntimeError as e:
147-
assert repr(e).startswith("FileDataError")
148-
else:
149-
assert 0
144+
path = os.path.normpath(f'{__file__}/../../tests/resources/001003ED.pdf')
145+
doc = pymupdf.open(path, filetype="xps")
146+
assert 'PDF' in doc.metadata["format"]
150147

151-
try:
152-
pymupdf.open(filename, filetype="xxx")
153-
except Exception as e:
154-
assert repr(e).startswith("ValueError")
155-
else:
156-
assert 0
148+
doc = pymupdf.open(path, filetype="xxx")
149+
assert 'PDF' in doc.metadata["format"]
157150

158151
try:
159152
pymupdf.open("x.y")
@@ -165,8 +158,9 @@ def test_open_exceptions():
165158
try:
166159
pymupdf.open(stream=b"", filetype="pdf")
167160
except RuntimeError as e:
168-
assert repr(e).startswith("EmptyFileError")
161+
assert repr(e).startswith("EmptyFileError"), f'{repr(e)=}'
169162
else:
163+
print(f'{doc.metadata["format"]=}')
170164
assert 0
171165

172166

@@ -1361,7 +1355,7 @@ def check(filename=None, stream=None, filetype=None, exception=None):
13611355
assert 0, \
13621356
f'Incorrect exception, expected {etype}, received {type(e)=}.'
13631357
else:
1364-
assert 0, f'Did not received exception, expected {etype=}.'
1358+
assert 0, f'Did not received exception, expected {etype=}. {filename=} {stream=} {filetype=} {exception=}'
13651359
else:
13661360
document = pymupdf.open(filename=filename, stream=stream, filetype=filetype)
13671361
return document
@@ -1406,7 +1400,7 @@ def check(filename=None, stream=None, filetype=None, exception=None):
14061400
re.escape(f'mupdf.{etype2}: code=7: cannot recognize zip archive'),
14071401
re.escape(f'pymupdf.FileDataError: Failed to open file {path!r} as type {filetype!r}.'),
14081402
)
1409-
check(path, filetype=filetype, exception=(etype, eregex))
1403+
check(path, filetype=filetype, exception=None)
14101404

14111405
path = f'{resources}/chinese-tables.pickle'
14121406
etype = pymupdf.FileDataError
@@ -1559,9 +1553,9 @@ def test_3859():
15591553
def test_3905():
15601554
data = b'A,B,C,D\r\n1,2,1,2\r\n2,2,1,2\r\n'
15611555
try:
1562-
document = pymupdf.open(stream=data)
1556+
document = pymupdf.open(stream=data, filetype='pdf')
15631557
except pymupdf.FileDataError as e:
1564-
pass
1558+
print(f'test_3905(): e: {e}')
15651559
else:
15661560
assert 0
15671561
wt = pymupdf.TOOLS.mupdf_warnings()

0 commit comments

Comments
 (0)