File: test_parser.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 (37 lines) | stat: -rw-r--r-- 1,214 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
#! /usr/bin/env python

# $Id: test_parser.py 5889 2009-04-01 20:00:21Z gbrandl $
# Author: Stefan Rank <strank(AT)strank(DOT)info>
# Copyright: This module has been placed in the public domain.

"""
Tests for basic functionality of parser classes.
"""

import sys
import unittest
import DocutilsTestSupport              # must be imported before docutils
import docutils
from docutils import parsers, utils, frontend
from docutils._compat import b


class RstParserTests(unittest.TestCase):

    def test_inputrestrictions(self):
        parser_class = parsers.get_parser_class('rst')
        parser = parser_class()
        document = utils.new_document('test data', frontend.OptionParser(
                    components=(parser, )).get_default_values())

        if sys.version_info < (3,):
            # supplying string input is supported, but only if ascii-decodable
            self.assertRaises(UnicodeError, # UnicodeDecodeError since py2.3
                              parser.parse, b('hol%s' % chr(224)), document)
        else:
            # input must be unicode at all times
            self.assertRaises(TypeError, parser.parse, b('hol'), document)


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