import csv except ImportError: csv = None def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s mydir = 'test_parsers/test_rst/test_directives/' utf_16_csv = os.path.join(mydir, 'utf-16.csv') utf_16_csv_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_csv) empty_txt = os.path.join(mydir, 'empty.txt') unichr_exception = DocutilsTestSupport.exception_data( 'unichr(int("9999999999999", 16))')[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: unichr_exception_string = str(unichr_exception) null_bytes_code = """ import csv import cStringIO csv_data = open('%s', 'rb').read() csv_file = cStringIO.StringIO(csv_data) reader = csv.reader(csv_file) reader.next() """ % utf_16_csv null_bytes_exception = DocutilsTestSupport.exception_data(null_bytes_code)[0]
<system_message level="3" line="70" source="%(source)s" type="ERROR"> <paragraph> Unknown directive type "unknown". <literal_block xml:space="preserve"> .. unknown:: directive (info still reported with wrong line) <system_message level="3" line="72" source="%(source)s" type="ERROR"> <paragraph> Malformed table. No bottom table border found. <literal_block xml:space="preserve"> ============== ====== A simple table with no bottom border """ % {'source': reldir(include10), 'nonexistent': reldir(nonexistent), 'unichr_exception': DocutilsTestSupport.exception_data(unichr, int("11111111", 16))[2] }], ["""\ Include file with whitespace in the path: .. include:: %s """ % reldir(include11), """\ <document source="test data"> <paragraph> Include file with whitespace in the path: <paragraph> some text """], ["""\ Standard include data file:
from docutils.parsers.rst.directives import tables def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s mydir = 'test_parsers/test_rst/test_directives/' utf_16_csv = os.path.join(mydir, 'utf-16.csv') utf_16_csv_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_csv) empty_txt = os.path.join(mydir, 'empty.txt') unichr_exception = DocutilsTestSupport.exception_data(unichr, int("9999999999999", 16))[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: unichr_exception_string = str(unichr_exception) # some error messages changed in Python 3.3: csv_eod_error_str = 'unexpected end of data' if sys.version_info < (3, 2, 4) and not ( # backport to 2.7.4 sys.version_info[:2] == (2, 7) and sys.version_info[2] > 3): csv_eod_error_str = 'newline inside string' csv_unknown_url = "'bogus.csv'" if sys.version_info < (3, 3, 2): csv_unknown_url = "bogus.csv"
[ """\ .. image:: picture.png :scale: """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option value: (option: "scale"; value: None) %s. <literal_block xml:space="preserve"> .. image:: picture.png :scale: """ % DocutilsTestSupport.exception_data(int, None)[1][0] ], [ """\ .. image:: picture.png :height: 100 :scale 50 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option block. <literal_block xml:space="preserve"> .. image:: picture.png :height: 100
"""\ .. image:: picture.png :scale: """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option value: (option: "scale"; value: None) %s. <literal_block xml:space="preserve"> .. image:: picture.png :scale: """ % DocutilsTestSupport.exception_data(int, None)[1][0], ], [ """\ .. image:: picture.png :height: 100 :scale 50 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option block. <literal_block xml:space="preserve"> .. image:: picture.png
import csv from docutils._compat import u_prefix from docutils.parsers.rst.directives import tables def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s mydir = 'test_parsers/test_rst/test_directives/' utf_16_csv = os.path.join(mydir, 'utf-16.csv') utf_16_csv_rel = DocutilsTestSupport.utils.relative_path(None, utf_16_csv) empty_txt = os.path.join(mydir, 'empty.txt') unichr_exception = DocutilsTestSupport.exception_data( unichr, int("9999999999999", 16))[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: unichr_exception_string = str(unichr_exception) def null_bytes(): import csv csv_data = open(utf_16_csv, 'rb').read() csv_data = unicode(csv_data, 'latin1').splitlines() reader = csv.reader([tables.CSVTable.encode_for_csv(line + '\n') for line in csv_data]) reader.next() null_bytes_exception = DocutilsTestSupport.exception_data(null_bytes)[0]
"""], ["""\ .. image:: picture.png :scale: """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option value: (option: "scale"; value: None) %s. <literal_block xml:space="preserve"> .. image:: picture.png :scale: """ % DocutilsTestSupport.exception_data('int(None)')[1][0]], ["""\ .. image:: picture.png :scale 50 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option block. <literal_block xml:space="preserve"> .. image:: picture.png :scale 50 """], ["""\
[ """\ .. contents:: :depth: two """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "contents" directive: invalid option value: (option: "depth"; value: 'two') %s. <literal_block xml:space="preserve"> .. contents:: :depth: two """ % DocutilsTestSupport.exception_data(int, "two")[1][0] ], [ """\ .. contents:: :width: 2 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "contents" directive: unknown option: "width". <literal_block xml:space="preserve"> .. contents:: :width: 2 """
unicode:: 0x111111111111111111 <system_message level="2" line="2" source="test data" type="WARNING"> <paragraph> Substitution definition "too big for int" empty or invalid. <literal_block xml:space="preserve"> .. |too big for int| unicode:: 0x111111111111111111 <system_message level="3" line="3" source="test data" type="ERROR"> <paragraph> Invalid character code: 0x11111111 %s <literal_block xml:space="preserve"> unicode:: 0x11111111 <system_message level="2" line="3" source="test data" type="WARNING"> <paragraph> Substitution definition "too big for unicode" empty or invalid. <literal_block xml:space="preserve"> .. |too big for unicode| unicode:: 0x11111111 """ % ([DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0], 'code too large (%s)' % DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0]] [isinstance(DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0], OverflowError)], DocutilsTestSupport.exception_data('unichr(int("11111111", 16))')[2])] ] if __name__ == '__main__': import unittest unittest.main(defaultTest='suite')
# Author: David Goodger <*****@*****.**> # Copyright: This module has been placed in the public domain. """ Tests for misc.py "unicode" directive. """ from __init__ import DocutilsTestSupport def suite(): s = DocutilsTestSupport.ParserTestSuite() s.generateTests(totest) return s unichr_exception = DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0] if isinstance(unichr_exception, OverflowError): unichr_exception_string = 'code too large (%s)' % unichr_exception else: unichr_exception_string = str(unichr_exception) totest = {} totest['unicode'] = [ [""" Insert an em-dash (|mdash|), a copyright symbol (|copy|), a non-breaking space (|nbsp|), a backwards-not-equals (|bne|), and a captial omega (|Omega|). .. |mdash| unicode:: 0x02014 .. |copy| unicode:: \\u00A9 .. |nbsp| unicode::  
"""], ["""\ .. contents:: :depth: two """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "contents" directive: invalid option value: (option: "depth"; value: 'two') %s. <literal_block xml:space="preserve"> .. contents:: :depth: two """ % DocutilsTestSupport.exception_data(int, "two")[1][0]], ["""\ .. contents:: :width: 2 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "contents" directive: unknown option: "width". <literal_block xml:space="preserve"> .. contents:: :width: 2 """], ["""\
unicode:: 0x111111111111111111 <system_message level="2" line="2" source="test data" type="WARNING"> <paragraph> Substitution definition "too big for int" empty or invalid. <literal_block xml:space="preserve"> .. |too big for int| unicode:: 0x111111111111111111 <system_message level="3" line="3" source="test data" type="ERROR"> <paragraph> Invalid character code: 0x11111111 %s <literal_block xml:space="preserve"> unicode:: 0x11111111 <system_message level="2" line="3" source="test data" type="WARNING"> <paragraph> Substitution definition "too big for unicode" empty or invalid. <literal_block xml:space="preserve"> .. |too big for unicode| unicode:: 0x11111111 """ % ([DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0], 'code too large (%s)' % DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0]] [isinstance(DocutilsTestSupport.exception_data( 'unichr(int("111111111111111111", 16))')[0], OverflowError)], DocutilsTestSupport.exception_data('unichr(int("11111111", 16))')[2])] ] if __name__ == '__main__': import unittest unittest.main(defaultTest='suite')
[ """\ .. image:: picture.png :scale: """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option value: (option: "scale"; value: None) %s. <literal_block xml:space="preserve"> .. image:: picture.png :scale: """ % DocutilsTestSupport.exception_data('int(None)')[1][0] ], [ """\ .. image:: picture.png :scale 50 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option block. <literal_block xml:space="preserve"> .. image:: picture.png :scale 50 """
"""], ["""\ .. image:: picture.png :scale: """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option value: (option: "scale"; value: None) %s. <literal_block xml:space="preserve"> .. image:: picture.png :scale: """ % DocutilsTestSupport.exception_data(int, None)[1][0]], ["""\ .. image:: picture.png :height: 100 :scale 50 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "image" directive: invalid option block. <literal_block xml:space="preserve"> .. image:: picture.png :height: 100 :scale 50
"""], ["""\ .. contents:: :depth: two """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "contents" directive: invalid option value: (option: "depth"; value: 'two') %s. <literal_block xml:space="preserve"> .. contents:: :depth: two """ % DocutilsTestSupport.exception_data('int("two")')[1][0]], ["""\ .. contents:: :width: 2 """, """\ <document source="test data"> <system_message level="3" line="1" source="test data" type="ERROR"> <paragraph> Error in "contents" directive: unknown option: "width". <literal_block xml:space="preserve"> .. contents:: :width: 2 """], ["""\