~ubuntu-branches/ubuntu/karmic/python-docutils/karmic

« back to all changes in this revision

Viewing changes to test/test_dependencies.py

  • Committer: Bazaar Package Importer
  • Author(s): martin f. krafft
  • Date: 2006-07-10 11:45:05 UTC
  • mfrom: (2.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20060710114505-otkhqcslevewxmz5
Tags: 0.4-3
Added build dependency on python-central (closes: #377580).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
# Author: Felix Wiemann
 
4
# Contact: Felix_Wiemann@ososo.de
 
5
# Revision: $Revision: 4132 $
 
6
# Date: $Date: 2005-12-03 03:13:12 +0100 (Sat, 03 Dec 2005) $
 
7
# Copyright: This module has been placed in the public domain.
 
8
 
 
9
"""
 
10
Test module for the --record-dependencies option.
 
11
"""
 
12
 
 
13
import os.path
 
14
import unittest
 
15
import sys
 
16
import DocutilsTestSupport              # must be imported before docutils
 
17
import docutils.core
 
18
import docutils.utils
 
19
 
 
20
 
 
21
class RecordDependenciesTests(unittest.TestCase):
 
22
 
 
23
    def setUp(self):
 
24
        os.chdir(os.path.join(DocutilsTestSupport.testroot, 'data'))
 
25
 
 
26
    def get_record(self, inputfile=None, **settings):
 
27
 
 
28
        recordfile = 'record.txt'
 
29
        settings.setdefault('source_path', 'dependencies.txt')
 
30
        settings.setdefault('settings_overrides', {})
 
31
        settings['settings_overrides'] = settings['settings_overrides'].copy()
 
32
        settings['settings_overrides']['_disable_config'] = 1
 
33
        if not settings['settings_overrides'].has_key('record_dependencies'):
 
34
            settings['settings_overrides']['record_dependencies'] = \
 
35
                docutils.utils.DependencyList(recordfile)
 
36
        docutils.core.publish_file(destination=DocutilsTestSupport.DevNull(),
 
37
                                   **settings)
 
38
        settings['settings_overrides']['record_dependencies'].close()
 
39
        return open(recordfile).read().splitlines()
 
40
 
 
41
    def test_dependencies(self):
 
42
        self.assertEqual(self.get_record(),
 
43
                         ['include.txt',
 
44
                          'raw.txt'])
 
45
        self.assertEqual(self.get_record(writer_name='latex'),
 
46
                         ['include.txt',
 
47
                          'raw.txt',
 
48
                          'some_image.png'])
 
49
 
 
50
    def test_csv_dependencies(self):
 
51
        try:
 
52
            import csv
 
53
            self.assertEqual(self.get_record(source_path='csv_dep.txt'),
 
54
                             ['csv_data.txt'])
 
55
        except ImportError:
 
56
            pass
 
57
 
 
58
    def test_stylesheet_dependencies(self):
 
59
        # Parameters to publish_file.
 
60
        s = {'settings_overrides': {}}
 
61
        so = s['settings_overrides']
 
62
        so['embed_stylesheet'] = 0
 
63
        so['stylesheet_path'] = 'stylesheet.txt'
 
64
        so['stylesheet'] = None
 
65
        s['writer_name'] = 'html'
 
66
        self.assert_('stylesheet.txt' not in
 
67
                     self.get_record(**s))
 
68
        so['embed_stylesheet'] = 1
 
69
        self.assert_('stylesheet.txt' in
 
70
                     self.get_record(**s))
 
71
        del so['embed_stylesheet']
 
72
        s['writer_name'] = 'latex'
 
73
        self.assert_('stylesheet.txt' in
 
74
                     self.get_record(**s))
 
75
 
 
76
 
 
77
if __name__ == '__main__':
 
78
    unittest.main()