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
):
34 if not hasattr(unittest
.TestCase
, "assertTrue"):
35 assertTrue
= unittest
.TestCase
.failUnless
37 def get_record(self
, **settings
):
38 recordfile
= 'record.txt'
39 recorder
= docutils
.utils
.DependencyList(recordfile
)
40 # (Re) create the record file by running a conversion:
41 settings
.setdefault('source_path',
42 os
.path
.join('data', 'dependencies.txt'))
43 settings
.setdefault('settings_overrides', {})
44 if sys
.version_info
< (2, 4):
45 # python 2.3 update() takes no keyword arguments
46 settings
['settings_overrides'].update({"_disable_config":True,
47 "record_dependencies":recorder
})
49 settings
['settings_overrides'].update(_disable_config
=True,
50 record_dependencies
=recorder
)
51 docutils
.core
.publish_file(destination
=DocutilsTestSupport
.DevNull(),
54 # Read the record file:
55 record
= docutils
.io
.FileInput(source_path
=recordfile
,
57 return record
.read().splitlines()
59 def test_dependencies(self
):
60 # Note: currently, raw input files are read (and hence recorded) while
61 # parsing even if not used in the chosen output format.
62 # This should change (see parsers/rst/directives/misc.py).
63 keys
= ['include', 'raw']
65 keys
+= ['figure-image']
66 expected
= [paths
[key
] for key
in keys
]
67 record
= self
.get_record(writer_name
='xml')
68 # the order of the files is arbitrary
71 self
.assertEqual(record
, expected
)
73 def test_dependencies_html(self
):
74 keys
= ['include', 'raw', 'default-stylesheet']
76 keys
+= ['figure-image', 'scaled-image']
77 expected
= [paths
[key
] for key
in keys
]
78 record
= self
.get_record(writer_name
='html')
79 # the order of the files is arbitrary
82 self
.assertEqual(record
, expected
)
84 def test_dependencies_latex(self
):
85 # since 0.9, the latex writer records only really accessed files, too
86 # Note: currently, raw input files are read (and hence recorded) while
87 # parsing even if not used in the chosen output format.
88 # This should change (see parsers/rst/directives/misc.py).
89 keys
= ['include', 'raw']
91 keys
+= ['figure-image']
92 expected
= [paths
[key
] for key
in keys
]
93 record
= self
.get_record(writer_name
='latex')
94 # the order of the files is arbitrary
97 self
.assertEqual(record
, expected
)
99 def test_csv_dependencies(self
):
102 csvsource
= os
.path
.join('data', 'csv_dep.txt')
103 self
.assertEqual(self
.get_record(source_path
=csvsource
),
104 ['data/csv_data.txt'])
108 def test_stylesheet_dependencies(self
):
109 stylesheet
= paths
['stylesheet']
110 so
= {'stylesheet_path': paths
['stylesheet'],
113 so
['embed_stylesheet'] = False
114 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
115 self
.assertTrue(stylesheet
not in record
,
116 '%r should not be in %r' % (stylesheet
, record
))
117 record
= self
.get_record(writer_name
='latex', settings_overrides
=so
)
118 self
.assertTrue(stylesheet
not in record
,
119 '%r should not be in %r' % (stylesheet
, record
))
121 so
['embed_stylesheet'] = True
122 record
= self
.get_record(writer_name
='html', settings_overrides
=so
)
123 self
.assertTrue(stylesheet
in record
,
124 '%r should be in %r' % (stylesheet
, record
))
125 record
= self
.get_record(writer_name
='latex', settings_overrides
=so
)
126 self
.assertTrue(stylesheet
in record
,
127 '%r should be in %r' % (stylesheet
, record
))
130 if __name__
== '__main__':