File: test_dependencies.py

package info (click to toggle)
python-docutils 0.8.1-8
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,604 kB
  • sloc: python: 38,189; lisp: 7,807; sh: 142; makefile: 136; xml: 6
file content (87 lines) | stat: -rwxr-xr-x 3,443 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /usr/bin/env python

# $Id: test_dependencies.py 5720 2008-10-31 17:50:17Z goodger $
# Author: Lea Wiemann <LeWiemann@gmail.com>
# Copyright: This module has been placed in the public domain.

"""
Test module for the --record-dependencies option.
"""

import os.path
import unittest
import sys
import DocutilsTestSupport              # must be imported before docutils
import docutils.core
import docutils.utils


class RecordDependenciesTests(unittest.TestCase):

    # docutils.utils.DependencyList records relative URLs, not platform paths,
    # so use "/" as a path separator even on Windows (not os.path.join).

    def get_record(self, **settings):
        recordfile = 'record.txt'
        settings.setdefault('source_path',
                            os.path.join('data', 'dependencies.txt'))
        settings.setdefault('settings_overrides', {})
        settings['settings_overrides'] = settings['settings_overrides'].copy()
        settings['settings_overrides']['_disable_config'] = 1
        if 'record_dependencies' not in settings['settings_overrides']:
            settings['settings_overrides']['record_dependencies'] = \
                docutils.utils.DependencyList(recordfile)
        docutils.core.publish_file(destination=DocutilsTestSupport.DevNull(),
                                   **settings)
        settings['settings_overrides']['record_dependencies'].close()
        return open(recordfile).read().splitlines()

    def test_dependencies(self):
        self.assertEqual(self.get_record(),
                         ['data/include.txt', 'data/raw.txt'])
        self.assertEqual(self.get_record(writer_name='latex'),
                         ['data/include.txt',
                          'data/raw.txt',
                          # this is a URL, not a path:
                          'some_image.png'])

    def test_csv_dependencies(self):
        try:
            import csv
            self.assertEqual(
                self.get_record(source_path=os.path.join('data',
                                                         'csv_dep.txt')),
                ['data/csv_data.txt'])
        except ImportError:
            pass

    def test_stylesheet_dependencies(self):
        # Parameters to publish_file.
        s = {'settings_overrides': {}}
        so = s['settings_overrides']
        so['embed_stylesheet'] = 0
        # must use '/', not os.sep or os.path.join, because of URL handling
        # (see docutils.utils.relative_path):
        stylesheet_path = 'data/stylesheet.txt'
        so['stylesheet_path'] = stylesheet_path
        so['stylesheet'] = None
        s['writer_name'] = 'html'
        record = self.get_record(**s)
        self.assert_(stylesheet_path not in record,
                     '%r should not be in %r' % (stylesheet_path, record))
        so['embed_stylesheet'] = 1
        record = self.get_record(**s)
        self.assert_(stylesheet_path in record,
                     '%r should be in %r' % (stylesheet_path, record))
        s['writer_name'] = 'latex'
        record = self.get_record(**s)
        self.assert_(stylesheet_path in record,
                     '%r should be in %r' % (stylesheet_path, record))
        del so['embed_stylesheet']
        record = self.get_record(**s)
        self.assert_(stylesheet_path not in record,
                     '%r should not be in %r' % (stylesheet_path, record))


if __name__ == '__main__':
    unittest.main()