# -*- coding: utf-8 -*- """ test_docutilsconf ~~~~~~~~~~~~~~~~~ Test docutils.conf support for several writers. :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ import os import re from functools import wraps import six from util import test_roots, TestApp html_warnfile = six.StringIO() root = test_roots / 'test-docutilsconf' # need cleanenv to rebuild everytime. # docutils.conf change did not effect to rebuild. def with_conf_app(docutilsconf='', *args, **kwargs): default_kw = { 'srcdir': root, 'cleanenv': True, } default_kw.update(kwargs) def generator(func): @wraps(func) def deco(*args2, **kwargs2): app = TestApp(*args, **default_kw) (app.srcdir / 'docutils.conf').write_text(docutilsconf) try: cwd = os.getcwd() os.chdir(app.srcdir) func(app, *args2, **kwargs2) finally: os.chdir(cwd) # don't execute cleanup if test failed app.cleanup() return deco return generator def regex_count(expr, result): return len(re.findall(expr, result)) @with_conf_app(buildername='html') def test_html_with_default_docutilsconf(app): app.builder.build(['contents']) result = (app.outdir / 'contents.html').text(encoding='utf-8') assert regex_count(r'