git-svn-id: https://docutils.svn.sourceforge.net/svnroot/docutils/trunk/docutils...
[docutils.git] / test / test_dependencies.py
blob46e8ff8461f4289b7a9f30f297ca899534385baf
1 #! /usr/bin/env python
3 # Author: Felix Wiemann
4 # Contact: Felix_Wiemann@ososo.de
5 # Revision: $Revision$
6 # Date: $Date$
7 # Copyright: This module has been placed in the public domain.
9 """
10 Test module for the --record-dependencies option.
11 """
13 import os.path
14 import unittest
15 import sys
16 import DocutilsTestSupport # must be imported before docutils
17 import docutils.core
18 import docutils.utils
21 class RecordDependenciesTests(unittest.TestCase):
23 def setUp(self):
24 os.chdir(os.path.join(DocutilsTestSupport.testroot, 'data'))
26 def get_record(self, inputfile=None, **settings):
28 recordfile = 'record.txt'
29 settings.setdefault('source_path', 'dependencies.txt')
30 settings.setdefault('settings_overrides', {})
31 settings['settings_overrides'] = settings['settings_overrides'].copy()
32 settings['settings_overrides']['_disable_config'] = 1
33 if not settings['settings_overrides'].has_key('record_dependencies'):
34 settings['settings_overrides']['record_dependencies'] = \
35 docutils.utils.DependencyList(recordfile)
36 docutils.core.publish_file(destination=DocutilsTestSupport.DevNull(),
37 **settings)
38 settings['settings_overrides']['record_dependencies'].close()
39 return open(recordfile).read().splitlines()
41 def test_dependencies(self):
42 self.assertEqual(self.get_record(),
43 ['include.txt',
44 'raw.txt'])
45 self.assertEqual(self.get_record(writer_name='latex'),
46 ['include.txt',
47 'raw.txt',
48 'some_image.png'])
50 def test_csv_dependencies(self):
51 try:
52 import csv
53 self.assertEqual(self.get_record(source_path='csv_dep.txt'),
54 ['csv_data.txt'])
55 except ImportError:
56 pass
58 def test_stylesheet_dependencies(self):
59 # Parameters to publish_file.
60 s = {'settings_overrides': {}}
61 so = s['settings_overrides']
62 so['embed_stylesheet'] = 0
63 so['stylesheet_path'] = 'stylesheet.txt'
64 so['stylesheet'] = None
65 s['writer_name'] = 'html'
66 self.assert_('stylesheet.txt' not in
67 self.get_record(**s))
68 so['embed_stylesheet'] = 1
69 self.assert_('stylesheet.txt' in
70 self.get_record(**s))
71 del so['embed_stylesheet']
72 s['writer_name'] = 'latex'
73 self.assert_('stylesheet.txt' in
74 self.get_record(**s))
77 if __name__ == '__main__':
78 unittest.main()