Skip to content

Commit aa0335a

Browse files
authored
Merge pull request #9886 from tk0miya/9868_pytest_failing
Fix #9868: 4.3.0: pytest is failing
2 parents 538e281 + dbba0ae commit aa0335a

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bugs fixed
2525
having invalid __doc__ atribute
2626
* #9872: html: Class namespace collision between autodoc signatures and
2727
docutils-0.17
28+
* #9868: imgmath: Crashed if the dvisvgm command failed to convert equation
2829
* #9864: mathjax: Failed to render equations via MathJax v2. The loading method
2930
of MathJax is back to "async" method again
3031

sphinx/ext/imgmath.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import re
1313
import shutil
1414
import subprocess
15-
import sys
1615
import tempfile
1716
from os import path
1817
from subprocess import PIPE, CalledProcessError
@@ -43,11 +42,11 @@
4342
class MathExtError(SphinxError):
4443
category = 'Math extension error'
4544

46-
def __init__(self, msg: str, stderr: bytes = None, stdout: bytes = None) -> None:
45+
def __init__(self, msg: str, stderr: str = None, stdout: str = None) -> None:
4746
if stderr:
48-
msg += '\n[stderr]\n' + stderr.decode(sys.getdefaultencoding(), 'replace')
47+
msg += '\n[stderr]\n' + stderr
4948
if stdout:
50-
msg += '\n[stdout]\n' + stdout.decode(sys.getdefaultencoding(), 'replace')
49+
msg += '\n[stdout]\n' + stdout
5150
super().__init__(msg)
5251

5352

@@ -135,7 +134,8 @@ def compile_math(latex: str, builder: Builder) -> str:
135134
command.append('math.tex')
136135

137136
try:
138-
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True)
137+
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True,
138+
encoding='ascii')
139139
return path.join(tempdir, 'math.dvi')
140140
except OSError as exc:
141141
logger.warning(__('LaTeX command %r cannot be run (needed for math '

tests/test_util_inspect.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import types
1717
from inspect import Parameter
1818

19-
import _testcapi
2019
import pytest
2120

2221
from sphinx.util import inspect
@@ -627,8 +626,6 @@ class Descriptor:
627626
def __get__(self, obj, typ=None):
628627
pass
629628

630-
testinstancemethod = _testcapi.instancemethod(str.__repr__)
631-
632629
assert inspect.isattributedescriptor(Base.prop) is True # property
633630
assert inspect.isattributedescriptor(Base.meth) is False # method
634631
assert inspect.isattributedescriptor(Base.staticmeth) is False # staticmethod
@@ -639,7 +636,16 @@ def __get__(self, obj, typ=None):
639636
assert inspect.isattributedescriptor(dict.__dict__['fromkeys']) is False # ClassMethodDescriptorType # NOQA
640637
assert inspect.isattributedescriptor(types.FrameType.f_locals) is True # GetSetDescriptorType # NOQA
641638
assert inspect.isattributedescriptor(datetime.timedelta.days) is True # MemberDescriptorType # NOQA
642-
assert inspect.isattributedescriptor(testinstancemethod) is False # instancemethod (C-API) # NOQA
639+
640+
try:
641+
# _testcapi module cannot be importable in some distro
642+
# refs: https://github.com/sphinx-doc/sphinx/issues/9868
643+
import _testcapi
644+
645+
testinstancemethod = _testcapi.instancemethod(str.__repr__)
646+
assert inspect.isattributedescriptor(testinstancemethod) is False # instancemethod (C-API) # NOQA
647+
except ImportError:
648+
pass
643649

644650

645651
def test_isproperty(app):

0 commit comments

Comments
 (0)