diff options
author | Georg Brandl <georg@python.org> | 2007-02-09 21:28:07 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-02-09 21:28:07 (GMT) |
commit | 88fc6646d1b97cb3ba6188808e7c016884d44a73 (patch) | |
tree | 4cf73aca05a06e89ae71a719c7b2329af51392b8 /Lib/test | |
parent | 08c47ba0df4ba87cdce34c126e5bdb28f8c6034c (diff) | |
download | cpython-88fc6646d1b97cb3ba6188808e7c016884d44a73.zip cpython-88fc6646d1b97cb3ba6188808e7c016884d44a73.tar.gz cpython-88fc6646d1b97cb3ba6188808e7c016884d44a73.tar.bz2 |
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ast.py | 3 | ||||
-rw-r--r-- | Lib/test/test_class.py | 2 | ||||
-rw-r--r-- | Lib/test/test_code.py | 2 | ||||
-rw-r--r-- | Lib/test/test_descrtut.py | 25 | ||||
-rw-r--r-- | Lib/test/test_dis.py | 11 | ||||
-rw-r--r-- | Lib/test/test_extcall.py | 4 | ||||
-rw-r--r-- | Lib/test/test_parser.py | 31 | ||||
-rw-r--r-- | Lib/test/test_pkg.py | 80 | ||||
-rw-r--r-- | Lib/test/test_popen.py | 2 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 8 | ||||
-rw-r--r-- | Lib/test/test_syntax.py | 2 | ||||
-rw-r--r-- | Lib/test/test_tokenize.py | 20 | ||||
-rw-r--r-- | Lib/test/test_traceback.py | 6 |
13 files changed, 82 insertions, 114 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 24394ed..5d22053 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -30,8 +30,6 @@ exec_tests = [ "v = 1", # AugAssign "v += 1", - # Print - "print >>f, 1, ", # For "for v in v:pass", # While @@ -157,7 +155,6 @@ exec_results = [ ('Module', [('Delete', (1, 0), [('Name', (1, 4), 'v', ('Del',))])]), ('Module', [('Assign', (1, 0), [('Name', (1, 0), 'v', ('Store',))], ('Num', (1, 4), 1))]), ('Module', [('AugAssign', (1, 0), ('Name', (1, 0), 'v', ('Store',)), ('Add',), ('Num', (1, 5), 1))]), -('Module', [('Print', (1, 0), ('Name', (1, 8), 'f', ('Load',)), [('Num', (1, 11), 1)], False)]), ('Module', [('For', (1, 0), ('Name', (1, 4), 'v', ('Store',)), ('Name', (1, 9), 'v', ('Load',)), [('Pass', (1, 11))], [])]), ('Module', [('While', (1, 0), ('Name', (1, 6), 'v', ('Load',)), [('Pass', (1, 8))], [])]), ('Module', [('If', (1, 0), ('Name', (1, 3), 'v', ('Load',)), [('Pass', (1, 5))], [])]), diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 221fd48..ded3f1a 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -127,7 +127,7 @@ class AllTests: method_template = """\ def __%(method)s__(self, *args): - print "__%(method)s__:", args + print("__%(method)s__:", args) """ d = {} diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index f7014a6..4f43f5d 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -58,7 +58,7 @@ consts: ('None',) name: attrs argcount: 1 kwonlyargcount: 0 -names: ('attr1', 'attr2', 'attr3') +names: ('print', 'attr1', 'attr2', 'attr3') varnames: ('obj',) cellvars: () freevars: () diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index 3351b67..001aa49 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -36,28 +36,28 @@ test_1 = """ Here's the new type at work: - >>> print(defaultdict) # show our type + >>> print(defaultdict) # show our type <class 'test.test_descrtut.defaultdict'> - >>> print(type(defaultdict)) # its metatype + >>> print(type(defaultdict)) # its metatype <type 'type'> >>> a = defaultdict(default=0.0) # create an instance - >>> print(a) # show the instance + >>> print(a) # show the instance {} - >>> print(type(a)) # show its type + >>> print(type(a)) # show its type <class 'test.test_descrtut.defaultdict'> - >>> print(a.__class__) # show its class + >>> print(a.__class__) # show its class <class 'test.test_descrtut.defaultdict'> - >>> print(type(a) is a.__class__) # its type is its class + >>> print(type(a) is a.__class__) # its type is its class True >>> a[1] = 3.25 # modify the instance - >>> print(a) # show the new value + >>> print(a) # show the new value {1: 3.25} - >>> print(a[1]) # show the new item + >>> print(a[1]) # show the new item 3.25 - >>> print(a[0]) # a non-existant item + >>> print(a[0]) # a non-existant item 0.0 >>> a.merge({1:100, 2:200}) # use a dict method - >>> print(sortdict(a)) # show the result + >>> print(sortdict(a)) # show the result {1: 3.25, 2: 200} >>> @@ -67,10 +67,11 @@ statement or the built-in function eval(): >>> print(sorted(a.keys())) [1, 2] - >>> exec("x = 3; print x", a) + >>> a['print'] = print # need the print function here + >>> exec("x = 3; print(x)", a) 3 >>> print(sorted(a.keys(), key=lambda x: (str(type(x)), x))) - [1, 2, '__builtins__', 'x'] + [1, 2, '__builtins__', 'print', 'x'] >>> print(a['x']) 3 >>> diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 3916c32..ab70778 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -12,12 +12,13 @@ def _f(a): return 1 dis_f = """\ - %-4d 0 LOAD_FAST 0 (a) - 3 PRINT_ITEM - 4 PRINT_NEWLINE + %-4d 0 LOAD_GLOBAL 0 (print) + 3 LOAD_FAST 0 (a) + 6 CALL_FUNCTION 1 + 9 POP_TOP - %-4d 5 LOAD_CONST 1 (1) - 8 RETURN_VALUE + %-4d 10 LOAD_CONST 1 (1) + 13 RETURN_VALUE """%(_f.func_code.co_firstlineno + 1, _f.func_code.co_firstlineno + 2) diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index e67b3f8..3e0426f 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -260,8 +260,8 @@ for args in ['', 'a', 'ab']: lambda x: '%s="%s"' % (x, x), defargs) if vararg: arglist.append('*' + vararg) if kwarg: arglist.append('**' + kwarg) - decl = (('def %s(%s): print "ok %s", a, b, d, e, v, ' + - 'type(k) is type ("") and k or sortdict(k)') + decl = (('def %s(%s): print("ok %s", a, b, d, e, v, ' + + 'type(k) is type ("") and k or sortdict(k))') % (name, ', '.join(arglist), name)) exec(decl) func = eval(name) diff --git a/Lib/test/test_parser.py b/Lib/test/test_parser.py index 36bc4e3..ddb58b5 100644 --- a/Lib/test/test_parser.py +++ b/Lib/test/test_parser.py @@ -85,14 +85,6 @@ class RoundtripLegalSyntaxTestCase(unittest.TestCase): self.check_expr("(x for x in range(10))") self.check_expr("foo(x for x in range(10))") - def test_print(self): - self.check_suite("print") - self.check_suite("print 1") - self.check_suite("print 1,") - self.check_suite("print >>fp") - self.check_suite("print >>fp, 1") - self.check_suite("print >>fp, 1,") - def test_simple_expression(self): # expr_stmt self.check_suite("a") @@ -359,29 +351,6 @@ class IllegalSyntaxTestCase(unittest.TestCase): (0, '')))) self.check_bad_tree(tree, "def f():\n return 1\n yield 1") - def test_print_chevron_comma(self): - # Illegal input: print >>fp, - tree = \ - (257, - (264, - (265, - (266, - (268, - (1, 'print'), - (35, '>>'), - (290, - (291, - (292, - (293, - (295, - (296, - (297, - (298, (299, (300, (301, (302, (303, (1, 'fp')))))))))))))), - (12, ','))), - (4, ''))), - (0, '')) - self.check_bad_tree(tree, "print >>fp,") - def test_a_comma_comma_c(self): # Illegal input: a,,c tree = \ diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index 79c9098..ad9cc1a 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -81,122 +81,122 @@ tests = [ ("t2", [ ("t2", None), - ("t2 __init__"+os.extsep+"py", "'doc for t2'; print __name__, 'loading'"), + ("t2 __init__"+os.extsep+"py", "'doc for t2'; print(__name__, 'loading')"), ("t2 sub", None), ("t2 sub __init__"+os.extsep+"py", ""), ("t2 sub subsub", None), - ("t2 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), + ("t2 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"), ], """ import t2 -print t2.__doc__ +print(t2.__doc__) import t2.sub import t2.sub.subsub -print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__ +print(t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__) import t2 from t2 import * -print dir() +print(dir()) from t2 import sub from t2.sub import subsub from t2.sub.subsub import spam -print sub.__name__, subsub.__name__ -print sub.subsub.__name__ -print dir() +print(sub.__name__, subsub.__name__) +print(sub.subsub.__name__) +print(dir()) import t2.sub import t2.sub.subsub -print t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__ +print(t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__) from t2 import * -print dir() +print(dir()) """), ("t3", [ ("t3", None), - ("t3 __init__"+os.extsep+"py", "print __name__, 'loading'"), + ("t3 __init__"+os.extsep+"py", "print(__name__, 'loading')"), ("t3 sub", None), ("t3 sub __init__"+os.extsep+"py", ""), ("t3 sub subsub", None), - ("t3 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), + ("t3 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"), ], """ import t3.sub.subsub -print t3.__name__, t3.sub.__name__, t3.sub.subsub.__name__ +print(t3.__name__, t3.sub.__name__, t3.sub.subsub.__name__) reload(t3) reload(t3.sub) reload(t3.sub.subsub) """), ("t4", [ - ("t4"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (t4"+os.extsep+"py)'"), + ("t4"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (t4"+os.extsep+"py)')"), ("t4", None), - ("t4 __init__"+os.extsep+"py", "print __name__, 'loading'"), - ("t4 sub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)'"), + ("t4 __init__"+os.extsep+"py", "print(__name__, 'loading')"), + ("t4 sub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)')"), ("t4 sub", None), ("t4 sub __init__"+os.extsep+"py", ""), - ("t4 sub subsub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)'"), + ("t4 sub subsub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)')"), ("t4 sub subsub", None), - ("t4 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), + ("t4 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"), ], """ from t4.sub.subsub import * -print "t4.sub.subsub.spam =", spam +print("t4.sub.subsub.spam =", spam) """), ("t5", [ ("t5", None), ("t5 __init__"+os.extsep+"py", "import t5.foo"), - ("t5 string"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), + ("t5 string"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"), ("t5 foo"+os.extsep+"py", - "print __name__, 'loading'; from . import string; print string.spam"), + "print(__name__, 'loading'); from . import string; print(string.spam)"), ], """ import t5 from t5 import * -print dir() +print(dir()) import t5 -print fixdir(dir(t5)) -print fixdir(dir(t5.foo)) -print fixdir(dir(t5.string)) +print(fixdir(dir(t5))) +print(fixdir(dir(t5.foo))) +print(fixdir(dir(t5.string))) """), ("t6", [ ("t6", None), ("t6 __init__"+os.extsep+"py", "__all__ = ['spam', 'ham', 'eggs']"), - ("t6 spam"+os.extsep+"py", "print __name__, 'loading'"), - ("t6 ham"+os.extsep+"py", "print __name__, 'loading'"), - ("t6 eggs"+os.extsep+"py", "print __name__, 'loading'"), + ("t6 spam"+os.extsep+"py", "print(__name__, 'loading')"), + ("t6 ham"+os.extsep+"py", "print(__name__, 'loading')"), + ("t6 eggs"+os.extsep+"py", "print(__name__, 'loading')"), ], """ import t6 -print fixdir(dir(t6)) +print(fixdir(dir(t6))) from t6 import * -print fixdir(dir(t6)) -print dir() +print(fixdir(dir(t6))) +print(dir()) """), ("t7", [ - ("t7"+os.extsep+"py", "print 'Importing t7"+os.extsep+"py'"), + ("t7"+os.extsep+"py", "print('Importing t7"+os.extsep+"py')"), ("t7", None), - ("t7 __init__"+os.extsep+"py", "print __name__, 'loading'"), - ("t7 sub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)'"), + ("t7 __init__"+os.extsep+"py", "print(__name__, 'loading')"), + ("t7 sub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (sub"+os.extsep+"py)')"), ("t7 sub", None), ("t7 sub __init__"+os.extsep+"py", ""), - ("t7 sub subsub"+os.extsep+"py", "print 'THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)'"), + ("t7 sub subsub"+os.extsep+"py", "print('THIS SHOULD NOT BE PRINTED (subsub"+os.extsep+"py)')"), ("t7 sub subsub", None), - ("t7 sub subsub __init__"+os.extsep+"py", "print __name__, 'loading'; spam = 1"), + ("t7 sub subsub __init__"+os.extsep+"py", "print(__name__, 'loading'); spam = 1"), ], """ t7, sub, subsub = None, None, None import t7 as tas -print fixdir(dir(tas)) +print(fixdir(dir(tas))) verify(not t7) from t7 import sub as subpar -print fixdir(dir(subpar)) +print(fixdir(dir(subpar))) verify(not t7 and not sub) from t7.sub import subsub as subsubsub -print fixdir(dir(subsubsub)) +print(fixdir(dir(subsubsub))) verify(not t7 and not sub and not subsub) from t7.sub.subsub import spam as ham -print "t7.sub.subsub.spam =", ham +print("t7.sub.subsub.spam =", ham) verify(not t7 and not sub and not subsub) """), diff --git a/Lib/test/test_popen.py b/Lib/test/test_popen.py index 069f370..2457396 100644 --- a/Lib/test/test_popen.py +++ b/Lib/test/test_popen.py @@ -19,7 +19,7 @@ if ' ' in python: class PopenTest(unittest.TestCase): def _do_test_commandline(self, cmdline, expected): - cmd = '%s -c "import sys;print sys.argv" %s' % (python, cmdline) + cmd = '%s -c "import sys; print(sys.argv)" %s' % (python, cmdline) data = os.popen(cmd).read() got = eval(data)[1:] # strip off argv[0] self.assertEqual(got, expected) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 1b34d61..ce7b659 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -84,7 +84,7 @@ class ProcessTestCase(unittest.TestCase): def test_stdin_none(self): # .stdin is None when not redirected - p = subprocess.Popen([sys.executable, "-c", 'print "banana"'], + p = subprocess.Popen([sys.executable, "-c", 'print("banana")'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() self.assertEqual(p.stdin, None) @@ -92,16 +92,16 @@ class ProcessTestCase(unittest.TestCase): def test_stdout_none(self): # .stdout is None when not redirected p = subprocess.Popen([sys.executable, "-c", - 'print " this bit of output is from a ' + 'print(" this bit of output is from a ' 'test of stdout in a different ' - 'process ..."'], + 'process ...")'], stdin=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() self.assertEqual(p.stdout, None) def test_stderr_none(self): # .stderr is None when not redirected - p = subprocess.Popen([sys.executable, "-c", 'print "banana"'], + p = subprocess.Popen([sys.executable, "-c", 'print("banana")'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) p.wait() self.assertEqual(p.stderr, None) diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index ba33761..8999e3a 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -423,7 +423,7 @@ class SyntaxTestCase(unittest.TestCase): source = re.sub('(?m)^ *:', '', """\ :def foo(x): : def bar(): - : print x + : print(x) : del x :""") self._check_error(source, "nested scope") diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py index 7d6a818..138ed74 100644 --- a/Lib/test/test_tokenize.py +++ b/Lib/test/test_tokenize.py @@ -43,9 +43,9 @@ regenerate the original program text from the tokens. There are some standard formatting practices that are easy to get right. >>> roundtrip("if x == 1:\\n" -... " print x\\n") +... " print(x)\\n") if x == 1: - print x + print(x) Some people use different formatting conventions, which makes untokenize a little trickier. Note that this test involves trailing @@ -53,29 +53,29 @@ whitespace after the colon. Note that we use hex escapes to make the two trailing blanks apparent in the expected output. >>> roundtrip("if x == 1 : \\n" -... " print x\\n") +... " print(x)\\n") if x == 1 :\x20\x20 - print x + print(x) Comments need to go in the right place. >>> roundtrip("if x == 1:\\n" ... " # A comment by itself.\\n" -... " print x # Comment here, too.\\n" +... " print(x) # Comment here, too.\\n" ... " # Another comment.\\n" ... "after_if = True\\n") if x == 1: # A comment by itself. - print x # Comment here, too. + print(x) # Comment here, too. # Another comment. after_if = True >>> roundtrip("if (x # The comments need to go in the right place\\n" ... " == 1):\\n" -... " print 'x == 1'\\n") +... " print('x == 1')\\n") if (x # The comments need to go in the right place == 1): - print 'x == 1' + print('x == 1') """ @@ -130,9 +130,9 @@ def decistmt(s): """Substitute Decimals for floats in a string of statements. >>> from decimal import Decimal - >>> s = 'print +21.3e-5*-.1234/81.7' + >>> s = 'print(+21.3e-5*-.1234/81.7)' >>> decistmt(s) - "print +Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7')" + "print (+Decimal ('21.3e-5')*-Decimal ('.1234')/Decimal ('81.7'))" The format of the exponent is inherited from the platform C library. Known cases are "e-007" (Windows) and "e-07" (not Windows). Since diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 1ccb2b2..9c7af70 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -25,7 +25,7 @@ class TracebackCases(unittest.TestCase): import test.badsyntax_nocaret def syntax_error_bad_indentation(self): - compile("def spam():\n print 1\n print 2", "?", "exec") + compile("def spam():\n print(1)\n print(2)", "?", "exec") def test_caret(self): err = self.get_exception_format(self.syntax_error_with_caret, @@ -48,9 +48,9 @@ class TracebackCases(unittest.TestCase): err = self.get_exception_format(self.syntax_error_bad_indentation, IndentationError) self.assert_(len(err) == 4) - self.assert_(err[1].strip() == "print 2") + self.assert_(err[1].strip() == "print(2)") self.assert_("^" in err[2]) - self.assert_(err[1].find("2") == err[2].find("^")) + self.assert_(err[1].find(")") == err[2].find("^")) def test_bug737473(self): import sys, os, tempfile, time |