test_dependencies.py :  » Development » Docutils » docutils » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Docutils 
Docutils » docutils » test » test_dependencies.py
#! /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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.