mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
pytest: update by reviewing
* remove 'specific_srcdir' feature * simplify 'shared_result' feature * rename 'AppWrapper' into 'SphinxTestAppWrapperForSkipBuilding'
This commit is contained in:
parent
561abdd164
commit
b5530629a9
@ -35,10 +35,11 @@ def app_params(request, test_params, shared_result):
|
|||||||
|
|
||||||
# ##### process pytest.mark.test_params
|
# ##### process pytest.mark.test_params
|
||||||
|
|
||||||
if test_params['specific_srcdir'] and 'srcdir' not in kwargs:
|
|
||||||
kwargs['srcdir'] = test_params['specific_srcdir']
|
|
||||||
|
|
||||||
if test_params['shared_result']:
|
if test_params['shared_result']:
|
||||||
|
if 'srcdir' in kwargs:
|
||||||
|
raise pytest.Exception('You can not spcify shared_result and '
|
||||||
|
'srcdir in same time.')
|
||||||
|
kwargs['srcdir'] = test_params['shared_result']
|
||||||
restore = shared_result.restore(test_params['shared_result'])
|
restore = shared_result.restore(test_params['shared_result'])
|
||||||
kwargs.update(restore)
|
kwargs.update(restore)
|
||||||
|
|
||||||
@ -66,43 +67,27 @@ def test_params(request):
|
|||||||
"""
|
"""
|
||||||
test parameters that is specified by 'pytest.mark.test_params'
|
test parameters that is specified by 'pytest.mark.test_params'
|
||||||
|
|
||||||
:param Union[str, bool, None] specific_srcdir:
|
:param Union[str] shared_result:
|
||||||
If True, testroot directory will be copied into
|
If the value is provided, app._status and app._warning objects will be
|
||||||
'<TMPDIR>/<TEST FUNCTION NAME>'.
|
shared in the parametrized test functions and/or test functions that
|
||||||
If string is specified, it copied into '<TMPDIR>/<THE STRING>'.
|
have same 'shared_result' value.
|
||||||
You can used this feature for providing special crafted source
|
**NOTE**: You can not specify shared_result and srcdir in same time.
|
||||||
directory. Also you can used for sharing source directory for
|
|
||||||
parametrized testing and/or inter test functions. Default is None.
|
|
||||||
:param Union[str, bool, None] shared_result:
|
|
||||||
If True, app._status and app._warning objects will be shared in the
|
|
||||||
parametrized test functions. If string is specified, the objects will
|
|
||||||
be shred in the test functions that have same 'shared_result' value.
|
|
||||||
If you don't specify specific_srcdir, this option override
|
|
||||||
specific_srcdir param by 'shared_result' value. Default is None.
|
|
||||||
"""
|
"""
|
||||||
env = request.node.get_marker('test_params')
|
env = request.node.get_marker('test_params')
|
||||||
kwargs = env.kwargs if env else {}
|
kwargs = env.kwargs if env else {}
|
||||||
result = {
|
result = {
|
||||||
'specific_srcdir': None,
|
|
||||||
'shared_result': None,
|
'shared_result': None,
|
||||||
}
|
}
|
||||||
result.update(kwargs)
|
result.update(kwargs)
|
||||||
|
|
||||||
if (result['shared_result'] and
|
if (result['shared_result'] and
|
||||||
not isinstance(result['shared_result'], string_types)):
|
not isinstance(result['shared_result'], string_types)):
|
||||||
result['shared_result'] = request.node.originalname or request.node.name
|
raise pytest.Exception('You can only provide a string type of value '
|
||||||
|
'for "shared_result" ')
|
||||||
if result['shared_result'] and not result['specific_srcdir']:
|
|
||||||
result['specific_srcdir'] = result['shared_result']
|
|
||||||
|
|
||||||
if (result['specific_srcdir'] and
|
|
||||||
not isinstance(result['specific_srcdir'], string_types)):
|
|
||||||
result['specific_srcdir'] = request.node.originalname or request.node.name
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class AppWrapper(object):
|
class SphinxTestAppWrapperForSkipBuilding(object):
|
||||||
"""
|
"""
|
||||||
This class is a wrapper for SphinxTestApp to speed up the test by skipping
|
This class is a wrapper for SphinxTestApp to speed up the test by skipping
|
||||||
`app.build` process if it is already built and there is even one output
|
`app.build` process if it is already built and there is even one output
|
||||||
@ -175,7 +160,7 @@ def make_app(test_params):
|
|||||||
app_ = util.SphinxTestApp(*args, **kwargs)
|
app_ = util.SphinxTestApp(*args, **kwargs)
|
||||||
apps.append(app_)
|
apps.append(app_)
|
||||||
if test_params['shared_result']:
|
if test_params['shared_result']:
|
||||||
app_ = AppWrapper(app_)
|
app_ = SphinxTestAppWrapperForSkipBuilding(app_)
|
||||||
return app_
|
return app_
|
||||||
yield make
|
yield make
|
||||||
|
|
||||||
|
@ -570,8 +570,10 @@ def test_numfig_disabled(app, cached_etree_parse, fname, expect):
|
|||||||
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
|
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True})
|
@pytest.mark.sphinx(
|
||||||
@pytest.mark.test_params(specific_srcdir=True)
|
'html', testroot='numfig',
|
||||||
|
srcdir='test_numfig_without_numbered_toctree_warn',
|
||||||
|
confoverrides={'numfig': True})
|
||||||
def test_numfig_without_numbered_toctree_warn(app, warning):
|
def test_numfig_without_numbered_toctree_warn(app, warning):
|
||||||
app.build()
|
app.build()
|
||||||
# remove :numbered: option
|
# remove :numbered: option
|
||||||
@ -667,8 +669,10 @@ def test_numfig_without_numbered_toctree_warn(app, warning):
|
|||||||
"span[@class='caption-number']", '^Listing 6 $', True),
|
"span[@class='caption-number']", '^Listing 6 $', True),
|
||||||
],
|
],
|
||||||
}))
|
}))
|
||||||
@pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True})
|
@pytest.mark.sphinx(
|
||||||
@pytest.mark.test_params(specific_srcdir=True)
|
'html', testroot='numfig',
|
||||||
|
srcdir='test_numfig_without_numbered_toctree',
|
||||||
|
confoverrides={'numfig': True})
|
||||||
def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect):
|
def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect):
|
||||||
# remove :numbered: option
|
# remove :numbered: option
|
||||||
index = (app.srcdir / 'index.rst').text()
|
index = (app.srcdir / 'index.rst').text()
|
||||||
@ -1085,8 +1089,10 @@ def test_numfig_with_singlehtml(app, cached_etree_parse, fname, expect):
|
|||||||
(".//li/a/span", 'No.2', True),
|
(".//li/a/span", 'No.2', True),
|
||||||
],
|
],
|
||||||
}))
|
}))
|
||||||
@pytest.mark.sphinx('html', testroot='add_enumerable_node')
|
@pytest.mark.sphinx(
|
||||||
@pytest.mark.test_params(specific_srcdir=True)
|
'html', testroot='add_enumerable_node',
|
||||||
|
srcdir='test_enumerable_node',
|
||||||
|
)
|
||||||
def test_enumerable_node(app, cached_etree_parse, fname, expect):
|
def test_enumerable_node(app, cached_etree_parse, fname, expect):
|
||||||
app.build()
|
app.build()
|
||||||
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
|
check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect)
|
||||||
|
@ -970,7 +970,10 @@ def test_additional_targets_should_not_be_translated(app):
|
|||||||
|
|
||||||
|
|
||||||
@sphinx_intl
|
@sphinx_intl
|
||||||
@pytest.mark.sphinx('html', confoverrides={
|
@pytest.mark.sphinx(
|
||||||
|
'html',
|
||||||
|
srcdir='test_additional_targets_should_be_translated',
|
||||||
|
confoverrides={
|
||||||
'language': 'xx', 'locale_dirs': ['.'],
|
'language': 'xx', 'locale_dirs': ['.'],
|
||||||
'gettext_compact': False,
|
'gettext_compact': False,
|
||||||
'gettext_additional_targets': [
|
'gettext_additional_targets': [
|
||||||
@ -980,8 +983,8 @@ def test_additional_targets_should_not_be_translated(app):
|
|||||||
'raw',
|
'raw',
|
||||||
'image',
|
'image',
|
||||||
],
|
],
|
||||||
})
|
}
|
||||||
@pytest.mark.test_params(specific_srcdir=True)
|
)
|
||||||
def test_additional_targets_should_be_translated(app):
|
def test_additional_targets_should_be_translated(app):
|
||||||
app.build()
|
app.build()
|
||||||
# [literalblock.txt]
|
# [literalblock.txt]
|
||||||
@ -1045,9 +1048,9 @@ def test_text_references(app, warning):
|
|||||||
|
|
||||||
@pytest.mark.sphinx(
|
@pytest.mark.sphinx(
|
||||||
'dummy', testroot='image-glob',
|
'dummy', testroot='image-glob',
|
||||||
|
srcdir='test_intl_image_glob',
|
||||||
confoverrides={'language': 'xx'}
|
confoverrides={'language': 'xx'}
|
||||||
)
|
)
|
||||||
@pytest.mark.test_params(specific_srcdir='test_intl_image_glob')
|
|
||||||
def test_image_glob_intl(app):
|
def test_image_glob_intl(app):
|
||||||
app.build()
|
app.build()
|
||||||
# index.rst
|
# index.rst
|
||||||
@ -1089,12 +1092,12 @@ def test_image_glob_intl(app):
|
|||||||
|
|
||||||
@pytest.mark.sphinx(
|
@pytest.mark.sphinx(
|
||||||
'dummy', testroot='image-glob',
|
'dummy', testroot='image-glob',
|
||||||
|
srcdir='test_intl_image_glob',
|
||||||
confoverrides={
|
confoverrides={
|
||||||
'language': 'xx',
|
'language': 'xx',
|
||||||
'figure_language_filename': u'{root}{ext}.{language}',
|
'figure_language_filename': u'{root}{ext}.{language}',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@pytest.mark.test_params(specific_srcdir='test_intl_image_glob')
|
|
||||||
def test_image_glob_intl_using_figure_language_filename(app):
|
def test_image_glob_intl_using_figure_language_filename(app):
|
||||||
app.build()
|
app.build()
|
||||||
# index.rst
|
# index.rst
|
||||||
|
Loading…
Reference in New Issue
Block a user