def test_autodoc(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "doc_cite.html").read_text()
    labels = [
        'One', 'Two', 'Thr', 'Fou', 'Fiv', 'Six', 'Sev', 'Eig', 'Nin', 'Ten',
        'Ele'
    ]
    titles = [
        'Een', 'Twee', 'Drie', 'Vier', 'Vijf', 'Zes', 'Zeven', 'Acht', 'Negen',
        'Tien', 'Elf'
    ]
    for label, title in zip(labels, titles):
        assert len(common.html_citation_refs(label=label).findall(output)) == 1
        assert len(common.html_citations(label=label).findall(output)) == 1
        match_ref = common.html_citation_refs(label=label).search(output)
        match = common.html_citations(label=label).search(output)
        assert match_ref
        assert match
        assert match_ref.group('refid') == match.group('id_')
        assert title in match.group('text')
    output2 = (app.outdir / "doc_footcite.html").read_text()
    assert len(common.html_footnote_refs().findall(output2)) == 11
    for title in titles:
        text = ".*" + title + ".*"
        assert len(common.html_footnotes(text=text).findall(output2)) == 1
        match = common.html_footnotes(text=text).search(output2)
        assert match
        id_ = match.group('id_')
        assert len(common.html_footnote_refs(refid=id_).findall(output2)) == 1
def test_backrefs(app, warning):
    app.build()
    output = (app.outdir / "index.html").read_text()
    match = common.html_citations(text=".*Test zero.*").search(output)
    assert match
    assert match.group('backref') is None
    assert match.group('backref1') is None
    assert match.group('backref2') is None
    assert match.group('backref3') is None
    match = common.html_citations(text=".*Test one.*").search(output)
    assert match
    assert match.group('backref') is not None
    assert match.group('backref1') is None
    assert match.group('backref2') is None
    assert match.group('backref3') is None
    match = common.html_citations(text=".*Test two.*").search(output)
    assert match
    assert match.group('backref') is None
    assert match.group('backref1') is not None
    assert match.group('backref2') is not None
    assert match.group('backref3') is None
    match = common.html_citations(text=".*Test three.*").search(output)
    assert match
    assert match.group('backref') is None
    assert match.group('backref1') is not None
    assert match.group('backref2') is not None
    assert match.group('backref3') is not None
def test_list_citation(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.html").read_text()
    assert common.html_citations(label='1', text='.*Akkerdju.*').search(output)
    assert common.html_citations(label='2', text='.*Bro.*').search(output)
    assert common.html_citations(label='3', text='.*Chap.*').search(output)
    assert common.html_citations(label='4', text='.*Dude.*').search(output)
Exemplo n.º 4
0
def test_duplicate_label(app, warning):
    # see github issue 14
    app.build()
    assert 'duplicate label "1" for keys "Test" and "Test2"' \
           in warning.getvalue()
    output = (app.outdir / "doc1.html").read_text()
    output2 = (app.outdir / "doc2.html").read_text()
    assert common.html_citations(label="1").search(output)
    assert common.html_citations(label="1").search(output2)
def test_bibliography_style_label_1(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.html").read_text()
    # the custom style uses keys as labels
    # citations
    assert len(common.html_citations(
        label='myfancybibtexkey').findall(output)) == 1
    assert len(common.html_citations(
        label='myotherfancybibtexkey').findall(output)) == 1
    assert len(common.html_citation_refs(
        label='myfancybibtexkey').findall(output)) == 1
    assert len(common.html_citation_refs(
        label='myotherfancybibtexkey').findall(output)) == 1
def test_bibliography_label_prefix_2(app, warning):
    doc1_refs = {'AFM12', 'ABlu83', 'AGIH02', 'AWS14'}
    doc1_cites = {'ABlu83', 'AFM12', 'AGIH02', 'AWS14'}
    doc2_refs = {'BShi13'}
    doc2_cites = {'BShi13'}
    sum_refs = {'CMcMahonKM10', 'CRMM11', 'CRM09', 'CMM03', 'CHdJMD13',
                'AFM12'}
    sum_cites = {'CMcMahonKM10', 'CRMM11', 'CRM09', 'CMM03', 'CHdJMD13'}
    app.build()
    assert not warning.getvalue()
    output1 = (app.outdir / "doc1.html").read_text()
    assert doc1_refs == citation_refs(output1)
    assert doc1_cites == citations(output1)
    output2 = (app.outdir / "doc2.html").read_text()
    assert doc2_refs == citation_refs(output2)
    assert doc2_cites == citations(output2)
    output3 = (app.outdir / "summary.html").read_text()
    assert sum_refs == citation_refs(output3)
    assert sum_cites == citations(output3)
    # check citation reference from summary to doc1
    match1 = common.html_citations(label='AFM12').search(output1)
    match3 = common.html_citation_refs(label='AFM12').search(output3)
    assert match1
    assert match3
    assert match1.group('id_') == match3.group('refid')
    assert match3.group('refdoc') == 'doc1.html'
Exemplo n.º 7
0
def test_duplicate_nearly_identical_entries(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.html").read_text()
    cits = list(common.html_citations().finditer(output))
    cit_refs = list(common.html_citation_refs().finditer(output))
    assert len(cits) == len(cit_refs) == 2
    assert ({cit.group('label')
             for cit in cits} ==
            {cit_ref.group('label')
             for cit_ref in cit_refs} == {'xyz19a', 'xyz19b'})
def test_citation_multiple_keys(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.html").read_text()
    cits = {
        match.group('label')
        for match in common.html_citations().finditer(output)
    }
    citrefs = {
        match.group('label')
        for match in common.html_citation_refs().finditer(output)
    }
    assert {"App", "Bra"} == cits == citrefs
Exemplo n.º 9
0
def test_duplicate_nearly_identical_keys(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.html").read_text()
    # assure both citations and citation references are present
    assert common.html_citation_refs(label='Smi').search(output)
    assert common.html_citation_refs(label='Pop').search(output)
    assert common.html_citation_refs(label='Ein').search(output)
    assert common.html_citations(label='Smi').search(output)
    assert common.html_citations(label='Pop').search(output)
    assert common.html_citations(label='Ein').search(output)
    # assure distinct ids for citations
    ids = {
        match.group('id_')
        for match in common.html_citations().finditer(output)
    }
    refids = {
        match.group('refid')
        for match in common.html_citation_refs().finditer(output)
    }
    assert None not in ids
    assert len(ids) == 3
    assert ids == refids
Exemplo n.º 10
0
def test_duplicate_citation(app, warning):
    app.build()
    warning.seek(0)
    warnings = list(warning.readlines())
    assert len(warnings) == 1
    assert 'duplicate citation for key "Test"' in warnings[0]
    # assure distinct citation ids
    output = (app.outdir / "index.html").read_text()
    ids = [
        match.group('id_')
        for match in common.html_citations().finditer(output)
    ]
    assert len(ids) == 2  # just to check ids are found
    assert len(set(ids)) == 2, "citation ids not unique"
Exemplo n.º 11
0
def test_duplicate_citation_id(app, warning):
    app.build()
    assert not warning.getvalue()
    output = (app.outdir / "index.html").read_text()
    user_ids = {'id1', 'id2', 'id3'}
    ids = {
        match.group('id_')
        for match in common.html_citations().finditer(output)
    }
    refids = {
        match.group('refid')
        for match in common.html_citation_refs().finditer(output)
    }
    assert ids == refids
    assert len(ids) == 1
    assert not (user_ids & ids)
def test_bibfiles_out_of_date(make_app, app_params):
    args, kwargs = app_params
    app = make_app(*args, **kwargs)
    app.build()
    status = app._status.getvalue()
    # not found, parsing
    assert re.search(status_not_found, status) is not None
    assert re.search(status_up_to_date, status) is None
    assert re.search(status_out_of_date, status) is None
    assert re.search(status_parsing, status) is not None
    output = (app.outdir / "index.html").read_text()
    assert common.html_citations(label='1', text='.*Akkerdju.*').search(output)
    assert common.html_citations(label='2', text='.*Bro.*').search(output)
    assert common.html_citations(label='3', text='.*Chap.*').search(output)
    assert common.html_citations(label='4', text='.*Dude.*').search(output)
    # wait to ensure different timestamp
    time.sleep(0.1)
    shutil.copyfile((app.srcdir / 'test_new.xxx'), (app.srcdir / 'test.bib'))
    app = make_app(*args, **kwargs)
    app.build()
    status = app._status.getvalue()
    # out of date, parsing
    assert re.search(status_not_found, status) is None
    assert re.search(status_up_to_date, status) is None
    assert re.search(status_out_of_date, status) is not None
    assert re.search(status_parsing, status) is not None
    output = (app.outdir / "index.html").read_text()
    assert common.html_citations(label='1', text='.*Eminence.*').search(output)
    assert common.html_citations(label='2', text='.*Frater.*').search(output)
    assert common.html_citations(label='3', text='.*Giggles.*').search(output)
    assert common.html_citations(label='4', text='.*Handy.*').search(output)
    # wait to ensure different timestamp
    time.sleep(0.1)
    shutil.copyfile((app.srcdir / 'index_new.xxx'), (app.srcdir / 'index.rst'))
    app = make_app(*args, **kwargs)
    app.build()
    status = app._status.getvalue()
    # up to date
    assert re.search(status_not_found, status) is None
    assert re.search(status_up_to_date, status) is not None
    assert re.search(status_out_of_date, status) is None
    assert re.search(status_parsing, status) is None
def citations(output):
    return {match.group('label')
            for match in common.html_citations().finditer(output)}