diff options
| author | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2013-03-02 16:27:22 +0000 |
|---|---|---|
| committer | milde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2013-03-02 16:27:22 +0000 |
| commit | a20b056453a444512c0d076023c0e3be562dc27a (patch) | |
| tree | d45eaa8d6fad308e337c723fe57d4a8a6e124152 /test | |
| parent | cd9a7ae9d077b7e45ba59316b049b18f29c717e8 (diff) | |
| download | docutils-a20b056453a444512c0d076023c0e3be562dc27a.tar.gz | |
New setting `stylesheet_dirs`.
Comma-separated list of directories where stylesheets are found. Used by
`stylesheet_path` when expanding relative path arguments.
Now, it is easy to add a custom stylesheet to Docutils default
stylesheet with, e.g., --stylesheet_path="html4css1.css, mystyle.css"
Changed behaviour of the default settings:
if there is a file "html4css1.css" in the working directory of the
process at launch, it is used instead of the one provided by Docutils
in the writer source directory.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils@7618 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'test')
| -rwxr-xr-x | test/test_utils.py | 13 | ||||
| -rwxr-xr-x | test/test_writers/test_html4css1_misc.py | 80 |
2 files changed, 78 insertions, 15 deletions
diff --git a/test/test_utils.py b/test/test_utils.py index dec123ee4..fd8d0d273 100755 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -287,6 +287,19 @@ class HelperFunctionsTests(unittest.TestCase): target = os.path.join(u'eggs', u'fileB') self.assertEqual(utils.relative_path(None, target), u'eggs/fileB') + def test_find_file_in_dirs(self): + # Search for file `path` in the sequence of directories `dirs`. + # Return the first expansion that matches an existing file. + dirs = ('nonex', '.', '..') + self.assertEqual(utils.find_file_in_dirs('HISTORY.txt', dirs), + '../HISTORY.txt') + # Return `path` if the file exists in the cwd or if there is no match + self.assertEqual(utils.find_file_in_dirs('alltests.py', dirs), + 'alltests.py') + self.assertEqual(utils.find_file_in_dirs('gibts/nicht.txt', dirs), + 'gibts/nicht.txt') + + if __name__ == '__main__': unittest.main() diff --git a/test/test_writers/test_html4css1_misc.py b/test/test_writers/test_html4css1_misc.py index b0f32a351..b011a1566 100755 --- a/test/test_writers/test_html4css1_misc.py +++ b/test/test_writers/test_html4css1_misc.py @@ -30,12 +30,62 @@ class EncodingTestCase(DocutilsTestSupport.StandardTestCase): # xmlcharrefreplace handler is used. self.assertIn(b('EUR = €'), result) +class SettingsTestCase(DocutilsTestSupport.StandardTestCase): + data = 'test' + + def test_default_stylesheet(self): + # default style sheet, embedded + mysettings = {'_disable_config': True,} + styles = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['stylesheet'] + self.assertIn('Default cascading style sheet ' + 'for the HTML output of Docutils.', styles) + + def test_default_stylesheet_linked(self): + # default style sheet, linked + mysettings = {'_disable_config': True, + 'embed_stylesheet': False} + styles = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['stylesheet'] + self.assertIn('docutils/writers/html4css1/html4css1.css', styles) + + def test_math_stylesheet_linked(self): + # default + math style sheet, linked + mysettings = {'_disable_config': True, + 'embed_stylesheet': False, + 'stylesheet_path': 'html4css1.css, math.css'} + styles = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['stylesheet'] + self.assertIn('docutils/writers/html4css1/html4css1.css', styles) + self.assertIn('docutils/writers/html4css1/math.css', styles) + + def test_custom_stylesheet_linked(self): + # default + custom style sheet, linked + mysettings = {'_disable_config': True, + 'embed_stylesheet': False, + 'stylesheet_path': 'html4css1.css, ' + 'data/ham.css'} + styles = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['stylesheet'] + self.assertIn('docutils/writers/html4css1/html4css1.css', styles) + self.assertIn('href="data/ham.css"', styles) + + def test_custom_stylesheet_dir(self): + mysettings = {'_disable_config': True, + 'embed_stylesheet': False, + 'stylesheet_dirs': ('../docutils/writers/html4css1/', + 'data'), + 'stylesheet_path': 'html4css1.css, ham.css'} + styles = core.publish_parts(self.data, writer_name='html4css1', + settings_overrides=mysettings)['stylesheet'] + self.assertIn('docutils/writers/html4css1/html4css1.css', styles) + self.assertIn('href="data/ham.css"', styles) + class MathTestCase(DocutilsTestSupport.StandardTestCase): - + """Attention: This class tests the current implementation of maths support which is open to change in future Docutils releases. """ - settings_overrides={'_disable_config': True,} mathjax_script = '<script type="text/javascript" src="%s">' default_mathjax_url = ('http://cdn.mathjax.org/mathjax/latest/MathJax.js' '?config=TeX-AMS-MML_HTMLorMML') @@ -45,40 +95,40 @@ class MathTestCase(DocutilsTestSupport.StandardTestCase): def test_math_output_default(self): # Currently MathJax with default URL. Likely to change to HTML! - mysettings = self.settings_overrides + mysettings = {'_disable_config': True,} head = core.publish_parts(self.data, writer_name='html4css1', settings_overrides=mysettings)['head'] self.assertIn(self.mathjax_script % self.default_mathjax_url, head) - + def test_math_output_mathjax(self): # Explicitly specifying math_output=MathJax, case insensitively # use default MathJax URL - mysettings = self.settings_overrides.copy() - mysettings.update({'math_output': 'MathJax'}) + mysettings = {'_disable_config': True, + 'math_output': 'MathJax'} head = core.publish_parts(self.data, writer_name='html4css1', settings_overrides=mysettings)['head'] self.assertIn(self.mathjax_script % self.default_mathjax_url, head) def test_math_output_mathjax_custom(self): # Customizing MathJax URL - mysettings = self.settings_overrides.copy() - mysettings.update({'math_output': - 'mathjax %s' % self.custom_mathjax_url}) + mysettings = {'_disable_config': True, + 'math_output': + 'mathjax %s' % self.custom_mathjax_url} head = core.publish_parts(self.data, writer_name='html4css1', settings_overrides=mysettings)['head'] self.assertIn(self.mathjax_script % self.custom_mathjax_url, head) - + def test_math_output_html(self): # There should be no MathJax script when math_output is not MathJax - mysettings = self.settings_overrides.copy() - mysettings.update({'math_output': 'HTML'}) + mysettings = {'_disable_config': True, + 'math_output': 'HTML'} head = core.publish_parts(self.data, writer_name='html4css1', settings_overrides=mysettings)['head'] self.assertNotIn('MathJax.js', head) - + def test_math_output_mathjax_no_math(self): - mysettings = self.settings_overrides.copy() - mysettings.update({'math_output': 'MathJax'}) + mysettings = {'_disable_config': True, + 'math_output': 'MathJax'} # There should be no math script when text does not contain math head = core.publish_parts('No math.', writer_name='html4css1')['head'] self.assertNotIn('MathJax', head) |
