Specify encoding to avoid EncodingWarning

This commit is contained in:
Adam Turner 2024-07-29 18:21:01 +01:00
parent b0485f9323
commit a4102a7507
3 changed files with 4 additions and 3 deletions

View File

@ -6,14 +6,14 @@ from sphinx.util.fileutil import copy_asset
def _copy_asset_overwrite_hook(app):
css = app.outdir / '_static' / 'custom-styles.css'
# html_static_path is copied by default
assert css.read_text() == '/* html_static_path */\n', 'invalid default text'
assert css.read_text(encoding='utf-8') == '/* html_static_path */\n', 'invalid default text'
# warning generated by here
copy_asset(
Path(__file__).parent.joinpath('myext_static', 'custom-styles.css'),
app.outdir / '_static',
)
# This demonstrates that no overwriting occurs
assert css.read_text() == '/* html_static_path */\n', 'file overwritten!'
assert css.read_text(encoding='utf-8') == '/* html_static_path */\n', 'file overwritten!'
return []

View File

@ -240,6 +240,7 @@ def test_raw_node(app: SphinxTestApp) -> None:
index.write_text(
".. raw:: 'html'\n"
" :url: http://{address}/".format(address=address),
encoding='utf-8',
)
app.build()

View File

@ -696,7 +696,7 @@ def test_autogen(rootdir, tmp_path):
def test_autogen_remove_old(rootdir, tmp_path):
"""Test the ``--remove-old`` option."""
tmp_path.joinpath('other.rst').write_text('old content')
tmp_path.joinpath('other.rst').write_text('old content', encoding='utf-8')
with chdir(rootdir / 'test-templating'):
args = ['-o', str(tmp_path), '-t', '.', 'autosummary_templating.txt']
autogen_main(args)