summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Turner <9087854+aa-turner@users.noreply.github.com>2022-04-27 03:11:08 +0100
committerAdam Turner <9087854+aa-turner@users.noreply.github.com>2022-04-27 03:11:08 +0100
commit4674cc11c83c302102c167123de00a68b3d5dd88 (patch)
tree38c7a19f3621b4566de8a7eeefe64d4d72112d2a
parent24e3b7c8c8c0a2d01ec2d2d4d04105bcb565e440 (diff)
downloadsphinx-git-4674cc11c83c302102c167123de00a68b3d5dd88.tar.gz
`.write_text(...)` -> `.write_text(..., encoding='utf8')`
-rw-r--r--tests/test_build.py6
-rw-r--r--tests/test_build_html.py4
-rw-r--r--tests/test_builder.py2
-rw-r--r--tests/test_config.py6
-rw-r--r--tests/test_ext_apidoc.py32
-rw-r--r--tests/test_ext_autodoc_configs.py20
-rw-r--r--tests/test_ext_autosummary.py4
-rw-r--r--tests/test_project.py2
-rw-r--r--tests/test_setup_command.py11
-rw-r--r--tests/test_toctree.py2
-rw-r--r--tests/test_util_fileutil.py10
-rw-r--r--tests/test_util_i18n.py22
12 files changed, 65 insertions, 56 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
index c31cc3263..fd123e294 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -37,14 +37,14 @@ def nonascii_srcdir(request, rootdir, sphinx_test_tempdir):
(srcdir / (test_name + '.txt')).write_text(dedent("""
nonascii file name page
=======================
- """))
+ """), encoding='utf8')
root_doc = srcdir / 'index.txt'
root_doc.write_text(root_doc.read_text(encoding='utf8') + dedent("""
.. toctree::
%(test_name)s/%(test_name)s
- """ % {'test_name': test_name}))
+ """ % {'test_name': test_name}), encoding='utf8')
return srcdir
@@ -63,7 +63,7 @@ def test_build_all(requests_head, make_app, nonascii_srcdir, buildername):
def test_root_doc_not_found(tempdir, make_app):
- (tempdir / 'conf.py').write_text('')
+ (tempdir / 'conf.py').write_text('', encoding='utf8')
assert tempdir.listdir() == ['conf.py']
app = make_app('dummy', srcdir=tempdir)
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 74051cd6e..571b6202c 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -696,7 +696,7 @@ def test_numfig_without_numbered_toctree_warn(app, warning):
# remove :numbered: option
index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
index = re.sub(':numbered:.*', '', index)
- (app.srcdir / 'index.rst').write_text(index)
+ (app.srcdir / 'index.rst').write_text(index, encoding='utf8')
app.builder.build_all()
warnings = warning.getvalue()
@@ -784,7 +784,7 @@ def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect)
# remove :numbered: option
index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
index = re.sub(':numbered:.*', '', index)
- (app.srcdir / 'index.rst').write_text(index)
+ (app.srcdir / 'index.rst').write_text(index, encoding='utf8')
if not app.outdir.listdir():
app.build()
diff --git a/tests/test_builder.py b/tests/test_builder.py
index c866a9720..1ff8aea05 100644
--- a/tests/test_builder.py
+++ b/tests/test_builder.py
@@ -13,7 +13,7 @@ def test_incremental_reading(app):
assert 'subdir/excluded' not in app.env.found_docs
# before second reading, add, modify and remove source files
- (app.srcdir / 'new.txt').write_text('New file\n========\n')
+ (app.srcdir / 'new.txt').write_text('New file\n========\n', encoding='utf8')
app.env.all_docs['index'] = 0 # mark as modified
(app.srcdir / 'autodoc.txt').unlink()
diff --git a/tests/test_config.py b/tests/test_config.py
index 7981dd7a9..3d72a6b0f 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -138,7 +138,7 @@ def test_errors_warnings(logger, tempdir):
assert 'conf.py' in str(excinfo.value)
# test the automatic conversion of 2.x only code in configs
- (tempdir / 'conf.py').write_text('project = u"Jägermeister"\n')
+ (tempdir / 'conf.py').write_text('project = u"Jägermeister"\n', encoding='utf8')
cfg = Config.read(tempdir, {}, None)
cfg.init_values()
assert cfg.project == 'Jägermeister'
@@ -147,7 +147,7 @@ def test_errors_warnings(logger, tempdir):
def test_errors_if_setup_is_not_callable(tempdir, make_app):
# test the error to call setup() in the config file
- (tempdir / 'conf.py').write_text('setup = 1')
+ (tempdir / 'conf.py').write_text('setup = 1', encoding='utf8')
with pytest.raises(ConfigError) as excinfo:
make_app(srcdir=tempdir)
assert 'callable' in str(excinfo.value)
@@ -155,7 +155,7 @@ def test_errors_if_setup_is_not_callable(tempdir, make_app):
@pytest.fixture
def make_app_with_empty_project(make_app, tempdir):
- (tempdir / 'conf.py').write_text('')
+ (tempdir / 'conf.py').write_text('', encoding='utf8')
def _make_app(*args, **kw):
kw.setdefault('srcdir', path(tempdir))
diff --git a/tests/test_ext_apidoc.py b/tests/test_ext_apidoc.py
index 5e8789a8f..1d705e182 100644
--- a/tests/test_ext_apidoc.py
+++ b/tests/test_ext_apidoc.py
@@ -402,8 +402,8 @@ def test_subpackage_in_toc(make_app, apidoc):
def test_private(tempdir):
- (tempdir / 'hello.py').write_text('')
- (tempdir / '_world.py').write_text('')
+ (tempdir / 'hello.py').write_text('', encoding='utf8')
+ (tempdir / '_world.py').write_text('', encoding='utf8')
# without --private option
apidoc_main(['-o', tempdir, tempdir])
@@ -421,8 +421,8 @@ def test_private(tempdir):
def test_toc_file(tempdir):
outdir = path(tempdir)
(outdir / 'module').makedirs()
- (outdir / 'example.py').write_text('')
- (outdir / 'module' / 'example.py').write_text('')
+ (outdir / 'example.py').write_text('', encoding='utf8')
+ (outdir / 'module' / 'example.py').write_text('', encoding='utf8')
apidoc_main(['-o', tempdir, tempdir])
assert (outdir / 'modules.rst').exists()
@@ -438,7 +438,7 @@ def test_toc_file(tempdir):
def test_module_file(tempdir):
outdir = path(tempdir)
- (outdir / 'example.py').write_text('')
+ (outdir / 'example.py').write_text('', encoding='utf8')
apidoc_main(['-o', tempdir, tempdir])
assert (outdir / 'example.rst').exists()
@@ -454,7 +454,7 @@ def test_module_file(tempdir):
def test_module_file_noheadings(tempdir):
outdir = path(tempdir)
- (outdir / 'example.py').write_text('')
+ (outdir / 'example.py').write_text('', encoding='utf8')
apidoc_main(['--no-headings', '-o', tempdir, tempdir])
assert (outdir / 'example.rst').exists()
@@ -468,11 +468,11 @@ def test_module_file_noheadings(tempdir):
def test_package_file(tempdir):
outdir = path(tempdir)
(outdir / 'testpkg').makedirs()
- (outdir / 'testpkg' / '__init__.py').write_text('')
- (outdir / 'testpkg' / 'hello.py').write_text('')
- (outdir / 'testpkg' / 'world.py').write_text('')
+ (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
+ (outdir / 'testpkg' / 'hello.py').write_text('', encoding='utf8')
+ (outdir / 'testpkg' / 'world.py').write_text('', encoding='utf8')
(outdir / 'testpkg' / 'subpkg').makedirs()
- (outdir / 'testpkg' / 'subpkg' / '__init__.py').write_text('')
+ (outdir / 'testpkg' / 'subpkg' / '__init__.py').write_text('', encoding='utf8')
apidoc_main(['-o', tempdir, tempdir / 'testpkg'])
assert (outdir / 'testpkg.rst').exists()
assert (outdir / 'testpkg.subpkg.rst').exists()
@@ -532,8 +532,8 @@ def test_package_file(tempdir):
def test_package_file_separate(tempdir):
outdir = path(tempdir)
(outdir / 'testpkg').makedirs()
- (outdir / 'testpkg' / '__init__.py').write_text('')
- (outdir / 'testpkg' / 'example.py').write_text('')
+ (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
+ (outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8')
apidoc_main(['--separate', '-o', tempdir, tempdir / 'testpkg'])
assert (outdir / 'testpkg.rst').exists()
assert (outdir / 'testpkg.example.rst').exists()
@@ -571,8 +571,8 @@ def test_package_file_separate(tempdir):
def test_package_file_module_first(tempdir):
outdir = path(tempdir)
(outdir / 'testpkg').makedirs()
- (outdir / 'testpkg' / '__init__.py').write_text('')
- (outdir / 'testpkg' / 'example.py').write_text('')
+ (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
+ (outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8')
apidoc_main(['--module-first', '-o', tempdir, tempdir])
content = (outdir / 'testpkg.rst').read_text(encoding='utf8')
@@ -599,7 +599,7 @@ def test_package_file_module_first(tempdir):
def test_package_file_without_submodules(tempdir):
outdir = path(tempdir)
(outdir / 'testpkg').makedirs()
- (outdir / 'testpkg' / '__init__.py').write_text('')
+ (outdir / 'testpkg' / '__init__.py').write_text('', encoding='utf8')
apidoc_main(['-o', tempdir, tempdir / 'testpkg'])
assert (outdir / 'testpkg.rst').exists()
@@ -619,7 +619,7 @@ def test_package_file_without_submodules(tempdir):
def test_namespace_package_file(tempdir):
outdir = path(tempdir)
(outdir / 'testpkg').makedirs()
- (outdir / 'testpkg' / 'example.py').write_text('')
+ (outdir / 'testpkg' / 'example.py').write_text('', encoding='utf8')
apidoc_main(['--implicit-namespace', '-o', tempdir, tempdir / 'testpkg'])
assert (outdir / 'testpkg.rst').exists()
diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py
index 391247f0c..90fc91f67 100644
--- a/tests/test_ext_autodoc_configs.py
+++ b/tests/test_ext_autodoc_configs.py
@@ -865,7 +865,8 @@ def test_autodoc_typehints_description_no_undoc(app):
'.. autofunction:: target.typehints.tuple_args\n'
'\n'
' :param x: arg\n'
- ' :return: another tuple\n'
+ ' :return: another tuple\n',
+ encoding='utf8'
)
app.build()
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
@@ -917,7 +918,8 @@ def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
'\n'
'.. autofunction:: target.typehints.Math.horse\n'
'\n'
- ' :return: nothing\n'
+ ' :return: nothing\n',
+ encoding='utf8'
)
app.build()
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
@@ -961,7 +963,8 @@ def test_autodoc_typehints_description_no_undoc_doc_rtype(app):
def test_autodoc_typehints_description_with_documented_init(app):
(app.srcdir / 'index.rst').write_text(
'.. autoclass:: target.typehints._ClassWithDocumentedInit\n'
- ' :special-members: __init__\n'
+ ' :special-members: __init__\n',
+ encoding='utf8'
)
app.build()
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
@@ -992,7 +995,8 @@ def test_autodoc_typehints_description_with_documented_init(app):
def test_autodoc_typehints_description_with_documented_init_no_undoc(app):
(app.srcdir / 'index.rst').write_text(
'.. autoclass:: target.typehints._ClassWithDocumentedInit\n'
- ' :special-members: __init__\n'
+ ' :special-members: __init__\n',
+ encoding='utf8'
)
app.build()
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
@@ -1017,7 +1021,8 @@ def test_autodoc_typehints_description_with_documented_init_no_undoc_doc_rtype(a
# docstring.
(app.srcdir / 'index.rst').write_text(
'.. autoclass:: target.typehints._ClassWithDocumentedInit\n'
- ' :special-members: __init__\n'
+ ' :special-members: __init__\n',
+ encoding='utf8'
)
app.build()
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
@@ -1048,7 +1053,8 @@ def test_autodoc_typehints_both(app):
'\n'
'.. autofunction:: target.typehints.tuple_args\n'
'\n'
- '.. autofunction:: target.overload.sum\n'
+ '.. autofunction:: target.overload.sum\n',
+ encoding='utf8'
)
app.build()
context = (app.outdir / 'index.txt').read_text(encoding='utf8')
@@ -1217,7 +1223,7 @@ def test_autodoc_type_aliases(app):
confoverrides={'autodoc_typehints': "description",
'autodoc_type_aliases': {'myint': 'myint'}})
def test_autodoc_typehints_description_and_type_aliases(app):
- (app.srcdir / 'autodoc_type_aliases.rst').write_text('.. autofunction:: target.autodoc_type_aliases.sum')
+ (app.srcdir / 'autodoc_type_aliases.rst').write_text('.. autofunction:: target.autodoc_type_aliases.sum', encoding='utf8')
app.build()
context = (app.outdir / 'autodoc_type_aliases.txt').read_text(encoding='utf8')
assert ('target.autodoc_type_aliases.sum(x, y)\n'
diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py
index 29fe22bee..97d6f740e 100644
--- a/tests/test_ext_autosummary.py
+++ b/tests/test_ext_autosummary.py
@@ -383,7 +383,7 @@ def test_autosummary_generate_overwrite1(app_params, make_app):
srcdir = kwargs.get('srcdir')
(srcdir / 'generated').makedirs(exist_ok=True)
- (srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('')
+ (srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('', encoding='utf8')
app = make_app(*args, **kwargs)
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text(encoding='utf8')
@@ -398,7 +398,7 @@ def test_autosummary_generate_overwrite2(app_params, make_app):
srcdir = kwargs.get('srcdir')
(srcdir / 'generated').makedirs(exist_ok=True)
- (srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('')
+ (srcdir / 'generated' / 'autosummary_dummy_module.rst').write_text('', encoding='utf8')
app = make_app(*args, **kwargs)
content = (srcdir / 'generated' / 'autosummary_dummy_module.rst').read_text(encoding='utf8')
diff --git a/tests/test_project.py b/tests/test_project.py
index 40db85ef3..d4e0a0d8c 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -65,7 +65,7 @@ def test_project_doc2path(app):
assert project.doc2path('foo') == (app.srcdir / 'foo.rst')
# matched source_suffix is used if exists
- (app.srcdir / 'foo.txt').write_text('')
+ (app.srcdir / 'foo.txt').write_text('', encoding='utf8')
assert project.doc2path('foo') == (app.srcdir / 'foo.txt')
# absolute path
diff --git a/tests/test_setup_command.py b/tests/test_setup_command.py
index bfb2f2d96..a56f9d4a3 100644
--- a/tests/test_setup_command.py
+++ b/tests/test_setup_command.py
@@ -83,7 +83,7 @@ def nonascii_srcdir(request, setup_command):
(srcdir / mb_name / (mb_name + '.txt')).write_text(dedent("""
multi byte file name page
==========================
- """))
+ """), encoding='utf8')
root_doc = srcdir / 'index.txt'
root_doc.write_bytes((root_doc.read_text(encoding='utf8') + dedent("""
@@ -106,7 +106,8 @@ def test_build_sphinx_with_nonascii_path(setup_command):
def test_build_sphinx_return_nonzero_status(setup_command):
srcdir = (setup_command.pkgroot / 'doc')
(srcdir / 'contents.txt').write_text(
- 'http://localhost.unexistentdomain/index.html')
+ 'http://localhost.unexistentdomain/index.html',
+ encoding='utf8')
proc = setup_command.proc
out, err = proc.communicate()
print(out.decode())
@@ -117,7 +118,8 @@ def test_build_sphinx_return_nonzero_status(setup_command):
def test_build_sphinx_warning_return_zero_status(setup_command):
srcdir = (setup_command.pkgroot / 'doc')
(srcdir / 'contents.txt').write_text(
- 'See :ref:`unexisting-reference-label`')
+ 'See :ref:`unexisting-reference-label`',
+ encoding='utf8')
proc = setup_command.proc
out, err = proc.communicate()
print(out.decode())
@@ -129,7 +131,8 @@ def test_build_sphinx_warning_return_zero_status(setup_command):
def test_build_sphinx_warning_is_error_return_nonzero_status(setup_command):
srcdir = (setup_command.pkgroot / 'doc')
(srcdir / 'contents.txt').write_text(
- 'See :ref:`unexisting-reference-label`')
+ 'See :ref:`unexisting-reference-label`',
+ encoding='utf8')
proc = setup_command.proc
out, err = proc.communicate()
print(out.decode())
diff --git a/tests/test_toctree.py b/tests/test_toctree.py
index f739f4232..39d0916d2 100644
--- a/tests/test_toctree.py
+++ b/tests/test_toctree.py
@@ -35,5 +35,5 @@ def test_numbered_toctree(app, status, warning):
# give argument to :numbered: option
index = (app.srcdir / 'index.rst').read_text(encoding='utf8')
index = re.sub(':numbered:.*', ':numbered: 1', index)
- (app.srcdir / 'index.rst').write_text(index)
+ (app.srcdir / 'index.rst').write_text(index, encoding='utf8')
app.builder.build_all()
diff --git a/tests/test_util_fileutil.py b/tests/test_util_fileutil.py
index d7463ef66..8ae3f918f 100644
--- a/tests/test_util_fileutil.py
+++ b/tests/test_util_fileutil.py
@@ -64,13 +64,13 @@ def test_copy_asset(tempdir):
# prepare source files
source = (tempdir / 'source')
source.makedirs()
- (source / 'index.rst').write_text('index.rst')
- (source / 'foo.rst_t').write_text('{{var1}}.rst')
+ (source / 'index.rst').write_text('index.rst', encoding='utf8')
+ (source / 'foo.rst_t').write_text('{{var1}}.rst', encoding='utf8')
(source / '_static').makedirs()
- (source / '_static' / 'basic.css').write_text('basic.css')
+ (source / '_static' / 'basic.css').write_text('basic.css', encoding='utf8')
(source / '_templates').makedirs()
- (source / '_templates' / 'layout.html').write_text('layout.html')
- (source / '_templates' / 'sidebar.html_t').write_text('sidebar: {{var2}}')
+ (source / '_templates' / 'layout.html').write_text('layout.html', encoding='utf8')
+ (source / '_templates' / 'sidebar.html_t').write_text('sidebar: {{var2}}', encoding='utf8')
# copy a single file
assert not (tempdir / 'test1').exists()
diff --git a/tests/test_util_i18n.py b/tests/test_util_i18n.py
index c80e9183e..e52e27671 100644
--- a/tests/test_util_i18n.py
+++ b/tests/test_util_i18n.py
@@ -28,12 +28,12 @@ def test_catalog_info_for_sub_domain_file_and_path():
def test_catalog_outdated(tempdir):
- (tempdir / 'test.po').write_text('#')
+ (tempdir / 'test.po').write_text('#', encoding='utf8')
cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8')
assert cat.is_outdated() # if mo is not exist
mo_file = (tempdir / 'test.mo')
- mo_file.write_text('#')
+ mo_file.write_text('#', encoding='utf8')
assert not cat.is_outdated() # if mo is exist and newer than po
os.utime(mo_file, (os.stat(mo_file).st_mtime - 10,) * 2) # to be outdate
@@ -41,7 +41,7 @@ def test_catalog_outdated(tempdir):
def test_catalog_write_mo(tempdir):
- (tempdir / 'test.po').write_text('#')
+ (tempdir / 'test.po').write_text('#', encoding='utf8')
cat = i18n.CatalogInfo(tempdir, 'test', 'utf-8')
cat.write_mo('en')
assert os.path.exists(cat.mo_path)
@@ -146,18 +146,18 @@ def test_get_filename_for_language(app):
def test_CatalogRepository(tempdir):
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES').makedirs()
- (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#', encoding='utf8')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'test2.po').write_text('#', encoding='utf8')
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub').makedirs()
- (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#')
- (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test3.po').write_text('#', encoding='utf8')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / 'sub' / 'test4.po').write_text('#', encoding='utf8')
(tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / '.dotdir').makedirs()
- (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / '.dotdir' / 'test5.po').write_text('#')
+ (tempdir / 'loc1' / 'xx' / 'LC_MESSAGES' / '.dotdir' / 'test5.po').write_text('#', encoding='utf8')
(tempdir / 'loc1' / 'yy' / 'LC_MESSAGES').makedirs()
- (tempdir / 'loc1' / 'yy' / 'LC_MESSAGES' / 'test6.po').write_text('#')
+ (tempdir / 'loc1' / 'yy' / 'LC_MESSAGES' / 'test6.po').write_text('#', encoding='utf8')
(tempdir / 'loc2' / 'xx' / 'LC_MESSAGES').makedirs()
- (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#')
- (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test7.po').write_text('#')
+ (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test1.po').write_text('#', encoding='utf8')
+ (tempdir / 'loc2' / 'xx' / 'LC_MESSAGES' / 'test7.po').write_text('#', encoding='utf8')
# for language xx
repo = i18n.CatalogRepository(tempdir, ['loc1', 'loc2'], 'xx', 'utf-8')