From edf2f3bec1de42965e347eb808f8604151c35bdb Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> Date: Wed, 2 Jul 2003 17:51:01 +0000 Subject: This commit was manufactured by cvs2svn to create branch 'ax'. git-svn-id: http://svn.code.sf.net/p/docutils/code/branches/ax@1551 929543f6-e4f2-0310-98a6-ba3bd3dd1d04 --- docutils/test/test_readers/test_python/__init__.py | 14 - docutils/test/test_readers/test_python/showast | 57 -- docutils/test/test_readers/test_python/showdoc | 33 - docutils/test/test_readers/test_python/showparse | 48 -- docutils/test/test_readers/test_python/showtok | 40 -- .../test_readers/test_python/test_functions.py | 56 -- .../test/test_readers/test_python/test_parser.py | 745 --------------------- .../test_readers/test_python/test_token_parser.py | 46 -- 8 files changed, 1039 deletions(-) delete mode 100644 docutils/test/test_readers/test_python/__init__.py delete mode 100755 docutils/test/test_readers/test_python/showast delete mode 100755 docutils/test/test_readers/test_python/showdoc delete mode 100755 docutils/test/test_readers/test_python/showparse delete mode 100755 docutils/test/test_readers/test_python/showtok delete mode 100644 docutils/test/test_readers/test_python/test_functions.py delete mode 100644 docutils/test/test_readers/test_python/test_parser.py delete mode 100644 docutils/test/test_readers/test_python/test_token_parser.py (limited to 'docutils/test/test_readers/test_python') diff --git a/docutils/test/test_readers/test_python/__init__.py b/docutils/test/test_readers/test_python/__init__.py deleted file mode 100644 index 2fe79c55c..000000000 --- a/docutils/test/test_readers/test_python/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -import os -import os.path -import sys - -sys.path.insert(0, os.path.abspath(os.curdir)) -prev = '' -while sys.path[0] != prev: - try: - import DocutilsTestSupport - break - except ImportError: - prev = sys.path[0] - sys.path[0] = os.path.dirname(prev) -sys.path.pop(0) diff --git a/docutils/test/test_readers/test_python/showast b/docutils/test/test_readers/test_python/showast deleted file mode 100755 index e7d846307..000000000 --- a/docutils/test/test_readers/test_python/showast +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env python - -""" -This is a tool for exploring abstract syntax trees generated by -``compiler.parse()`` from test data in -docutils/test/test_readers/test_python/test_parser or stdin. - -Usage:: - - showast - - showast < - -Where ```` is the key to the ``totest`` dictionary, and ```` is -the index of the list ``totest[key]``. If no arguments are given, stdin is -used for input. -""" - -import sys -import compiler -from compiler.ast import Node -import test_parser - -def pformat(ast, indent=' ', level=0): - assert isinstance(ast, Node), 'ast is not a Node: %r' % (ast,) - atts = {} - for name, value in vars(ast).items(): - if not value or isinstance(value, Node): - continue - if isinstance(value, list): - if isinstance(value[0], Node): - continue - if isinstance(value[0], tuple) and value[0] \ - and isinstance(value[0][0], Node): - continue - atts[name] = str(value).encode('unicode-escape') - attlist = atts.items() - attlist.sort() - parts = [ast.__class__.__name__] - for name, value in attlist: - parts.append('%s="%s"' % (name, value)) - result = ['%s<%s>\n' % (indent * level, ' '.join(parts))] - for node in ast.getChildNodes(): - result.extend(pformat(node, level=level+1)) - return result - -if len(sys.argv) > 1: - key, caseno = sys.argv[1:] - print 'totest["%s"][%s][0]:\n' % (key, caseno) - input_text = test_parser.totest[key][int(caseno)][0] -else: - input_text = sys.stdin.read() -print input_text -module = compiler.parse(input_text) -print module -print -print ''.join(pformat(module)), diff --git a/docutils/test/test_readers/test_python/showdoc b/docutils/test/test_readers/test_python/showdoc deleted file mode 100755 index 6461960f8..000000000 --- a/docutils/test/test_readers/test_python/showdoc +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env python - -""" -This is a tool for exploring module documentation trees generated by -``docutils.readers.python.moduleparser.parse_module()`` from test data in -docutils/test/test_readers/test_python/test_parser or stdin. - -Usage:: - - showdoc - - showdoc < - -Where ```` is the key to the ``totest`` dictionary, and ```` is -the index of the list ``totest[key]``. If no arguments are given, stdin is -used for input. -""" - -import sys -from docutils.readers.python.moduleparser import parse_module -import test_parser - -if len(sys.argv) > 1: - key, caseno = sys.argv[1:] - print 'totest["%s"][%s][0]:\n' % (key, caseno) - input_text = test_parser.totest[key][int(caseno)][0] - input_source = "test_parser.totest['%s'][%s][0]" % (key, caseno) -else: - input_text = sys.stdin.read() - input_source = '' -print input_text -module = parse_module(input_text, input_source) -print module, diff --git a/docutils/test/test_readers/test_python/showparse b/docutils/test/test_readers/test_python/showparse deleted file mode 100755 index 8144256d6..000000000 --- a/docutils/test/test_readers/test_python/showparse +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env python - -""" -This is a tool for exploring abstract syntax trees generated by -``parser.suite()`` from test data in -docutils/test/test_readers/test_python/test_parser or stdin. - -Usage:: - - showparse - - showparse < - -Where ```` is the key to the ``totest`` dictionary, and ```` is -the index of the list ``totest[key]``. If no arguments are given, stdin is -used for input. -""" - -import sys -import types -import parser -import token -import symbol -import pprint -import test_parser - -names = token.tok_name.copy() -names.update(symbol.sym_name) - -def name_elements(ast): - if ast: - name = names[ast[0]] - ast[0] = '%s (%s)' % (name, ast[0]) - for node in ast[1:]: - if type(node) == types.ListType: - name_elements(node) - -if len(sys.argv) > 1: - key, caseno = sys.argv[1:] - print 'totest["%s"][%s][0]:\n' % (key, caseno) - input_text = test_parser.totest[key][int(caseno)][0] -else: - input_text = sys.stdin.read() -print input_text -module = parser.suite(input_text) -ast = parser.ast2list(module, line_info=1) -name_elements(ast) -pprint.pprint(ast) diff --git a/docutils/test/test_readers/test_python/showtok b/docutils/test/test_readers/test_python/showtok deleted file mode 100755 index efd250ce1..000000000 --- a/docutils/test/test_readers/test_python/showtok +++ /dev/null @@ -1,40 +0,0 @@ -#! /usr/bin/env python - - -""" -This is a tool for exploring token lists generated by -``tokenize.generate_tokens()`` from test data in -docutils/test/test_readers/test_python/test_parser or stdin. - -Usage:: - - showtok - - showtok < - -Where ```` is the key to the ``totest`` dictionary, and ```` is -the index of the list ``totest[key]``. If no arguments are given, stdin is -used for input. -""" - -import sys -import tokenize -import pprint -from token import tok_name -import test_parser - -def name_tokens(tokens): - for i in range(len(tokens)): - tup = tokens[i] - tokens[i] = (tok_name[tup[0]], tup) - -if len(sys.argv) > 1: - key, caseno = sys.argv[1:] - print 'totest["%s"][%s][0]:\n' % (key, caseno) - input_text = test_parser.totest[key][int(caseno)][0] -else: - input_text = sys.stdin.read() -print input_text -tokens = list(tokenize.generate_tokens(iter(input_text.splitlines(1)).next)) -name_tokens(tokens) -pprint.pprint(tokens) diff --git a/docutils/test/test_readers/test_python/test_functions.py b/docutils/test/test_readers/test_python/test_functions.py deleted file mode 100644 index d521b2203..000000000 --- a/docutils/test/test_readers/test_python/test_functions.py +++ /dev/null @@ -1,56 +0,0 @@ -#! /usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -Tests for PySource Reader functions. -""" - -import unittest -from __init__ import DocutilsTestSupport -from docutils.readers.python.moduleparser import trim_docstring - - -class MiscTests(unittest.TestCase): - - docstrings = ( - ("""""", """"""), # empty - ("""Begins on the first line. - - Middle line indented. - - Last line unindented. - """, - """\ -Begins on the first line. - - Middle line indented. - -Last line unindented."""), - (""" - Begins on the second line. - - Middle line indented. - - Last line unindented.""", - """\ -Begins on the second line. - - Middle line indented. - -Last line unindented."""), - ("""All on one line.""", """All on one line.""")) - - def test_trim_docstring(self): - for docstring, expected in self.docstrings: - self.assertEquals(trim_docstring(docstring), expected) - self.assertEquals(trim_docstring('\n ' + docstring), - expected) - - -if __name__ == '__main__': - unittest.main() diff --git a/docutils/test/test_readers/test_python/test_parser.py b/docutils/test/test_readers/test_python/test_parser.py deleted file mode 100644 index ce70cc27c..000000000 --- a/docutils/test/test_readers/test_python/test_parser.py +++ /dev/null @@ -1,745 +0,0 @@ -#! /usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -Tests for docutils/readers/python/moduleparser.py. -""" - -from __init__ import DocutilsTestSupport - - -def suite(): - s = DocutilsTestSupport.PythonModuleParserTestSuite() - s.generateTests(totest) - return s - -totest = {} - -totest['module'] = [ -['''\ -''', -'''\ - -'''], -['''\ -"""docstring""" -''', -'''\ - - - docstring -'''], -['''\ -u"""Unicode docstring""" -''', -'''\ - - - Unicode docstring -'''], -['''\ -"""docstring""" -"""additional docstring""" -''', -'''\ - - - docstring - - additional docstring -'''], -['''\ -"""docstring""" -# comment -"""additional docstring""" -''', -'''\ - - - docstring - - additional docstring -'''], -['''\ -"""docstring""" -1 -"""not an additional docstring""" -''', -'''\ - - - docstring -'''], -] - -totest['import'] = [ -['''\ -import module -''', -'''\ - - - module -'''], -['''\ -import module as local -''', -'''\ - - - module as local -'''], -['''\ -import module.name -''', -'''\ - - - module.name -'''], -['''\ -import module.name as local -''', -'''\ - - - module.name as local -'''], -['''\ -import module -"""not documentable""" -''', -'''\ - - - module -'''], -] - -totest['from'] = [ -['''\ -from module import name -''', -'''\ - - - name -'''], -['''\ -from module import name as local -''', -'''\ - - - name as local -'''], -['''\ -from module import name1, name2 as local2 -''', -'''\ - - - name1 - name2 as local2 -'''], -['''\ -from module.sub import name -''', -'''\ - - - name -'''], -['''\ -from module.sub import name as local -''', -'''\ - - - name as local -'''], -['''\ -from module import * -''', -'''\ - - - * -'''], -['''\ -from __future__ import division -''', -'''\ - - - division -'''], -] - -totest['assign'] = [ -['''\ -a = 1 -''', -'''\ - - - - 1 -'''], -['''a = 1''', -'''\ - - - - 1 -'''], -['''\ -a = 1 -"""a's docstring""" -''', #" -'''\ - - - - 1 - - a's docstring -'''], #' -['''\ -a = 1 -"""a's docstring""" -"""additional docstring""" -''', #" -'''\ - - - - 1 - - a's docstring - - additional docstring -'''], #' -['''\ -a = 1 + 2 * 3 / 4 ** 5 -''', -'''\ - - - - 1 + 2 * 3 / 4 ** 5 -'''], -['''\ -a = 1 \\ - + 2 -''', -'''\ - - - - 1 + 2 -'''], -['''\ -a = not 1 and 2 or 3 -''', -'''\ - - - - not 1 and 2 or 3 -'''], -['''\ -a = ~ 1 & 2 | 3 ^ 4 -''', -'''\ - - - - ~ 1 & 2 | 3 ^ 4 -'''], -['''\ -a = `1 & 2` -''', -'''\ - - - - `1 & 2` -'''], -['''\ -very_long_name = \\ - x -''', -'''\ - - - - x -'''], -['''\ -very_long_name \\ - = x -''', -'''\ - - - - x -'''], -['''\ -very_long_name = \\ - another_long_name = \\ - x -''', -'''\ - - - - x - - - x -'''], -['''\ -a = (1 - + 2) -b = a.b[1 + - fn(x, y, - z, {'key': (1 + 2 - + 3)})][4] -c = """first line -second line - third""" -''', -'''\ - - - - (1 + 2) - - - a.b[1 + fn(x, y, z, {'key': (1 + 2 + 3)})][4] - - - """first line\\nsecond line\\n third""" -'''], -['''\ -a, b, c = range(3) -(d, e, - f) = a, b, c -g, h, i = j = a, b, c -k.a, k.b.c, k.d.e.f = a, b, c -''', -'''\ - - - - range(3) - - - a, b, c - - - a, b, c - - - a, b, c - - - a, b, c -'''], -['''\ -a = 1 ; b = 2 -print ; c = 3 -''', -'''\ - - - - 1 - - - 2 - - - 3 -'''], -['''\ -a.b = 1 -"""This assignment is noted but ignored unless ``a`` is a function.""" -''', -'''\ - - - - 1 - - This assignment is noted but ignored unless ``a`` is a function. -'''], -['''\ -a[b] = 1 -"""Subscript assignments are ignored.""" -''', -'''\ - -'''], -['''\ -a = foo(b=1) -''', -'''\ - - - - foo(b=1) -'''], -# ['''\ -# a = 1 -# -# """Because of the blank above, this is a module docstring.""" -# ''', -# '''\ -# -# -# -# 1 -# -# Because of the blank above, this is a module docstring. -# '''], -] - -totest['def'] = [ -['''\ -def f(): - """Function f's docstring""" - """Additional docstring""" - local = 1 - """Not a docstring, since ``local`` is local.""" -''', # " -'''\ - - - - Function f's docstring - - Additional docstring -'''], # ' -['''\ -def f(a, b): - local = 1 -''', -'''\ - - - - - -'''], -['''\ -def f(a=None, b=1): - local = 1 -''', -'''\ - - - - - - None - - - 1 -'''], -['''\ -def f(a, (b, c, d)=range(3), - e=None): - local = 1 -''', -'''\ - - - - - - - range(3) - - - None -'''], -['''\ -def f(*args): - local = 1 -''', -'''\ - - - - -'''], -['''\ -def f(**kwargs): - local = 1 -''', -'''\ - - - - -'''], -['''\ -def f(a, b=None, *args, **kwargs): - local = 1 -''', -'''\ - - - - - - - None - - -'''], -['''\ -def f(): - pass -f.attrib = 1 -"""f.attrib's docstring""" -''', # " -# @@@ When should the Attribute move inside the Function? -'''\ - - - - - 1 - - f.attrib's docstring -'''], # ' -['''\ -def f(): - def g(): - pass - """Not a docstring""" - local = 1 -''', -'''\ - - -'''], -] - -totest['class'] = [ -['''\ -class C: - """class C's docstring""" -''', -'''\ - - - - class C's docstring -'''], -['''\ -class C(Super): - pass - -class D(SuperD, package.module.SuperD): - pass -''', -'''\ - - - -'''], -['''\ -class C: - class D: - pass - """Not a docstring""" -''', -'''\ - - -'''], -['''\ -class C: - def f(self): - self.local = 1 - local = 1 -''', -'''\ - - - - - -'''], -['''\ -class C: - def __init__(self): - self.local = 1 - local = 1 -''', -'''\ - - - - - - - - 1 - - - 1 -'''], -['''\ -class C: - def __init__(self): - local = foo(a=1) -''', -'''\ - - - - - - - - foo(a=1) -'''], -] - -totest['ignore'] = [ -['''\ -1 + 2 -''', -'''\ - -'''], -['''\ -del a -''', -'''\ - -'''], -] - -totest['comments'] = [ -# ['''\ -# # Comment -# ''', -# '''\ -# -# -# # Comment -# '''], -] - -# @@@ no comments yet -totest['everything'] = [ -['''\ -# comment - -"""Docstring""" - -"""Additional docstring""" - -__docformat__ = 'reStructuredText' - -a = 1 -"""Attribute docstring""" - -class C(Super): - - """C's docstring""" - - class_attribute = 1 - """class_attribute's docstring""" - - def __init__(self, text=None): - """__init__'s docstring""" - - self.instance_attribute = (text * 7 - + ' whaddyaknow') - """instance_attribute's docstring""" - - -def f(x, # parameter x - y=a*5, # parameter y - *args): # parameter args - """f's docstring""" - return [x + item for item in args] - -f.function_attribute = 1 -"""f.function_attribute's docstring""" -''', -'''\ - - - Docstring - - Additional docstring - - - 'reStructuredText' - - - 1 - - Attribute docstring - - - C's docstring - - - 1 - - class_attribute's docstring - - - __init__'s docstring - - - - - None - - - (text * 7 + ' whaddyaknow') - - instance_attribute's docstring - - - f's docstring - - - - - a * 5 - - - - 1 - - f.function_attribute's docstring -'''], -] - -""" -['''\ -''', -'''\ -'''], -""" - -if __name__ == '__main__': - import unittest - unittest.main(defaultTest='suite') diff --git a/docutils/test/test_readers/test_python/test_token_parser.py b/docutils/test/test_readers/test_python/test_token_parser.py deleted file mode 100644 index 23015a7dc..000000000 --- a/docutils/test/test_readers/test_python/test_token_parser.py +++ /dev/null @@ -1,46 +0,0 @@ -#! /usr/bin/env python - -# Author: David Goodger -# Contact: goodger@users.sourceforge.net -# Revision: $Revision$ -# Date: $Date$ -# Copyright: This module has been placed in the public domain. - -""" -Tests for docutils/readers/python/moduleparser.py. -""" - -from __init__ import DocutilsTestSupport - - -def suite(): - s = DocutilsTestSupport.PythonModuleParserTestSuite() - s.generateTests(totest, testmethod='test_token_parser_rhs') - return s - -totest = {} - -totest['expressions'] = [ -['''a = 1''', '''1'''], -['''a = b = 1''', '''1'''], -['''\ -a = ( - 1 + 2 - + 3 - ) -''', -'''(1 + 2 + 3)'''], -['''\ -a = """\\ -line one -line two""" -''', -'''"""\\\nline one\nline two"""'''], -['''a = `1`''', '''`1`'''], -['''a = `1`+`2`''', '''`1` + `2`'''], -] - - -if __name__ == '__main__': - import unittest - unittest.main(defaultTest='suite') -- cgit v1.2.1