diff options
author | Guido van Rossum <guido@python.org> | 1992-01-27 17:00:37 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1992-01-27 17:00:37 (GMT) |
commit | 3bead0984c802a2f709076bb9c8531fc67f56ee8 (patch) | |
tree | 853b49f1a9932b1f8296449bad1902dca7ea23df /Lib | |
parent | 19a86e72df72ff8e0b3a6f0d97b233bd22b70b7d (diff) | |
download | cpython-3bead0984c802a2f709076bb9c8531fc67f56ee8.zip cpython-3bead0984c802a2f709076bb9c8531fc67f56ee8.tar.gz cpython-3bead0984c802a2f709076bb9c8531fc67f56ee8.tar.bz2 |
Initial revision
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/pdb.doc | 157 | ||||
-rw-r--r-- | Lib/test/test_b1.py | 127 | ||||
-rw-r--r-- | Lib/test/test_b2.py | 130 | ||||
-rw-r--r-- | Lib/test/test_builtin.py | 13 | ||||
-rw-r--r-- | Lib/test/test_exceptions.py | 91 | ||||
-rw-r--r-- | Lib/test/test_grammar.py | 344 | ||||
-rw-r--r-- | Lib/test/test_opcodes.py | 24 | ||||
-rw-r--r-- | Lib/test/test_operations.py | 5 | ||||
-rw-r--r-- | Lib/test/test_support.py | 22 |
9 files changed, 913 insertions, 0 deletions
diff --git a/Lib/pdb.doc b/Lib/pdb.doc new file mode 100644 index 0000000..7eb68d2 --- /dev/null +++ b/Lib/pdb.doc @@ -0,0 +1,157 @@ +The Python Debugger +=================== + +To use the debugger in its simplest form: + + >>> import pdb + >>> pdb.run('<a statement>') + +The debugger's prompt is '(Pdb) '. This will stop in the first +function call in <a statement>. + +The commands recognized by the debugger are listed in the next +section. Most can be abbreviated as indicated; e.g., h(elp) means +that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel', +nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in +square brackets. + +A blank line repeats the previous command literally. (Except for +'list', where it lists the next 11 lines.) + +Commands that the debugger doesn't recognize are assumed to be Python +statements and are executed in the context of the program being +debugged. Python statements can also be prefixed with an exclamation +point ('!'). This is a powerful way to inspect the program being +debugged; it is even possible to change variables. When an exception +occurs in such a statement, the exception name is printed but the +debugger's state is not changed. + +The debugger is not directly programmable; but it is implemented as a +class from which you can derive your own debugger class, so you can +make as fancy as you like. + + +Debugger commands +================= + +h(elp) + Without argument, print the list of available commands. + With a command name as argument, print help about that command + (this is currently not implemented). + +w(here) + Print a stack trace, with the most recent frame at the bottom. + An arrow indicates the "current frame", which determines the + context of most commands. + +d(own) + Move the current frame one level down in the stack trace + (to an older frame). + +u(p) + Move the current frame one level up in the stack trace + (to a newer frame). + +b(reak) [lineno] + With a line number argument, set a break there in the current file. + Without argument, list all breaks. + +cl(ear) [lineno] + With a line number argument, clear that break in the current file. + Without argument, clear all breaks (but first ask confirmation). + +s(tep) + Execute the current line, stop at the first possible occasion + (either in a function that is called or in the current function). + +n(ext) + Continue execution until the next line in the current function + is reached or it returns. + +r(eturn) + Continue execution until the current function returns. + +c(ont(inue)) + Continue execution, only stop when a breakpoint is encountered. + +l(ist) [first [,last]] + List source code for the current file. + Without arguments, list 11 lines around the current line + or continue the previous listing. + With one argument, list 11 lines starting at that line. + With two arguments, list the given range; + if the second argument is less than the first, it is a count. + +a(rgs) + Print the argument list of the current function. + +p expression + Print the value of the expression. + +(!) statement + Execute the (one-line) statement in the context of + the current stack frame. + The exclamation point can be omitted unless the first word + of the statement resembles a debugger command. + To assign to a global variable you must always prefix the + command with a 'global' command, e.g.: + (Pdb) global list_options; list_options = ['-l'] + (Pdb) + +q(uit) + Quit from the debugger. + The program being executed is aborted. + + +How it works +============ + +Some changes were made to the interpreter: +- if sys.trace is defined (by the user) and not None, it should be a function +- sys.trace is called the global trace function +- there can also a local trace function (see later) + +Trace functions have three arguments: (frame, event, arg) + - frame is the current stack frame + - event is a string: 'call', 'line', 'return' or 'exception' + - arg is dependent on the event type +A trace function should return a new trace function or None. +Class methods are accepted (and most useful!) as trace methods. + +The events have the following meaning: + + 'call': A function is called (or some other code block entered). + The global trace function is called; + arg is the argument list to the function; + the return value specifies the local trace function. + + 'line': The interpreter is about to execute a new line of code + (sometimes multiple line events on one line exist). + The local trace function is called; arg in None; + the return value specifies the new local trace function. + + 'return': A function (or other code block) is about to return. + The local trace function is called; + arg is the value that will be returned. + The trace function's return value is ignored. + + 'exception': An exception has occurred. + The local trace function is called; + arg is a triple (exception, value, traceback); + the return value specifies the new local trace function + +Note that as an exception is propagated down the chain of callers, an +'exception' event is generated at each level. + +Stack frame objects have the following read-only attributes: + f_code: the code object being executed + f_lineno: the current line number (-1 for 'call' events) + f_back: the stack frame of the caller, or None + f_locals: dictionary containing local name bindings + f_globals: dictionary containing global name bindings + +Code objects have the following read-only attributes: + co_code: the code string + co_names: the list of names used by the code + co_consts: the list of (literal) constants used by the code + co_filename: the filename from which the code was compiled diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py new file mode 100644 index 0000000..1fafc4f --- /dev/null +++ b/Lib/test/test_b1.py @@ -0,0 +1,127 @@ +# Python test set -- part 4a, built-in functions a-m + +from test_support import * + +print 'abs' +if abs(0) <> 0: raise TestFailed, 'abs(0)' +if abs(1234) <> 1234: raise TestFailed, 'abs(1234)' +if abs(-1234) <> 1234: raise TestFailed, 'abs(-1234)' +# +if abs(0.0) <> 0.0: raise TestFailed, 'abs(0.0)' +if abs(3.14) <> 3.14: raise TestFailed, 'abs(3.14)' +if abs(-3.14) <> 3.14: raise TestFailed, 'abs(-3.14)' +# +if abs(0L) <> 0L: raise TestFailed, 'abs(0L)' +if abs(1234L) <> 1234L: raise TestFailed, 'abs(1234L)' +if abs(-1234L) <> 1234L: raise TestFailed, 'abs(-1234L)' + +print 'apply' +def f0(*args): + if args != (): raise TestFailed, 'f0 called with ' + `args` +def f1(a1): + if a1 != 1: raise TestFailed, 'f1 called with ' + `a1` +def f2(a1, a2): + if a1 != 1 or a2 != 2: + raise TestFailed, 'f2 called with ' + `a1, a2` +def f3(a1, a2, a3): + if a1 != 1 or a2 != 2 or a3 != 3: + raise TestFailed, 'f2 called with ' + `a1, a2, a3` +apply(f0, ()) +apply(f1, (1,)) +apply(f2, (1, 2)) +apply(f3, (1, 2, 3)) + +print 'chr' +if chr(32) <> ' ': raise TestFailed, 'chr(32)' +if chr(65) <> 'A': raise TestFailed, 'chr(65)' +if chr(97) <> 'a': raise TestFailed, 'chr(97)' + +print 'dir' +x = 1 +if 'x' not in dir(): raise TestFailed, 'dir()' +import sys +if 'modules' not in dir(sys): raise TestFailed, 'dir(sys)' + +print 'divmod' +if divmod(12, 7) <> (1, 5): raise TestFailed, 'divmod(12, 7)' +if divmod(-12, 7) <> (-2, 2): raise TestFailed, 'divmod(-12, 7)' +if divmod(12, -7) <> (-2, -2): raise TestFailed, 'divmod(12, -7)' +if divmod(-12, -7) <> (1, -5): raise TestFailed, 'divmod(-12, -7)' +# +if divmod(12L, 7L) <> (1L, 5L): raise TestFailed, 'divmod(12L, 7L)' +if divmod(-12L, 7L) <> (-2L, 2L): raise TestFailed, 'divmod(-12L, 7L)' +if divmod(12L, -7L) <> (-2L, -2L): raise TestFailed, 'divmod(12L, -7L)' +if divmod(-12L, -7L) <> (1L, -5L): raise TestFailed, 'divmod(-12L, -7L)' +# +if divmod(12, 7L) <> (1, 5L): raise TestFailed, 'divmod(12, 7L)' +if divmod(-12, 7L) <> (-2, 2L): raise TestFailed, 'divmod(-12, 7L)' +if divmod(12L, -7) <> (-2L, -2): raise TestFailed, 'divmod(12L, -7)' +if divmod(-12L, -7) <> (1L, -5): raise TestFailed, 'divmod(-12L, -7)' +# +if divmod(3.25, 1.0) <> (3.0, 0.25): raise TestFailed, 'divmod(3.25, 1.0)' +if divmod(-3.25, 1.0) <> (-4.0, 0.75): raise TestFailed, 'divmod(-3.25, 1.0)' +if divmod(3.25, -1.0) <> (-4.0, -0.75): raise TestFailed, 'divmod(3.25, -1.0)' +if divmod(-3.25, -1.0) <> (3.0, -0.25): raise TestFailed, 'divmod(-3.25, -1.0)' + +print 'eval' +if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')' + +print 'exec' +z = 0 +exec('z=1+1\n') +if z <> 2: raise TestFailed, 'exec(\'z=1+1\'\\n)' + +print 'float' +if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)' +if float(314) <> 314.0: raise TestFailed, 'float(314)' +if float(314L) <> 314.0: raise TestFailed, 'float(314L)' + +print 'getattr' +import sys +if getattr(sys, 'stdout') is not sys.stdout: raise TestFailed, 'getattr' + +print 'hex' +if hex(16) != '0x10': raise TestFailed, 'hex(16)' +if hex(16L) != '0x10L': raise TestFailed, 'hex(16L)' +if hex(-16) != '-0x10': raise TestFailed, 'hex(-16)' +if hex(-16L) != '-0x10L': raise TestFailed, 'hex(-16L)' + +# Test input() later, together with raw_input + +print 'int' +if int(314) <> 314: raise TestFailed, 'int(314)' +if int(3.14) <> 3: raise TestFailed, 'int(3.14)' +if int(314L) <> 314: raise TestFailed, 'int(314L)' + +print 'len' +if len('123') <> 3: raise TestFailed, 'len(\'123\')' +if len(()) <> 0: raise TestFailed, 'len(())' +if len((1, 2, 3, 4)) <> 4: raise TestFailed, 'len((1, 2, 3, 4))' +if len([1, 2, 3, 4]) <> 4: raise TestFailed, 'len([1, 2, 3, 4])' +if len({}) <> 0: raise TestFailed, 'len({})' +if len({'a':1, 'b': 2}) <> 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})' + +print 'long' +if long(314) <> 314L: raise TestFailed, 'long(314)' +if long(3.14) <> 3L: raise TestFailed, 'long(3.14)' +if long(314L) <> 314L: raise TestFailed, 'long(314L)' + +print 'max' +if max('123123') <> '3': raise TestFailed, 'max(\'123123\')' +if max(1, 2, 3) <> 3: raise TestFailed, 'max(1, 2, 3)' +if max((1, 2, 3, 1, 2, 3)) <> 3: raise TestFailed, 'max((1, 2, 3, 1, 2, 3))' +if max([1, 2, 3, 1, 2, 3]) <> 3: raise TestFailed, 'max([1, 2, 3, 1, 2, 3])' +# +if max(1, 2L, 3.0) <> 3.0: raise TestFailed, 'max(1, 2L, 3.0)' +if max(1L, 2.0, 3) <> 3: raise TestFailed, 'max(1L, 2.0, 3)' +if max(1.0, 2, 3L) <> 3L: raise TestFailed, 'max(1.0, 2, 3L)' + +print 'min' +if min('123123') <> '1': raise TestFailed, 'min(\'123123\')' +if min(1, 2, 3) <> 1: raise TestFailed, 'min(1, 2, 3)' +if min((1, 2, 3, 1, 2, 3)) <> 1: raise TestFailed, 'min((1, 2, 3, 1, 2, 3))' +if min([1, 2, 3, 1, 2, 3]) <> 1: raise TestFailed, 'min([1, 2, 3, 1, 2, 3])' +# +if min(1, 2L, 3.0) <> 1: raise TestFailed, 'min(1, 2L, 3.0)' +if min(1L, 2.0, 3) <> 1L: raise TestFailed, 'min(1L, 2.0, 3)' +if min(1.0, 2, 3L) <> 1.0: raise TestFailed, 'min(1.0, 2, 3L)' diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py new file mode 100644 index 0000000..a4bea24 --- /dev/null +++ b/Lib/test/test_b2.py @@ -0,0 +1,130 @@ +# Python test set -- part 4b, built-in functions n-z + +from test_support import * + +print 'oct' +if oct(100) != '0144': raise TestFailed, 'oct(100)' +if oct(100L) != '0144L': raise TestFailed, 'oct(100L)' +if oct(-100) != '-0144': raise TestFailed, 'oct(-100)' +if oct(-100L) != '-0144L': raise TestFailed, 'oct(-100L)' + +print 'open' +# NB the first 4 lines are also used to test input and raw_input, below +fp = open(TESTFN, 'w') +try: + fp.write('1+1\n') + fp.write('1+1\n') + fp.write('The quick brown fox jumps over the lazy dog') + fp.write('.\n') + fp.write('Dear John\n') + fp.write('XXX'*100) + fp.write('YYY'*100) +finally: + fp.close() +# +fp = open(TESTFN, 'r') +try: + if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' + if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact' + if fp.readline() <> 'The quick brown fox jumps over the lazy dog.\n': + raise TestFailed, 'readline() # default' + if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short' + if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)' + if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)' + if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate' +finally: + fp.close() + +print 'ord' +if ord(' ') <> 32: raise TestFailed, 'ord(\' \')' +if ord('A') <> 65: raise TestFailed, 'ord(\'A\')' +if ord('a') <> 97: raise TestFailed, 'ord(\'a\')' + +print 'pow' +if pow(0,0) <> 1: raise TestFailed, 'pow(0,0)' +if pow(0,1) <> 0: raise TestFailed, 'pow(0,1)' +if pow(1,0) <> 1: raise TestFailed, 'pow(1,0)' +if pow(1,1) <> 1: raise TestFailed, 'pow(1,1)' +# +if pow(2,0) <> 1: raise TestFailed, 'pow(2,0)' +if pow(2,10) <> 1024: raise TestFailed, 'pow(2,10)' +if pow(2,20) <> 1024*1024: raise TestFailed, 'pow(2,20)' +if pow(2,30) <> 1024*1024*1024: raise TestFailed, 'pow(2,30)' +# +if pow(-2,0) <> 1: raise TestFailed, 'pow(-2,0)' +if pow(-2,1) <> -2: raise TestFailed, 'pow(-2,1)' +if pow(-2,2) <> 4: raise TestFailed, 'pow(-2,2)' +if pow(-2,3) <> -8: raise TestFailed, 'pow(-2,3)' +# +if pow(0L,0) <> 1: raise TestFailed, 'pow(0L,0)' +if pow(0L,1) <> 0: raise TestFailed, 'pow(0L,1)' +if pow(1L,0) <> 1: raise TestFailed, 'pow(1L,0)' +if pow(1L,1) <> 1: raise TestFailed, 'pow(1L,1)' +# +if pow(2L,0) <> 1: raise TestFailed, 'pow(2L,0)' +if pow(2L,10) <> 1024: raise TestFailed, 'pow(2L,10)' +if pow(2L,20) <> 1024*1024: raise TestFailed, 'pow(2L,20)' +if pow(2L,30) <> 1024*1024*1024: raise TestFailed, 'pow(2L,30)' +# +if pow(-2L,0) <> 1: raise TestFailed, 'pow(-2L,0)' +if pow(-2L,1) <> -2: raise TestFailed, 'pow(-2L,1)' +if pow(-2L,2) <> 4: raise TestFailed, 'pow(-2L,2)' +if pow(-2L,3) <> -8: raise TestFailed, 'pow(-2L,3)' +# +if pow(0.,0) <> 1.: raise TestFailed, 'pow(0.,0)' +if pow(0.,1) <> 0.: raise TestFailed, 'pow(0.,1)' +if pow(1.,0) <> 1.: raise TestFailed, 'pow(1.,0)' +if pow(1.,1) <> 1.: raise TestFailed, 'pow(1.,1)' +# +if pow(2.,0) <> 1.: raise TestFailed, 'pow(2.,0)' +if pow(2.,10) <> 1024.: raise TestFailed, 'pow(2.,10)' +if pow(2.,20) <> 1024.*1024.: raise TestFailed, 'pow(2.,20)' +if pow(2.,30) <> 1024.*1024.*1024.: raise TestFailed, 'pow(2.,30)' +# +# XXX These don't work -- negative float to the float power... +#if pow(-2.,0) <> 1.: raise TestFailed, 'pow(-2.,0)' +#if pow(-2.,1) <> -2.: raise TestFailed, 'pow(-2.,1)' +#if pow(-2.,2) <> 4.: raise TestFailed, 'pow(-2.,2)' +#if pow(-2.,3) <> -8.: raise TestFailed, 'pow(-2.,3)' + +print 'range' +if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)' +if range(1, 5) <> [1, 2, 3, 4]: raise TestFailed, 'range(1, 5)' +if range(0) <> []: raise TestFailed, 'range(0)' +if range(-3) <> []: raise TestFailed, 'range(-3)' +if range(1, 10, 3) <> [1, 4, 7]: raise TestFailed, 'range(1, 10, 3)' +if range(5, -5, -3) <> [5, 2, -1, -4]: raise TestFailed, 'range(5, -5, -3)' + +print 'input and raw_input' +import sys +fp = open(TESTFN, 'r') +savestdin = sys.stdin +try: + sys.stdin = fp + if input() <> 2: raise TestFailed, 'input()' + if input('testing\n') <> 2: raise TestFailed, 'input()' + if raw_input() <> 'The quick brown fox jumps over the lazy dog.': + raise TestFailed, 'raw_input()' + if raw_input('testing\n') <> 'Dear John': + raise TestFailed, 'raw_input(\'testing\\n\')' +finally: + sys.stdin = savestdin + fp.close() + +print 'reload' +import string +reload(string) + +print 'setattr' +import sys +setattr(sys, 'foobar', 1) +if sys.foobar != 1: raise TestFailed, 'setattr(sys, \'foobar\', 1)' + +print 'type' +if type('') <> type('123') or type('') == type(()): + raise TestFailed, 'type()' + + +# Epilogue -- unlink the temp file + +unlink(TESTFN) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py new file mode 100644 index 0000000..33fef8d --- /dev/null +++ b/Lib/test/test_builtin.py @@ -0,0 +1,13 @@ +# Python test set -- part 4, built-in functions + +from test_support import * + +print '4. Built-in functions' + +print 'test_b1' +unload('test_b1') +import test_b1 + +print 'test_b2' +unload('test_b2') +import test_b2 diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py new file mode 100644 index 0000000..7ee6e21 --- /dev/null +++ b/Lib/test/test_exceptions.py @@ -0,0 +1,91 @@ +# Python test set -- part 5, built-in exceptions + +from test_support import * + +print '5. Built-in exceptions' +# XXX This is not really enough, each *operation* should be tested! + +def r(name): print name + +r(AttributeError) +import sys +try: x = sys.undefined_attribute +except AttributeError: pass + +r(EOFError) +import sys +fp = open(TESTFN, 'w') +fp.close() +fp = open(TESTFN, 'r') +savestdin = sys.stdin +try: + sys.stdin = fp + x = raw_input() +except EOFError: + pass +finally: + sys.stdin = savestdin + fp.close() + +r(IOError) +try: open('this file does not exist', 'r') +except IOError: pass + +r(ImportError) +try: import undefined_module +except ImportError: pass + +r(IndexError) +x = [] +try: a = x[10] +except IndexError: pass + +r(KeyError) +x = {} +try: a = x['key'] +except KeyError: pass + +r(KeyboardInterrupt) +print '(not testable in a script)' + +r(MemoryError) +print '(not safe to test)' + +r(NameError) +try: x = undefined_variable +except NameError: pass + +r(OverflowError) +x = 1 +try: + while 1: x = x+x +except OverflowError: pass + +r(RuntimeError) +print '(not used any more?)' + +r(SyntaxError) +try: exec('/\n') +except SyntaxError: pass + +r(SystemError) +print '(hard to reproduce)' + +r(SystemExit) +import sys +try: sys.exit(0) +except SystemExit: pass + +r(TypeError) +try: [] + () +except TypeError: pass + +r(ValueError) +try: x = chr(10000) +except ValueError: pass + +r(ZeroDivisionError) +try: x = 1/0 +except ZeroDivisionError: pass + +unlink(TESTFN) diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py new file mode 100644 index 0000000..3f1447f --- /dev/null +++ b/Lib/test/test_grammar.py @@ -0,0 +1,344 @@ +# Python test set -- part 1, grammar. +# This just tests whether the parser accepts them all. + +from test_support import * + +print '1. Parser' + +print '1.1 Tokens' + +print '1.1.1 Backslashes' + +# Backslash means line continuation: +x = 1 \ ++ 1 +if x <> 2: raise TestFailed, 'backslash for line continuation' + +# Backslash does not means continuation in comments :\ +x = 0 +if x <> 0: raise TestFailed, 'backslash ending comment' + +print '1.1.2 Numeric literals' + +print '1.1.2.1 Plain integers' +if 0xff <> 255: raise TestFailed, 'hex int' +if 0377 <> 255: raise TestFailed, 'octal int' +if 2147483647 != 017777777777: raise TestFailed, 'max positive int' +if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int' +# XXX -2147483648 +if 037777777777 != -1: raise TestFailed, 'oct -1' +if 0xffffffff != -1: raise TestFailed, 'hex -1' +for s in '2147483648', '040000000000', '0x100000000': + try: + x = eval(s) + except OverflowError: + continue + raise TestFailed, 'No OverflowError on huge integer literal ' + `s` + +print '1.1.2.2 Long integers' +x = 0L +x = 0l +x = 0xffffffffffffffffL +x = 0xffffffffffffffffl +x = 077777777777777777L +x = 077777777777777777l +x = 123456789012345678901234567890L +x = 123456789012345678901234567890l + +print '1.1.2.3 Floating point' +x = 3.14 +x = 314. +x = 0.314 +# XXX x = 000.314 +x = .314 +x = 3e14 +x = 3E14 +x = 3e-14 +x = 3e+14 +x = 3.e14 +x = .3e14 +x = 3.1e4 + +print '1.2 Grammar' + +print 'single_input' # NEWLINE | simple_stmt | compound_stmt NEWLINE +# XXX can't test in a script -- this rule is only used when interactive + +print 'file_input' # (NEWLINE | stmt)* ENDMARKER +# Being tested as this very moment this very module + +print 'expr_input' # testlist NEWLINE +# XXX Hard to test -- used only in calls to input() + +print 'eval_input' # testlist ENDMARKER +x = eval('1, 0 or 1') + +print 'funcdef' +### 'def' NAME parameters ':' suite +### parameters: '(' [varargslist] ')' +### varargslist: (fpdef ',')* ('+'|'*') NAME | fpdef (',' fpdef)* [','] +### fpdef: NAME | '(' fplist ')' +### fplist: fpdef (',' fpdef)* [','] +def f1(): pass +def f2(one_argument): pass +def f3(two, arguments): pass +def f4(two, (compound, (argument, list))): pass +def a1(one_arg,): pass +def a2(two, args,): pass +def v0(*rest): pass +def v1(a, *rest): pass +def v2(a, b, *rest): pass +def v3(a, (b, c), *rest): pass + +### stmt: simple_stmt | compound_stmt +# Tested below + +### simple_stmt: small_stmt (';' small_stmt)* [';'] +print 'simple_stmt' +x = 1; pass; del x + +### small_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt +# Tested below + +print 'expr_stmt' # (exprlist '=')* exprlist +1 +1, 2, 3 +x = 1 +x = 1, 2, 3 +x = y = z = 1, 2, 3 +x, y, z = 1, 2, 3 +abc = a, b, c = x, y, z = xyz = 1, 2, (3, 4) +# NB these variables are deleted below + +print 'print_stmt' # 'print' (test ',')* [test] +print 1, 2, 3 +print 1, 2, 3, +print +print 0 or 1, 0 or 1, +print 0 or 1 + +print 'del_stmt' # 'del' exprlist +del abc +del x, y, (z, xyz) + +print 'pass_stmt' # 'pass' +pass + +print 'flow_stmt' # break_stmt | continue_stmt | return_stmt | raise_stmt +# Tested below + +print 'break_stmt' # 'break' +while 1: break + +print 'continue_stmt' # 'continue' +i = 1 +while i: i = 0; continue + +print 'return_stmt' # 'return' [testlist] +def g1(): return +def g2(): return 1 +g1() +x = g2() + +print 'raise_stmt' # 'raise' test [',' test] +try: raise RuntimeError, 'just testing' +except RuntimeError: pass +try: raise KeyboardInterrupt +except KeyboardInterrupt: pass + +print 'import_stmt' # 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*) +[1] +import sys +[2] +import time, math +[3] +from time import sleep +[4] +from sys import * +[5] +from math import sin, cos +[6] + +print 'global_stmt' # 'global' NAME (',' NAME)* +def f(): + global a + global a, b + global one, two, three, four, five, six, seven, eight, nine, ten + +### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef +# Tested below + +print 'if_stmt' # 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] +if 1: pass +if 1: pass +else: pass +if 0: pass +elif 0: pass +if 0: pass +elif 0: pass +elif 0: pass +elif 0: pass +else: pass + +print 'while_stmt' # 'while' test ':' suite ['else' ':' suite] +while 0: pass +while 0: pass +else: pass + +print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite] +[1] +for i in 1, 2, 3: pass +[2] +for i, j, k in (): pass +else: pass +[3] + +print 'try_stmt' # 'try' ':' suite (except_clause ':' suite)* ['finally' ':' suite] +### except_clause: 'except' [expr [',' expr]] +try: pass +try: 1/0 +except ZeroDivisionError: pass +try: 1/0 +except EOFError: pass +except TypeError, msg: pass +except RuntimeError, msg: pass +except: pass +try: pass +finally: pass +try: 1/0 +except: pass +finally: pass + +print 'suite' # simple_stmt | NEWLINE INDENT NEWLINE* (stmt NEWLINE*)+ DEDENT +if 1: pass +if 1: + pass +if 1: + # + # + # + pass + pass + # + pass + # + +print 'test' +### and_test ('or' and_test)* +### and_test: not_test ('and' not_test)* +### not_test: 'not' not_test | comparison +if not 1: pass +if 1 and 1: pass +if 1 or 1: pass +if not not not 1: pass +if not 1 and 1 and 1: pass +if 1 and 1 or 1 and 1 and 1 or not 1 and 1: pass + +print 'comparison' +### comparison: expr (comp_op expr)* +### comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' +if 1: pass +x = (1 == 1) +if 1 == 1: pass +if 1 != 1: pass +if 1 <> 1: pass +if 1 < 1: pass +if 1 > 1: pass +if 1 <= 1: pass +if 1 >= 1: pass +if 1 is 1: pass +if 1 is not 1: pass +if 1 in (): pass +if 1 not in (): pass +if 1 < 1 > 1 == 1 >= 1 <= 1 <> 1 in 1 not in 1 is 1 is not 1: pass + +print 'binary mask ops' +x = 1 & 1 +x = 1 ^ 1 +x = 1 | 1 + +print 'shift ops' +x = 1 << 1 +x = 1 >> 1 +x = 1 << 1 >> 1 + +print 'additive ops' +x = 1 +x = 1 + 1 +x = 1 - 1 - 1 +x = 1 - 1 + 1 - 1 + 1 + +print 'multiplicative ops' +x = 1 * 1 +x = 1 / 1 +x = 1 % 1 +x = 1 / 1 * 1 % 1 + +print 'unary ops' +x = +1 +x = -1 +x = ~1 +x = ~1 ^ 1 & 1 | 1 & 1 ^ -1 +x = -1*1/1 + 1*1 - ---1*1 + +print 'selectors' +### trailer: '(' [testlist] ')' | '[' subscript ']' | '.' NAME +### subscript: expr | [expr] ':' [expr] +import sys, time +c = sys.path[0] +x = time.time() +x = sys.modules['time'].time() +a = '01234' +c = a[0] +c = a[-1] +s = a[0:5] +s = a[:5] +s = a[0:] +s = a[:] +s = a[-5:] +s = a[:-1] +s = a[-4:-3] + +print 'atoms' +### atom: '(' [testlist] ')' | '[' [testlist] ']' | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING +### dictmaker: test ':' test (',' test ':' test)* [','] + +x = (1) +x = (1 or 2 or 3) +x = (1 or 2 or 3, 2, 3) + +x = [] +x = [1] +x = [1 or 2 or 3] +x = [1 or 2 or 3, 2, 3] +x = [] + +x = {} +x = {'one': 1} +x = {'one': 1,} +x = {'one' or 'two': 1 or 2} +x = {'one': 1, 'two': 2} +x = {'one': 1, 'two': 2,} +x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6} + +x = `x` +x = `1 or 2 or 3` +x = x +x = 'x' +x = 123 + +### exprlist: expr (',' expr)* [','] +### testlist: test (',' test)* [','] +# These have been exercised enough above + +print 'classdef' # 'class' NAME parameters ['=' baselist] ':' suite +### baselist: atom arguments (',' atom arguments)* +### arguments: '(' [testlist] ')' +class B: pass +class C1(B): pass +class C2(B): pass +class D(C1, C2, B): pass +class C: + def meth1(self): pass + def meth2(self, arg): pass + def meth3(self, a1, a2): pass diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py new file mode 100644 index 0000000..41f1b8f --- /dev/null +++ b/Lib/test/test_opcodes.py @@ -0,0 +1,24 @@ +# Python test set -- part 2, opcodes + +from test_support import * + + +print '2. Opcodes' +print 'XXX Not yet fully implemented' + +print '2.1 try inside for loop' +n = 0 +for i in range(10): + n = n+i + try: 1/0 + except NameError: pass + except ZeroDivisionError: pass + except TypeError: pass + finally: pass + try: pass + except: pass + try: pass + finally: pass + n = n+i +if n <> 90: + raise TestFailed, 'try inside for' diff --git a/Lib/test/test_operations.py b/Lib/test/test_operations.py new file mode 100644 index 0000000..1a75065 --- /dev/null +++ b/Lib/test/test_operations.py @@ -0,0 +1,5 @@ +# Python test set -- part 3, built-in operations. + + +print '3. Operations' +print 'XXX Not yet implemented' diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py new file mode 100644 index 0000000..c6d0611 --- /dev/null +++ b/Lib/test/test_support.py @@ -0,0 +1,22 @@ +# Python test set -- supporting definitions. + +TestFailed = 'test_support -- test failed' # Exception + +def unload(name): + import sys + try: + del sys.modules[name] + except KeyError: + pass + +def forget(modname): + unload(modname) + import sys, os + for dirname in sys.path: + try: + os.unlink(os.path.join(dirname, modname + '.pyc')) + except os.error: + pass + +TESTFN = '@test' # Filename used for testing +from os import unlink |