def test_PDFObjectId_eq(): a = pdf.PDFObjectId(1, 2) b = pdf.PDFObjectId(1, 3) c = pdf.PDFObjectId(1, 2) assert a != b assert a == c assert c != b assert hash(a) == hash(c)
def test_ParseObjectId(): p = pdf_parser.ParseObjectId() assert p.parse(b"ahjkdga") is None assert p.parse(b"521") is None assert p.parse(b"512 ada") is None assert p.parse(b"512[12 R]") is None assert p.parse(b"512 12 ") is None assert p.parse(b"512 12 basa") is None assert p.parse(b"512 12 RR") is None assert p.parse(b"512 12 R<") == (pdf.PDFObjectId(512, 12), 8) assert p.parse(b"512 12 R ahdsga") == (pdf.PDFObjectId(512, 12), 8)
def test_DocumentCatalog(): pages = pdf.PDFObjectId(5, 2) root = pdf_write.DocumentCatalog(pages) dic = root.object().data assert set(bytes(x) for x in dic) == {b"/Type", b"/Pages"} assert dic[pdf.PDFName("Type")] == pdf.PDFName("Catalog") assert bytes(dic[pdf.PDFName("Pages")]) == b"5 2 R"
def test_DictionaryConsumer(): p = pdf_parser.ParseDictionary() c = p.consumer() assert isinstance(c, pdf_parser.DictionaryConsumer) assert c.end(b"ajsdga") is None assert c.end(b">>ahsga") == 2 c.consume(pdf.PDFName("Mat")) c.consume(pdf.PDFObjectId(12, 0)) d = c.build() assert bytes(d[pdf.PDFName("Mat")]) == b"12 0 R"
def test_Page(page1): page = page1 page.parent = pdf.PDFObjectId(2, 5) dic = page.object().data assert set(bytes(x) for x in dic) == { b"/Type", b"/Parent", b"/Resources", b"/MediaBox", b"/Contents" } assert dic[pdf.PDFName("Type")] == pdf.PDFName("Page") assert bytes(dic[pdf.PDFName("Parent")]) == b"2 5 R" assert bytes(dic[pdf.PDFName("Resources")]) == b"<</Matt 7>>" assert bytes(dic[pdf.PDFName("MediaBox")]) == b"[0 1 20 50]" assert bytes(dic[pdf.PDFName("Contents")]) == b"3 2 R"
def page1(): mediabox = pdf_write.Rectangle(0, 1, 20, 50) resources = pdf.PDFDictionary([(pdf.PDFName("Matt"), pdf.PDFNumeric(7))]) contents = pdf.PDFObjectId(3, 2) return pdf_write.Page(mediabox, resources, contents)
def test_read_object_1(pdf1): p = pdf_read.PDF(pdf1) objs = p.object_at(10) assert len(objs) == 1 assert objs[0][pdf.PDFName("Pages")] == pdf.PDFObjectId(2, 0) assert objs[0][pdf.PDFName("Type")] == pdf.PDFName("Catalog")
def test_PDFObjectId(): obj = pdf.PDFObjectId(2, 0) assert obj.number == 2 assert obj.generation == 0 assert repr(obj) == "PDFObjectId(2, 0)" assert bytes(obj) == b"2 0 R"