Exemplo n.º 1
0
def test_derive_annotations_works_with_nested_content():
    para = convert_node(
        f.para(content=[
            f.external_link('http://one.org', [
                f.text('foo'),
                f.external_link('http://two.org', [f.text('bar')]),
                f.text('baz'),
                f.external_link('http://three.org', [f.text('quux')]),
            ])
        ]))

    annos = derive_annotations(para)

    assert len(annos) == 1

    links = annos[ExternalLink]
    assert len(links) == 3

    one = links[0]
    assert para.text[one.start:one.end] == 'foobarbazquux'

    two = links[1]
    assert para.text[two.start:two.end] == 'bar'

    three = links[2]
    assert para.text[three.start:three.end] == 'quux'
Exemplo n.º 2
0
def test_derive_annotations_raises_err_on_invalid_footnote_citation():
    para = convert_node(
        f.para(
            content=[f.footnote_citation([f.text('3')])],
            children=[f.footnote(4, content=[f.text('Hi I am a footnote')])]))

    with pytest.raises(ValueError,
                       match="unable to find footnote for citation 3"):
        derive_annotations(para)
Exemplo n.º 3
0
def test_convert_paragraph_works():
    para_primitive = f.para(content=[
        f.text('Hello '),
        f.external_link('http://example.org/', [f.text('there')])
    ])
    para = convert_node(para_primitive)

    assert para.node_type == 'para'
    assert para.text == 'Hello there'
    assert para.json_content == para_primitive['content']
Exemplo n.º 4
0
def test_derive_annotations_works_with_footnote_citation():
    para = convert_node(
        f.para(
            content=[f.footnote_citation([f.text('3')])],
            children=[f.footnote(3, content=[f.text('Hi I am a footnote')])]))

    annos = derive_annotations(para)

    assert len(annos) == 1
    assert len(annos[FootnoteCitation]) == 1
    cit = annos[FootnoteCitation][0]
    assert cit.start == 0
    assert cit.end == 1
    assert cit.footnote_node.text == 'Hi I am a footnote'
Exemplo n.º 5
0
def test_derive_annotations_works_with_external_link():
    annos = derive_annotations(
        convert_node(
            f.para(content=[
                f.text('Hello '),
                f.external_link('http://example.org/', [f.text('there')])
            ])))

    assert len(annos) == 1
    assert len(annos[ExternalLink]) == 1
    link = annos[ExternalLink][0]
    assert link.href == 'http://example.org/'
    assert link.start == len('Hello ')
    assert link.end == link.start + len('there')
Exemplo n.º 6
0
def test_derive_annotations_works_on_children():
    para = convert_node(
        f.para(content=[f.text('hi')],
               children=[
                   f.para(content=[
                       f.external_link('http://one.org', [f.text('blah')])
                   ])
               ]))

    annos = derive_annotations(para)

    assert len(annos) == 1
    links = annos[ExternalLink]
    assert len(links) == 1
Exemplo n.º 7
0
def test_derive_annotations_works_with_cite():
    annos = derive_annotations(
        convert_node(
            f.para(content=[
                f.text('Hello '),
                f.cite(
                    [f.text('Federal STEM Education 5-Year Strategic Plan')])
            ])))

    assert len(annos) == 1
    assert len(annos[Cite]) == 1
    cite = annos[Cite][0]
    assert cite.start == len('Hello ')
    assert cite.end == cite.start + len(
        'Federal STEM Education 5-Year Strategic Plan')