예제 #1
0
def test_page_destination(resources, page_num, page_loc, kwargs):
    # @given precludes use of outlines_doc fixture - causes hypothesis health check to
    # fail
    with Pdf.open(resources / 'outlines.pdf') as doc:
        page_ref = doc.pages[page_num]

        if page_loc == 'invalid':
            with pytest.raises(ValueError, match='unsupported page location'):
                make_page_destination(doc, page_num, page_loc, **kwargs)
            return

        dest = make_page_destination(doc, page_num, page_loc, **kwargs)
        if isinstance(page_loc, PageLocation):
            loc_str = page_loc.name
        else:
            loc_str = page_loc
        if loc_str == 'XYZ':
            args = 'left', 'top', 'zoom'
        elif loc_str == 'FitH':
            args = ('top', )
        elif loc_str == 'FitV':
            args = ('left', )
        elif loc_str == 'FitR':
            args = 'left', 'bottom', 'right', 'top'
        elif loc_str == 'FitBH':
            args = ('top', )
        elif loc_str == 'FitBV':
            args = ('left', )
        else:
            args = ()
        expected_dest = [page_ref, Name(f'/{loc_str}')]
        expected_dest.extend(kwargs.get(k, 0) for k in args)
        assert dest == expected_dest
예제 #2
0
def test_page_destination(resources, page_num, page_loc, kwargs):
    doc = Pdf.open(resources / 'outlines.pdf')
    page_ref = doc.pages[page_num]
    dest = make_page_destination(doc, page_num, page_loc, **kwargs)
    if isinstance(page_loc, PageLocation):
        loc_str = page_loc.name
    else:
        loc_str = page_loc
    if loc_str == 'XYZ':
        args = 'left', 'top', 'zoom'
    elif loc_str == 'FitH':
        args = ('top', )
    elif loc_str == 'FitV':
        args = ('left', )
    elif loc_str == 'FitR':
        args = 'left', 'bottom', 'right', 'top'
    elif loc_str == 'FitBH':
        args = ('top', )
    elif loc_str == 'FitBV':
        args = ('left', )
    else:
        args = ()
    expected_dest = [page_ref, Name('/{0}'.format(loc_str))]
    expected_dest.extend(kwargs.get(k, 0) for k in args)
    assert dest == expected_dest
예제 #3
0
def test_outlineitem_str(resources):
    with Pdf.open(resources / 'outlines.pdf') as pdf:
        with pdf.open_outline() as outline:
            assert str(outline.root[0]) == '[+] One -> <Action>'
            assert str(outline.root[1]) == '[ ] Two -> <Action>'
            item = OutlineItem('Test', make_page_destination(pdf, 0))
            assert '[ ] Test -> 1' == str(item)
예제 #4
0
def test_outlineitem_str(outlines_doc):
    with outlines_doc.open_outline() as outline:
        assert str(outline.root[0]) == '[+] One -> <Action>'
        assert str(outline.root[1]) == '[ ] Two -> <Action>'

        outline.root[0].is_closed = False
        assert str(outline.root[0]) == '[-] One -> <Action>'

        item = OutlineItem('Test', make_page_destination(outlines_doc, 0))
        assert '[ ] Test -> 1' == str(item)

        assert str(outline) != ''