Fix testcases for singledispatch are sometimes failed

They are sometimes failed with python3.5 because the order of singledispatch
functions is not stable on python 3.5.  This uses comparision via "in"
keyword to check the signature of singledispatch functions stably.
This commit is contained in:
Takeshi KOMIYA 2020-11-04 23:19:25 +09:00
parent 242c63dc8b
commit 218de39462
2 changed files with 39 additions and 23 deletions

View File

@ -1832,19 +1832,26 @@ def test_autodoc_for_egged_code(app):
def test_singledispatch(app):
options = {"members": None}
actual = do_autodoc(app, 'module', 'target.singledispatch', options)
assert list(actual) == [
'',
'.. py:module:: target.singledispatch',
'',
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
if sys.version_info < (3, 6):
# check the result via "in" because the order of singledispatch signatures is
# usually changed (because dict is not OrderedDict yet!)
assert '.. py:function:: func(arg, kwarg=None)' in actual
assert ' func(arg: int, kwarg=None)' in actual
assert ' func(arg: str, kwarg=None)' in actual
else:
assert list(actual) == [
'',
'.. py:module:: target.singledispatch',
'',
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
@pytest.mark.skipif(sys.version_info < (3, 8),

View File

@ -9,6 +9,8 @@
:license: BSD, see LICENSE for details.
"""
import sys
import pytest
from test_ext_autodoc import do_autodoc
@ -108,16 +110,23 @@ def test_decorated(app):
def test_singledispatch(app):
options = {}
actual = do_autodoc(app, 'function', 'target.singledispatch.func', options)
assert list(actual) == [
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
if sys.version_info < (3, 6):
# check the result via "in" because the order of singledispatch signatures is
# usually changed (because dict is not OrderedDict yet!)
assert '.. py:function:: func(arg, kwarg=None)' in actual
assert ' func(arg: int, kwarg=None)' in actual
assert ' func(arg: str, kwarg=None)' in actual
else:
assert list(actual) == [
'',
'.. py:function:: func(arg, kwarg=None)',
' func(arg: int, kwarg=None)',
' func(arg: str, kwarg=None)',
' :module: target.singledispatch',
'',
' A function for general use.',
'',
]
@pytest.mark.sphinx('html', testroot='ext-autodoc')