add BUG comments
[docutils.git] / test / test_dependencies.py
blobe4ee80baaa1678e44bb22603bb1a8f1930b689ff
1 #! /usr/bin/env python
3 # $Id$
4 # Author: Lea Wiemann <LeWiemann@gmail.com>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Test module for the --record-dependencies option.
9 """
11 import os.path
12 import unittest
13 import sys
14 import DocutilsTestSupport # must be imported before docutils
15 import docutils.core
16 import docutils.utils
19 class RecordDependenciesTests(unittest.TestCase):
21 # docutils.utils.DependencyList records relative URLs, not platform paths,
22 # so use "/" as a path separator even on Windows (not os.path.join).
24 def get_record(self, **settings):
25 recordfile = 'record.txt'
26 settings.setdefault('source_path',
27 os.path.join('data', 'dependencies.txt'))
28 settings.setdefault('settings_overrides', {})
29 settings['settings_overrides'] = settings['settings_overrides'].copy()
30 settings['settings_overrides']['_disable_config'] = 1
31 if 'record_dependencies' not in settings['settings_overrides']:
32 settings['settings_overrides']['record_dependencies'] = \
33 docutils.utils.DependencyList(recordfile)
34 docutils.core.publish_file(destination=DocutilsTestSupport.DevNull(),
35 **settings)
36 settings['settings_overrides']['record_dependencies'].close()
37 return open(recordfile).read().splitlines()
39 def test_dependencies(self):
40 self.assertEqual(self.get_record(),
41 ['data/include.txt', 'data/raw.txt'])
42 self.assertEqual(self.get_record(writer_name='latex'),
43 ['data/include.txt',
44 'data/raw.txt',
45 # this is a URL, not a path:
46 'some_image.png'])
48 def test_csv_dependencies(self):
49 try:
50 import csv
51 self.assertEqual(
52 self.get_record(source_path=os.path.join('data',
53 'csv_dep.txt')),
54 ['data/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 # must use '/', not os.sep or os.path.join, because of URL handling
64 # (see docutils.utils.relative_path):
65 stylesheet_path = 'data/stylesheet.txt'
66 so['stylesheet_path'] = stylesheet_path
67 so['stylesheet'] = None
68 s['writer_name'] = 'html'
69 record = self.get_record(**s)
70 self.assert_(stylesheet_path not in record,
71 '%r should not be in %r' % (stylesheet_path, record))
72 so['embed_stylesheet'] = 1
73 record = self.get_record(**s)
74 self.assert_(stylesheet_path in record,
75 '%r should be in %r' % (stylesheet_path, record))
76 s['writer_name'] = 'latex'
77 record = self.get_record(**s)
78 self.assert_(stylesheet_path in record,
79 '%r should be in %r' % (stylesheet_path, record))
80 del so['embed_stylesheet']
81 record = self.get_record(**s)
82 self.assert_(stylesheet_path not in record,
83 '%r should not be in %r' % (stylesheet_path, record))
86 if __name__ == '__main__':
87 unittest.main()