blob: 5341968098012d206f642b9e3ef24c5782239073 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
from pikepdf import Pdf
import pytest
@pytest.fixture
def congress(resources):
pdf = Pdf.open(resources / 'congress.pdf')
pdfimage = pdf.pages[0].Resources.XObject['/Im0']
return pdfimage, pdf
def test_get_equality_stream(congress):
image = congress[0]
assert image.ColorSpace == image['/ColorSpace'] == image.get('/ColorSpace')
assert image.ColorSpace == image.stream_dict.ColorSpace
with pytest.raises(AttributeError):
image.NoSuchKey
with pytest.raises(KeyError):
image['/NoSuchKey']
image.get('/NoSuchKey', 42) == 42
def test_get_equality_dict(congress):
page = congress[1].pages[0]
assert page.MediaBox == page['/MediaBox'] == page.get('/MediaBox')
with pytest.raises(RuntimeError):
page.stream_dict
with pytest.raises(AttributeError):
page.NoSuchKey
with pytest.raises(KeyError):
page['/NoSuchKey']
page.get('/NoSuchKey', 42) == 42
|