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
18 from docutils
.parsers
.rst
.directives
.images
import PIL
20 # docutils.utils.DependencyList records POSIX paths,
21 # i.e. "/" as a path separator even on Windows (not os.path.join).
22 paths
= {'include': u
'data/include.txt', # included rst file
23 'raw': u
'data/raw.txt', # included raw "HTML file"
24 'scaled-image': u
'../docs/user/rst/images/biohazard.png',
25 'figure-image': u
'../docs/user/rst/images/title.png',
26 'stylesheet': u
'data/stylesheet.txt',
30 class RecordDependenciesTests(unittest
.TestCase
):
32 def get_record(self
, **settings
):
33 recordfile
= 'record.txt'
34 recorder
= docutils
.utils
.DependencyList(recordfile
)
35 # (Re) create the record file by running a conversion:
36 settings
.setdefault('source_path',
37 os
.path
.join('data', 'dependencies.txt'))
38 settings
.setdefault('settings_overrides', {})
39 settings
['settings_overrides'].update(_disable_config
=True,
40 record_dependencies
=recorder
)
41 docutils
.core
.publish_file(destination
=DocutilsTestSupport
.DevNull(),
44 # Read the record file:
45 record
= docutils
.io
.FileInput(source_path
=recordfile
,
47 return record
.read().splitlines()
49 def test_dependencies(self
):
50 # Note: currently, raw input files are read (and hence recorded) while
51 # parsing even if not used in the chosen output format.
52 # This should change (see parsers/rst/directives/misc.py).
53 keys
= ['include', 'raw']
55 keys
+= ['figure-image']
56 expected
= [paths
[key
] for key
in keys
]
57 record
= self
.get_record(writer_name
='xml')
58 # the order of the files is arbitrary
61 self
.assertEqual(record
, expected
)
63 def test_dependencies_html(self
):
64 keys
= ['include', 'raw']
66 keys
+= ['figure-image', 'scaled-image']
67 expected
= [paths
[key
] for key
in keys
]
68 # stylesheets are tested separately in test_stylesheet_dependencies():
69 so
= {'stylesheet_path': None, 'stylesheet': None}
70 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
71 # the order of the files is arbitrary
74 self
.assertEqual(record
, expected
)
76 def test_dependencies_latex(self
):
77 # since 0.9, the latex writer records only really accessed files, too
78 # Note: currently, raw input files are read (and hence recorded) while
79 # parsing even if not used in the chosen output format.
80 # This should change (see parsers/rst/directives/misc.py).
81 keys
= ['include', 'raw']
83 keys
+= ['figure-image']
84 expected
= [paths
[key
] for key
in keys
]
85 record
= self
.get_record(writer_name
='latex')
86 # the order of the files is arbitrary
89 self
.assertEqual(record
, expected
)
91 def test_csv_dependencies(self
):
94 csvsource
= os
.path
.join('data', 'csv_dep.txt')
95 self
.assertEqual(self
.get_record(source_path
=csvsource
),
96 ['data/csv_data.txt'])
100 def test_stylesheet_dependencies(self
):
101 stylesheet
= paths
['stylesheet']
102 so
= {'stylesheet_path': paths
['stylesheet'],
105 so
['embed_stylesheet'] = False
106 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
107 self
.assertTrue(stylesheet
not in record
,
108 '%r should not be in %r' % (stylesheet
, record
))
109 record
= self
.get_record(writer_name
='latex', settings_overrides
=so
)
110 self
.assertTrue(stylesheet
not in record
,
111 '%r should not be in %r' % (stylesheet
, record
))
113 so
['embed_stylesheet'] = True
114 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
115 self
.assertTrue(stylesheet
in record
,
116 '%r should be in %r' % (stylesheet
, record
))
117 record
= self
.get_record(writer_name
='latex', settings_overrides
=so
)
118 self
.assertTrue(stylesheet
in record
,
119 '%r should be in %r' % (stylesheet
, record
))
122 if __name__
== '__main__':