Skip to content

Commit

Permalink
Fix test encoding issues on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmtroffaes committed Aug 22, 2023
1 parent e34b67c commit a40c4ba
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion test/test_bibfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_bibfiles_missing_conf(make_app, app_params) -> None:
def test_bibfiles_encoding(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding='utf-8-sig')
assert u"Äpplé" in output


Expand Down
8 changes: 4 additions & 4 deletions test/test_bibliography.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ def test_bibliography_label_prefix_2(app, warning) -> None:
sum_cites = {'CMcMahonKM10', 'CRMM11', 'CRM09', 'CMM03', 'CHdJMD13'}
app.build()
assert not warning.getvalue()
output1 = (app.outdir / "doc1.html").read_text()
output1 = (app.outdir / "doc1.html").read_text(encoding="utf-8-sig")
# use <= instead of == as there are some extra reference nodes
assert doc1_refs <= citation_refs(output1)
assert doc1_cites == citations(output1)
output2 = (app.outdir / "doc2.html").read_text()
output2 = (app.outdir / "doc2.html").read_text(encoding="utf-8-sig")
assert doc2_refs <= citation_refs(output2)
assert doc2_cites == citations(output2)
output3 = (app.outdir / "summary.html").read_text()
output3 = (app.outdir / "summary.html").read_text(encoding="utf-8-sig")
assert sum_refs <= citation_refs(output3)
assert sum_cites == citations(output3)
# check citation reference from summary to doc1
Expand All @@ -151,7 +151,7 @@ def test_bibliography_label_prefix_2(app, warning) -> None:
def test_bibliography_order_unsorted(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
assert re.search(
r'<p>A\.\sFirst\. Test 1\.</p>.*<p>B\.\sSecond\. Test 2\.</p>',
output, re.DOTALL)
Expand Down
30 changes: 15 additions & 15 deletions test/test_citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_citation_mixed(app, warning) -> None:
def test_citation_multiple_keys(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
cits = {match.group('label')
for match in html_citations().finditer(output)}
citrefs = {match.group('label')
Expand All @@ -56,7 +56,7 @@ def test_citation_multiple_keys(app, warning) -> None:
def test_citation_any_role(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
cits = {match.group('label')
for match in html_citations().finditer(output)}
citrefs = {match.group('label')
Expand All @@ -73,7 +73,7 @@ def find_label(output: str, label: str):
def test_citation_no_author_no_key(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
find_label(output, "<em>Software projects built on Mesos</em>, 2015")
find_label(output, "2015")
find_label(output, "Mandel, 2009")
Expand All @@ -89,7 +89,7 @@ def test_citation_no_author_no_key(app, warning) -> None:
def test_citation_whitespace(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
# ensure Man09 is cited
assert len(html_citation_refs(label='Fir').findall(output)) == 1
assert len(html_citation_refs(label='Sec').findall(output)) == 1
Expand All @@ -106,7 +106,7 @@ def test_citation_from_orphan(app, warning) -> None:
def test_citation_roles_label(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.txt").read_text()
output = (app.outdir / "index.txt").read_text(encoding="utf-8-sig")
tests = [
("p", " [dDEF03] "),
("ps", " [dDEF03] "),
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_citation_roles_label(app, warning) -> None:
def test_citation_roles_authoryear(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.txt").read_text()
output = (app.outdir / "index.txt").read_text(encoding="utf-8-sig")
tests = [
("p", " [de Du *et al.*, 2003] "),
("ps", " [de Du, Em, and Fa, 2003] "),
Expand Down Expand Up @@ -243,7 +243,7 @@ def test_citation_roles_authoryear(app, warning) -> None:
def test_citation_roles_super(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
# just a cursory check that superscript references are present
assert '<sup><a class="reference internal" href="#' in output

Expand Down Expand Up @@ -299,7 +299,7 @@ class CustomReferenceStyle(AuthorYearReferenceStyle):
def test_citation_style_custom(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.txt").read_text()
output = (app.outdir / "index.txt").read_text(encoding="utf-8-sig")
tests = [
("p", " (de Du et al 2003) "),
("ps", " (de Du & Em & Fa 2003) "),
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_citation_style_custom(app, warning) -> None:
def test_citation_style_round_brackets(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.txt").read_text()
output = (app.outdir / "index.txt").read_text(encoding="utf-8-sig")
assert "(Evensen, 2003)" in output
assert "Evensen (2003)" in output

Expand All @@ -374,9 +374,9 @@ def test_citation_style_round_brackets(app, warning) -> None:
def test_citation_toctree(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output1 = (app.outdir / "adoc1.html").read_text()
output2 = (app.outdir / "adoc2.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
output1 = (app.outdir / "adoc1.html").read_text(encoding="utf-8-sig")
output2 = (app.outdir / "adoc2.html").read_text(encoding="utf-8-sig")
assert len(html_citations(label='1').findall(output)) == 1
assert len(html_citation_refs(label='1').findall(output1)) == 1
assert len(html_docutils_citation_refs(
Expand All @@ -388,7 +388,7 @@ def test_citation_toctree(app, warning) -> None:
def test_citation_tooltip(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
assert len(html_citations(label='tes').findall(output)) == 1
assert len(html_citation_refs(
label='tes', title=r"The title\.").findall(output)) == 1
Expand All @@ -399,7 +399,7 @@ def test_citation_tooltip(app, warning) -> None:
def test_citation_tooltip2(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
assert len(html_citations(label='tes').findall(output)) == 1
assert len(html_citation_refs(
label='tes', title=None).findall(output)) == 1
Expand All @@ -420,7 +420,7 @@ def get_misc_template(self, e):
def test_citation_tooltip3(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text()
output = (app.outdir / "index.html").read_text(encoding="utf-8-sig")
assert len(html_citations(label='tes').findall(output)) == 1
assert len(html_citation_refs(
label='tes', title='whoop whoop').findall(output)) == 1
4 changes: 2 additions & 2 deletions test/test_footcite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def test_footcite_roles(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.txt").read_text()
output = (app.outdir / "index.txt").read_text(encoding="utf-8-sig")
tests = [
("p", " [1] "),
("ps", " [1] "),
Expand Down Expand Up @@ -75,7 +75,7 @@ class CustomReferenceStyle(FootReferenceStyle):
def test_footcite_style_custom(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.txt").read_text()
output = (app.outdir / "index.txt").read_text(encoding="utf-8-sig")
tests = [
("p", " [1] "),
("ps", " [1] "),
Expand Down
4 changes: 2 additions & 2 deletions test/test_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
def test_latex_refs(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "test.tex").read_text()
output = (app.outdir / "test.tex").read_text(encoding="utf-8-sig")
assert len(latex_citations().findall(output)) == 1
assert len(latex_citation_refs().findall(output)) == 1
match = latex_citations().search(output)
Expand All @@ -22,7 +22,7 @@ def test_latex_refs(app, warning) -> None:
def test_latex_multidoc(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "test.tex").read_text()
output = (app.outdir / "test.tex").read_text(encoding="utf-8-sig")
assert len(latex_citations().findall(output)) == 1
assert len(latex_citation_refs().findall(output)) == 1
match = latex_citations().search(output)
Expand Down

0 comments on commit a40c4ba

Please sign in to comment.