translations de: pull-quote = Seitenansprache, use utf8 for umlauts
[docutils.git] / test / test_dependencies.py
blob90565335f515a60cc5096084117f3e6920ebff38
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
17 import docutils.io
20 class RecordDependenciesTests(unittest.TestCase):
22 # docutils.utils.DependencyList records relative URLs, not platform paths,
23 # so use "/" as a path separator even on Windows (not os.path.join).
25 def get_record(self, **settings):
26 recordfile = 'record.txt'
27 settings.setdefault('source_path',
28 os.path.join('data', 'dependencies.txt'))
29 settings.setdefault('settings_overrides', {})
30 settings['settings_overrides'] = settings['settings_overrides'].copy()
31 settings['settings_overrides']['_disable_config'] = 1
32 if 'record_dependencies' not in settings['settings_overrides']:
33 settings['settings_overrides']['record_dependencies'] = \
34 docutils.utils.DependencyList(recordfile)
35 docutils.core.publish_file(
36 destination=DocutilsTestSupport.DevNull(), **settings)
37 settings['settings_overrides']['record_dependencies'].close()
38 record = docutils.io.FileInput(source_path=recordfile,
39 encoding=sys.getfilesystemencoding())
40 return record.read().splitlines()
42 def test_dependencies(self):
43 self.assertEqual(self.get_record(),
44 ['data/include.txt', 'data/raw.txt'])
45 self.assertEqual(self.get_record(writer_name='latex'),
46 ['data/include.txt',
47 'data/raw.txt',
48 # this is a URL, not a path:
49 'some_image.png',
50 # cyrillic filename (testing with an image, because
51 # this does not abort if the file does not exist):
52 u'\u043a\u0430\u0440\u0442\u0438\u043d\u0430.jpg'])
54 def test_csv_dependencies(self):
55 try:
56 import csv
57 self.assertEqual(
58 self.get_record(source_path=os.path.join('data',
59 'csv_dep.txt')),
60 ['data/csv_data.txt'])
61 except ImportError:
62 pass
64 def test_stylesheet_dependencies(self):
65 # Parameters to publish_file.
66 s = {'settings_overrides': {}}
67 so = s['settings_overrides']
68 so['embed_stylesheet'] = 0
69 # must use '/', not os.sep or os.path.join, because of URL handling
70 # (see docutils.utils.relative_path):
71 stylesheet_path = 'data/stylesheet.txt'
72 so['stylesheet_path'] = stylesheet_path
73 so['stylesheet'] = None
74 s['writer_name'] = 'html'
75 record = self.get_record(**s)
76 self.assert_(stylesheet_path not in record,
77 '%r should not be in %r' % (stylesheet_path, record))
78 so['embed_stylesheet'] = 1
79 record = self.get_record(**s)
80 self.assert_(stylesheet_path in record,
81 '%r should be in %r' % (stylesheet_path, record))
82 s['writer_name'] = 'latex'
83 record = self.get_record(**s)
84 self.assert_(stylesheet_path in record,
85 '%r should be in %r' % (stylesheet_path, record))
86 del so['embed_stylesheet']
87 record = self.get_record(**s)
88 self.assert_(stylesheet_path not in record,
89 '%r should not be in %r' % (stylesheet_path, record))
92 if __name__ == '__main__':
93 unittest.main()