Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 967c079

Browse files
committed
utf-8 everywhere
1 parent 30e494c commit 967c079

5 files changed

Lines changed: 12 additions & 10 deletions

File tree

src/linklint/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def lint_file(filepath: str, fix: bool, checks: set[str]) -> list[LintIssue]:
1313
"""
1414
# print(filepath)
1515
path = Path(filepath)
16-
content = path.read_text()
16+
content = path.read_text(encoding="utf-8")
1717
result = lint_content(content, fix, checks)
1818
if fix and result.fixed:
19-
path.write_text(result.content)
19+
path.write_text(result.content, encoding="utf-8")
2020
return result.issues
2121

2222

src/linklint/rsthelp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
def run_sphinx(content: str, buildername: str, extensions: list[str]) -> nodes.document:
1515
# Create minimal conf.py
16-
Path("conf.py").write_text(f"extensions = {extensions!r}\n")
16+
Path("conf.py").write_text(f"extensions = {extensions!r}\n", encoding="utf-8")
1717

1818
# Copy the RST file as index.rst
19-
Path("index.rst").write_text(content)
19+
Path("index.rst").write_text(content, encoding="utf-8")
2020

2121
app = Sphinx(
2222
srcdir=".",

tests/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def text_and_id(*, text: str, id: str = ""):
1717
# It's a file name
1818
assert not id, "Don't provide filename and id"
1919
id = text
20-
text = (PROJECT / "tests/data" / text).read_text()
20+
text = (PROJECT / "tests/data" / text).read_text(encoding="utf-8")
2121
assert id, "Test cases must have an id"
2222
return text, id

tests/summarize_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def handle_data(self, data: str) -> None:
133133

134134
def summarize_html_file(filename: str) -> str:
135135
parser = HtmlSummarizer()
136-
parser.feed(Path(filename).read_text())
136+
parser.feed(Path(filename).read_text(encoding="utf-8"))
137137
return parser.summary()
138138

139139

tests/test_extension.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
[r.name for r in Path("tests/data").glob("*.rst")],
2626
)
2727
def test_summarize_html(rst_file: str) -> None:
28-
rst = (PROJECT / "tests/data" / rst_file).read_text()
28+
rst = (PROJECT / "tests/data" / rst_file).read_text(encoding="utf-8")
2929
root = rst_file.removesuffix(".rst")
3030
with in_tempdir():
3131
doctree = run_sphinx(rst, buildername="html", extensions=["linklint.ext"])
@@ -34,19 +34,21 @@ def test_summarize_html(rst_file: str) -> None:
3434
# In case of needing to see what happened, copy the HTML etc to tmp.
3535
shutil.copytree("_build/_static", PROJECT / "tmp/html/_static", dirs_exist_ok=True)
3636
shutil.copyfile("_build/index.html", PROJECT / f"tmp/html/{root}.html")
37-
(PROJECT / f"tmp/html/{root}_summary.html").write_text(summary)
37+
(PROJECT / f"tmp/html/{root}_summary.html").write_text(summary, encoding="utf-8")
3838

3939
# Also run without the extension to understand Sphinx native behavior.
4040
run_sphinx(rst, buildername="html", extensions=[])
4141
shutil.copyfile("_build/index.html", PROJECT / f"tmp/html/{root}_nofix.html")
4242
nofix_summary = summarize_html_file("_build/index.html")
43-
(PROJECT / f"tmp/html/{root}_summary_nofix.html").write_text(nofix_summary)
43+
(PROJECT / f"tmp/html/{root}_summary_nofix.html").write_text(
44+
nofix_summary, encoding="utf-8"
45+
)
4446

4547
save_test_doctree(doctree)
4648
assert 'class="self-link"' not in summary, f"Self-links found in {root}.html"
4749
summary_file = PROJECT / f"tests/data/{root}_summary.html"
4850
if summary_file.exists():
49-
expected = summary_file.read_text()
51+
expected = summary_file.read_text(encoding="utf-8")
5052
else:
5153
expected = f"Summary {summary_file} doesn't exist" # pragma: only failure
5254

0 commit comments

Comments
 (0)