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',
27 'default-stylesheet': u
'../docutils/writers/html4css1/html4css1.css',
31 class RecordDependenciesTests(unittest
.TestCase
):
33 def get_record(self
, **settings
):
34 recordfile
= 'record.txt'
35 recorder
= docutils
.utils
.DependencyList(recordfile
)
36 # (Re) create the record file by running a conversion:
37 settings
.setdefault('source_path',
38 os
.path
.join('data', 'dependencies.txt'))
39 settings
.setdefault('settings_overrides', {})
40 settings
['settings_overrides'].update(_disable_config
=True,
41 record_dependencies
=recorder
)
42 docutils
.core
.publish_file(destination
=DocutilsTestSupport
.DevNull(),
45 # Read the record file:
46 record
= docutils
.io
.FileInput(source_path
=recordfile
,
48 return record
.read().splitlines()
50 def test_dependencies(self
):
51 # Note: currently, raw input files are read (and hence recorded) while
52 # parsing even if not used in the chosen output format.
53 # This should change (see parsers/rst/directives/misc.py).
54 keys
= ['include', 'raw']
56 keys
+= ['figure-image']
57 expected
= [paths
[key
] for key
in keys
]
58 record
= self
.get_record(writer_name
='xml')
59 # the order of the files is arbitrary
62 self
.assertEqual(record
, expected
)
64 def test_dependencies_html(self
):
65 keys
= ['include', 'raw', 'default-stylesheet']
67 keys
+= ['figure-image', 'scaled-image']
68 expected
= [paths
[key
] for key
in keys
]
69 record
= self
.get_record(writer_name
='html')
70 # the order of the files is arbitrary
73 self
.assertEqual(record
, expected
)
75 def test_dependencies_latex(self
):
76 # since 0.9, the latex writer records only really accessed files, too
77 # Note: currently, raw input files are read (and hence recorded) while
78 # parsing even if not used in the chosen output format.
79 # This should change (see parsers/rst/directives/misc.py).
80 keys
= ['include', 'raw']
82 keys
+= ['figure-image']
83 expected
= [paths
[key
] for key
in keys
]
84 record
= self
.get_record(writer_name
='latex')
85 # the order of the files is arbitrary
88 self
.assertEqual(record
, expected
)
90 def test_csv_dependencies(self
):
93 csvsource
= os
.path
.join('data', 'csv_dep.txt')
94 self
.assertEqual(self
.get_record(source_path
=csvsource
),
95 ['data/csv_data.txt'])
99 def test_stylesheet_dependencies(self
):
100 stylesheet
= paths
['stylesheet']
101 so
= {'stylesheet_path': paths
['stylesheet'],
104 so
['embed_stylesheet'] = False
105 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
106 self
.assert_(stylesheet
not in record
,
107 '%r should not be in %r' % (stylesheet
, record
))
108 record
= self
.get_record(writer_name
='latex', settings_overrides
=so
)
109 self
.assert_(stylesheet
not in record
,
110 '%r should not be in %r' % (stylesheet
, record
))
112 so
['embed_stylesheet'] = True
113 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
114 self
.assert_(stylesheet
in record
,
115 '%r should be in %r' % (stylesheet
, record
))
116 record
= self
.get_record(writer_name
='latex', settings_overrides
=so
)
117 self
.assert_(stylesheet
in record
,
118 '%r should be in %r' % (stylesheet
, record
))
121 if __name__
== '__main__':