summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/writers/html.py8
-rw-r--r--tests/roots/test-docutilsconf/conf.py5
-rw-r--r--tests/roots/test-docutilsconf/contents.txt15
-rw-r--r--tests/roots/test-docutilsconf/docutils.conf0
-rw-r--r--tests/test_docutilsconf.py101
5 files changed, 129 insertions, 0 deletions
diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py
index ba26628d..f6716957 100644
--- a/sphinx/writers/html.py
+++ b/sphinx/writers/html.py
@@ -12,6 +12,7 @@
import sys
import posixpath
import os
+import copy
from docutils import nodes
from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator
@@ -32,6 +33,13 @@ except ImportError:
# http://www.arnebrodowski.de/blog/write-your-own-restructuredtext-writer.html
class HTMLWriter(Writer):
+
+ # override embed-stylesheet default value to 0.
+ settings_spec = copy.deepcopy(Writer.settings_spec)
+ for _setting in settings_spec[2]:
+ if '--embed-stylesheet' in _setting[1]:
+ _setting[2]['default'] = 0
+
def __init__(self, builder):
Writer.__init__(self)
self.builder = builder
diff --git a/tests/roots/test-docutilsconf/conf.py b/tests/roots/test-docutilsconf/conf.py
new file mode 100644
index 00000000..67074ec6
--- /dev/null
+++ b/tests/roots/test-docutilsconf/conf.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+project = 'Sphinx docutils conf <Tests>'
+source_suffix = '.txt'
+keep_warnings = True
diff --git a/tests/roots/test-docutilsconf/contents.txt b/tests/roots/test-docutilsconf/contents.txt
new file mode 100644
index 00000000..3d0003b8
--- /dev/null
+++ b/tests/roots/test-docutilsconf/contents.txt
@@ -0,0 +1,15 @@
+docutils conf
+=============
+
+field-name-limit
+----------------
+
+:short: desc
+:long long long long: long title
+
+option-limit
+------------
+
+--short short desc
+--long-long-long-long long desc
+
diff --git a/tests/roots/test-docutilsconf/docutils.conf b/tests/roots/test-docutilsconf/docutils.conf
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/roots/test-docutilsconf/docutils.conf
diff --git a/tests/test_docutilsconf.py b/tests/test_docutilsconf.py
new file mode 100644
index 00000000..08534ed7
--- /dev/null
+++ b/tests/test_docutilsconf.py
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+"""
+ test_docutilsconf
+ ~~~~~~~~~~~~~~~~~
+
+ Test docutils.conf support for several writers.
+
+ :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import os
+import re
+from StringIO import StringIO
+from functools import wraps
+
+from util import test_roots, TestApp
+
+
+html_warnfile = 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'<th class="field-name">', result) == 1
+ assert regex_count(r'<th class="field-name" colspan="2">', result) == 1
+ assert regex_count(r'<td class="option-group">', result) == 1
+ assert regex_count(r'<td class="option-group" colspan="2">', result) == 1
+
+
+@with_conf_app(buildername='html', docutilsconf=(
+ '\n[html4css1 writer]'
+ '\noption-limit:1'
+ '\nfield-name-limit:1'
+ '\n')
+)
+def test_html_with_docutilsconf(app):
+ app.builder.build(['contents'])
+ result = (app.outdir / 'contents.html').text(encoding='utf-8')
+
+ assert regex_count(r'<th class="field-name">', result) == 0
+ assert regex_count(r'<th class="field-name" colspan="2">', result) == 2
+ assert regex_count(r'<td class="option-group">', result) == 0
+ assert regex_count(r'<td class="option-group" colspan="2">', result) == 2
+
+
+@with_conf_app(buildername='html', warning=html_warnfile)
+def test_html(app):
+ app.builder.build(['contents'])
+ assert html_warnfile.getvalue() == ''
+
+
+@with_conf_app(buildername='latex', warning=html_warnfile)
+def test_latex(app):
+ app.builder.build(['contents'])
+ assert html_warnfile.getvalue() == ''
+
+
+@with_conf_app(buildername='man', warning=html_warnfile)
+def test_man(app):
+ app.builder.build(['contents'])
+ assert html_warnfile.getvalue() == ''
+
+
+@with_conf_app(buildername='texinfo', warning=html_warnfile)
+def test_texinfo(app):
+ app.builder.build(['contents'])
+ assert html_warnfile.getvalue() == ''