Skip to content

Commit bbc8127

Browse files
BoboTiGhumitos
andauthored
fix(tests): resource warnings about unclosed file (#232)
Co-authored-by: Manuel Kaufmann <[email protected]>
1 parent 68fe9e6 commit bbc8127

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tests/test_urls.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_default_settings(app, status, warning):
5757
app.build()
5858
path = app.outdir / '404.html'
5959
assert path.exists()
60-
content = open(path).read()
60+
content = path.read_text()
6161

6262
if sphinx.version_info < (6, 0):
6363
cssclass = "shortcut "
@@ -97,7 +97,7 @@ def test_context_settings(app, status, warning):
9797
app.build()
9898
path = app.outdir / '404.html'
9999
assert path.exists()
100-
content = open(path).read()
100+
content = path.read_text()
101101

102102
chunks = [
103103
'<h1>Boo!</h1>',
@@ -132,7 +132,7 @@ def test_urls_prefix_setting(app, status, warning):
132132
path = app.outdir / '404.html'
133133
assert path.exists()
134134

135-
content = open(path).read()
135+
content = path.read_text()
136136

137137
if sphinx.version_info < (6, 0):
138138
cssclass = "shortcut "
@@ -170,7 +170,7 @@ def test_urls_prefix_setting_none(app, status, warning):
170170
path = app.outdir / '404.html'
171171
assert path.exists()
172172

173-
content = open(path).read()
173+
content = path.read_text()
174174

175175
if sphinx.version_info < (6, 0):
176176
cssclass = "shortcut "
@@ -213,7 +213,7 @@ def test_template_setting(app, status, warning):
213213
path = app.outdir / '404.html'
214214
assert path.exists()
215215

216-
content = open(path).read()
216+
content = path.read_text()
217217

218218
chunks = [
219219
'Custom title',
@@ -237,7 +237,7 @@ def test_custom_404_rst_source(app, status, warning):
237237
path = app.outdir / '404.html'
238238
assert path.exists()
239239

240-
content = open(path).read()
240+
content = path.read_text()
241241

242242
chunks = [
243243
# custom 404.rst file content
@@ -279,7 +279,7 @@ def test_image_on_404_rst_source(app, status, warning):
279279
path = app.outdir / '404.html'
280280
assert path.exists()
281281

282-
content = open(path).read()
282+
content = path.read_text()
283283

284284
chunks = [
285285
# .. image::
@@ -313,7 +313,7 @@ def test_image_looks_like_absolute_url(app, status, warning):
313313

314314
path = app.outdir / '404.html'
315315
assert path.exists()
316-
content = open(path).read()
316+
content = path.read_text()
317317

318318
chunks = [
319319
'<img alt="PATH looking as an URL" src="/en/latest/_images/https.png" />',
@@ -327,8 +327,8 @@ def test_image_looks_like_absolute_url(app, status, warning):
327327
def test_image_absolute_url(app, status, warning):
328328
app.build()
329329
path = app.outdir / '404.html'
330-
assert path.exists() is True
331-
content = open(path).read()
330+
assert path.exists()
331+
content = path.read_text()
332332

333333
chunks = [
334334
'<img alt="Read the Docs Logo" src="https://read-the-docs-guidelines.readthedocs-hosted.com/_images/logo-dark.png" />',
@@ -347,7 +347,7 @@ def test_urls_for_dirhtml_builder(app, status, warning):
347347
path = app.outdir / '404' / 'index.html'
348348
assert path.exists()
349349

350-
content = open(path).read()
350+
content = path.read_text()
351351

352352
chunks = [
353353
# sidebar URLs
@@ -370,7 +370,7 @@ def test_sphinx_resource_urls(app, status, warning):
370370
path = app.outdir / '404.html'
371371
assert path.exists()
372372

373-
content = open(path).read()
373+
content = path.read_text()
374374

375375
chunks = [
376376
# Sphinx's resources URLs
@@ -398,7 +398,7 @@ def test_toctree_urls_notfound_default(app, status, warning):
398398
path = app.outdir / '404.html'
399399
assert path.exists()
400400

401-
content = open(path).read()
401+
content = path.read_text()
402402

403403
chunks = [
404404
# sidebar URLs
@@ -423,7 +423,7 @@ def test_toctree_links(app, status, warning):
423423
path = app.outdir / '404.html'
424424
assert path.exists()
425425

426-
content = open(path).read()
426+
content = path.read_text()
427427

428428
chunks = [
429429
'<h3>Navigation</h3>',
@@ -445,7 +445,7 @@ def test_toctree_links_custom_settings(app, status, warning):
445445
path = app.outdir / '404.html'
446446
assert path.exists()
447447

448-
content = open(path).read()
448+
content = path.read_text()
449449

450450
chunks = [
451451
'<h3>Navigation</h3>',
@@ -470,7 +470,7 @@ def test_resources_from_extension(app, status, warning):
470470
path = app.outdir / '404.html'
471471
assert path.exists()
472472

473-
content = open(path).read()
473+
content = path.read_text()
474474
chunks = [
475475
'<link rel="stylesheet" type="text/css" href="/en/latest/_static/css_added_by_extension.css" />',
476476
'<link rel="stylesheet" type="text/css" href="/en/latest/_static/css_added_by_extension.css" />',
@@ -492,7 +492,7 @@ def test_special_readthedocs_urls(environ, app, status, warning):
492492
path = app.outdir / '404.html'
493493
assert path.exists()
494494

495-
content = open(path).read()
495+
content = path.read_text()
496496

497497
chunks = [
498498
# Link included manually

0 commit comments

Comments
 (0)