From b5530629a99d3e2b1060b9329a3134e0e6ebb10b Mon Sep 17 00:00:00 2001 From: shimizukawa Date: Mon, 9 Jan 2017 17:41:47 +0900 Subject: [PATCH] pytest: update by reviewing * remove 'specific_srcdir' feature * simplify 'shared_result' feature * rename 'AppWrapper' into 'SphinxTestAppWrapperForSkipBuilding' --- tests/conftest.py | 41 +++++++++++++--------------------------- tests/test_build_html.py | 18 ++++++++++++------ tests/test_intl.py | 31 ++++++++++++++++-------------- 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 8032e8e6c..6fab88b12 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -35,10 +35,11 @@ def app_params(request, test_params, shared_result): # ##### 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 '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']) kwargs.update(restore) @@ -66,43 +67,27 @@ def test_params(request): """ test parameters that is specified by 'pytest.mark.test_params' - :param Union[str, bool, None] specific_srcdir: - If True, testroot directory will be copied into - '/'. - If string is specified, it copied into '/'. - You can used this feature for providing special crafted source - 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. + :param Union[str] shared_result: + If the value is provided, app._status and app._warning objects will be + shared in the parametrized test functions and/or test functions that + have same 'shared_result' value. + **NOTE**: You can not specify shared_result and srcdir in same time. """ env = request.node.get_marker('test_params') kwargs = env.kwargs if env else {} result = { - 'specific_srcdir': None, 'shared_result': None, } result.update(kwargs) if (result['shared_result'] and not isinstance(result['shared_result'], string_types)): - result['shared_result'] = request.node.originalname or request.node.name - - 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 - + raise pytest.Exception('You can only provide a string type of value ' + 'for "shared_result" ') return result -class AppWrapper(object): +class SphinxTestAppWrapperForSkipBuilding(object): """ 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 @@ -175,7 +160,7 @@ def make_app(test_params): app_ = util.SphinxTestApp(*args, **kwargs) apps.append(app_) if test_params['shared_result']: - app_ = AppWrapper(app_) + app_ = SphinxTestAppWrapperForSkipBuilding(app_) return app_ yield make diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 4a4eac2b6..63c8111e1 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -570,8 +570,10 @@ def test_numfig_disabled(app, cached_etree_parse, fname, expect): check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) -@pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True}) -@pytest.mark.test_params(specific_srcdir=True) +@pytest.mark.sphinx( + 'html', testroot='numfig', + srcdir='test_numfig_without_numbered_toctree_warn', + confoverrides={'numfig': True}) def test_numfig_without_numbered_toctree_warn(app, warning): app.build() # remove :numbered: option @@ -667,8 +669,10 @@ def test_numfig_without_numbered_toctree_warn(app, warning): "span[@class='caption-number']", '^Listing 6 $', True), ], })) -@pytest.mark.sphinx('html', testroot='numfig', confoverrides={'numfig': True}) -@pytest.mark.test_params(specific_srcdir=True) +@pytest.mark.sphinx( + 'html', testroot='numfig', + srcdir='test_numfig_without_numbered_toctree', + confoverrides={'numfig': True}) def test_numfig_without_numbered_toctree(app, cached_etree_parse, fname, expect): # remove :numbered: option 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), ], })) -@pytest.mark.sphinx('html', testroot='add_enumerable_node') -@pytest.mark.test_params(specific_srcdir=True) +@pytest.mark.sphinx( + 'html', testroot='add_enumerable_node', + srcdir='test_enumerable_node', +) def test_enumerable_node(app, cached_etree_parse, fname, expect): app.build() check_xpath(cached_etree_parse(app.outdir / fname), fname, *expect) diff --git a/tests/test_intl.py b/tests/test_intl.py index 1372c80d8..e7bb130ff 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -970,18 +970,21 @@ def test_additional_targets_should_not_be_translated(app): @sphinx_intl -@pytest.mark.sphinx('html', confoverrides={ - 'language': 'xx', 'locale_dirs': ['.'], - 'gettext_compact': False, - 'gettext_additional_targets': [ - 'index', - 'literal-block', - 'doctest-block', - 'raw', - 'image', - ], -}) -@pytest.mark.test_params(specific_srcdir=True) +@pytest.mark.sphinx( + 'html', + srcdir='test_additional_targets_should_be_translated', + confoverrides={ + 'language': 'xx', 'locale_dirs': ['.'], + 'gettext_compact': False, + 'gettext_additional_targets': [ + 'index', + 'literal-block', + 'doctest-block', + 'raw', + 'image', + ], + } +) def test_additional_targets_should_be_translated(app): app.build() # [literalblock.txt] @@ -1045,9 +1048,9 @@ def test_text_references(app, warning): @pytest.mark.sphinx( 'dummy', testroot='image-glob', + srcdir='test_intl_image_glob', confoverrides={'language': 'xx'} ) -@pytest.mark.test_params(specific_srcdir='test_intl_image_glob') def test_image_glob_intl(app): app.build() # index.rst @@ -1089,12 +1092,12 @@ def test_image_glob_intl(app): @pytest.mark.sphinx( 'dummy', testroot='image-glob', + srcdir='test_intl_image_glob', confoverrides={ 'language': 'xx', '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): app.build() # index.rst