summaryrefslogtreecommitdiff
path: root/tests/test_build_epub.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_build_epub.py')
-rw-r--r--tests/test_build_epub.py41
1 files changed, 19 insertions, 22 deletions
diff --git a/tests/test_build_epub.py b/tests/test_build_epub.py
index f9872f28c..86e40b65d 100644
--- a/tests/test_build_epub.py
+++ b/tests/test_build_epub.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
"""
test_build_html
~~~~~~~~~~~~~~~
@@ -10,7 +9,8 @@
"""
import os
-from subprocess import Popen, PIPE
+import subprocess
+from subprocess import CalledProcessError, PIPE
from xml.etree import ElementTree
import pytest
@@ -19,16 +19,13 @@ import pytest
# check given command is runnable
def runnable(command):
try:
- p = Popen(command, stdout=PIPE, stderr=PIPE)
- except OSError:
- # command not found
- return False
- else:
- p.communicate()
- return p.returncode == 0
+ subprocess.run(command, stdout=PIPE, stderr=PIPE, check=True)
+ return True
+ except (OSError, CalledProcessError):
+ return False # command not found or exit with non-zero
-class EPUBElementTree(object):
+class EPUBElementTree:
"""Test helper for content.opf and toc.ncx"""
namespaces = {
'idpf': 'http://www.idpf.org/2007/opf',
@@ -189,7 +186,7 @@ def test_nested_toc(app):
navpoints = toc.findall("./ncx:navMap/ncx:navPoint")
assert len(navpoints) == 4
assert navinfo(navpoints[0]) == ('navPoint1', '1', 'index.xhtml',
- u"Welcome to Sphinx Tests’s documentation!")
+ "Welcome to Sphinx Tests’s documentation!")
assert navpoints[0].findall("./ncx:navPoint") == []
# toc.ncx / nested navPoints
@@ -210,7 +207,7 @@ def test_nested_toc(app):
toc = nav.findall("./xhtml:body/xhtml:nav/xhtml:ol/xhtml:li")
assert len(toc) == 4
assert navinfo(toc[0]) == ('index.xhtml',
- u"Welcome to Sphinx Tests’s documentation!")
+ "Welcome to Sphinx Tests’s documentation!")
assert toc[0].findall("./xhtml:ol") == []
# nav.xhtml / nested toc
@@ -245,7 +242,7 @@ def test_escaped_toc(app):
navpoints = toc.findall("./ncx:navMap/ncx:navPoint")
assert len(navpoints) == 4
assert navinfo(navpoints[0]) == ('navPoint1', '1', 'index.xhtml',
- u"Welcome to Sphinx Tests's documentation!")
+ "Welcome to Sphinx Tests's documentation!")
assert navpoints[0].findall("./ncx:navPoint") == []
# toc.ncx / nested navPoints
@@ -254,7 +251,7 @@ def test_escaped_toc(app):
assert len(navchildren) == 4
assert navinfo(navchildren[0]) == ('navPoint3', '2', 'foo.xhtml', '<foo>')
assert navinfo(navchildren[1]) == ('navPoint4', '3', 'quux.xhtml', 'quux')
- assert navinfo(navchildren[2]) == ('navPoint5', '4', 'foo.xhtml#foo-1', u'foo “1”')
+ assert navinfo(navchildren[2]) == ('navPoint5', '4', 'foo.xhtml#foo-1', 'foo “1”')
assert navinfo(navchildren[3]) == ('navPoint8', '6', 'foo.xhtml#foo-2', 'foo.2')
# nav.xhtml / nav
@@ -274,7 +271,7 @@ def test_escaped_toc(app):
tocchildren = toc[1].findall("./xhtml:ol/xhtml:li")
assert len(tocchildren) == 3
assert navinfo(tocchildren[0]) == ('quux.xhtml', 'quux')
- assert navinfo(tocchildren[1]) == ('foo.xhtml#foo-1', u'foo “1”')
+ assert navinfo(tocchildren[1]) == ('foo.xhtml#foo-1', 'foo “1”')
assert navinfo(tocchildren[2]) == ('foo.xhtml#foo-2', 'foo.2')
grandchild = tocchildren[1].findall("./xhtml:ol/xhtml:li")
@@ -378,10 +375,10 @@ def test_run_epubcheck(app):
epubcheck = os.environ.get('EPUBCHECK_PATH', '/usr/share/java/epubcheck.jar')
if runnable(['java', '-version']) and os.path.exists(epubcheck):
- p = Popen(['java', '-jar', epubcheck, app.outdir / 'SphinxTests.epub'],
- stdout=PIPE, stderr=PIPE)
- stdout, stderr = p.communicate()
- if p.returncode != 0:
- print(stdout)
- print(stderr)
- assert False, 'epubcheck exited with return code %s' % p.returncode
+ try:
+ subprocess.run(['java', '-jar', epubcheck, app.outdir / 'SphinxTests.epub'],
+ stdout=PIPE, stderr=PIPE, check=True)
+ except CalledProcessError as exc:
+ print(exc.stdout)
+ print(exc.stderr)
+ assert False, 'epubcheck exited with return code %s' % exc.returncode