4 # Author: Lea Wiemann <LeWiemann@gmail.com>
5 # Copyright: This module has been placed in the public domain.
8 Test module for the --record-dependencies option.
14 import DocutilsTestSupport
# must be imported before docutils
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(),
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'),
45 # this is a URL, not a path:
48 def test_csv_dependencies(self
):
52 self
.get_record(source_path
=os
.path
.join('data',
54 ['data/csv_data.txt'])
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__':