annotate Lib/test/test_new.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 816c21c762c8
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
1 import unittest
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
2 from test import test_support
46775
816c21c762c8 Deprecate the new module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 40680
diff changeset
3 import sys
816c21c762c8 Deprecate the new module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 40680
diff changeset
4 new = test_support.import_module('new', deprecated=True)
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
5
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
6 class NewTest(unittest.TestCase):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
7 def test_spam(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
8 class Eggs:
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
9 def get_yolks(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
10 return self.yolks
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
11
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
12 m = new.module('Spam')
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
13 m.Eggs = Eggs
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
14 sys.modules['Spam'] = m
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
15 import Spam
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
16
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
17 def get_more_yolks(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
18 return self.yolks + 3
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
19
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
20 # new.classobj()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
21 C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
22
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
23 # new.instance()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
24 c = new.instance(C, {'yolks': 3})
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
25
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
26 o = new.instance(C)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
27 self.assertEqual(o.__dict__, {}, "new __dict__ should be empty")
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
28 del o
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
29 o = new.instance(C, None)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
30 self.assertEqual(o.__dict__, {}, "new __dict__ should be empty")
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
31 del o
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
32
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
33 def break_yolks(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
34 self.yolks = self.yolks - 2
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
35
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
36 # new.instancemethod()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
37 im = new.instancemethod(break_yolks, c, C)
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
38
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
39 self.assertEqual(c.get_yolks(), 3,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
40 'Broken call of hand-crafted class instance')
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
41 self.assertEqual(c.get_more_yolks(), 6,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
42 'Broken call of hand-crafted class instance')
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
43
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
44 im()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
45 self.assertEqual(c.get_yolks(), 1,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
46 'Broken call of hand-crafted instance method')
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
47 self.assertEqual(c.get_more_yolks(), 4,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
48 'Broken call of hand-crafted instance method')
34850
aef713de7a23 Backport:
Michael W. Hudson <mwh@python.net>
parents: 33116
diff changeset
49
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
50 im = new.instancemethod(break_yolks, c)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
51 im()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
52 self.assertEqual(c.get_yolks(), -1)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
53
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
54 # Verify that dangerous instance method creation is forbidden
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
55 self.assertRaises(TypeError, new.instancemethod, break_yolks, None)
39921
49fbddfb1217 Patch #1567691: super() and new.instancemethod() now don't accept
Georg Brandl <georg@python.org>
parents: 34850
diff changeset
56
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
57 # Verify that instancemethod() doesn't allow keyword args
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
58 self.assertRaises(TypeError, new.instancemethod, break_yolks, c, kw=1)
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
59
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
60 def test_scope(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
61 # It's unclear what the semantics should be for a code object compiled
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
62 # at module scope, but bound and run in a function. In CPython, `c' is
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
63 # global (by accident?) while in Jython, `c' is local. The intent of
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
64 # the test clearly is to make `c' global, so let's be explicit about it.
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
65 codestr = '''
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
66 global c
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
67 a = 1
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
68 b = 2
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
69 c = a + b
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
70 '''
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
71
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
72 codestr = "\n".join(l.strip() for l in codestr.splitlines())
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
73
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
74 ccode = compile(codestr, '<string>', 'exec')
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
75 # Jython doesn't have a __builtins__, so use a portable alternative
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
76 import __builtin__
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
77 g = {'c': 0, '__builtins__': __builtin__}
4663
4ee4b8bb67c7 A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff changeset
78
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
79 # this test could be more robust
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
80 func = new.function(ccode, g)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
81 func()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
82 self.assertEqual(g['c'], 3, 'Could not create a proper function object')
24193
6eb74e83a6f1 Extend function() to support an optional closure argument.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21317
diff changeset
83
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
84 def test_function(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
85 # test the various extended flavors of function.new
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
86 def f(x):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
87 def g(y):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
88 return x + y
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
89 return g
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
90 g = f(4)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
91 new.function(f.func_code, {}, "blah")
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
92 g2 = new.function(g.func_code, {}, "blah", (2,), g.func_closure)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
93 self.assertEqual(g2(), 6)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
94 g3 = new.function(g.func_code, {}, "blah", None, g.func_closure)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
95 self.assertEqual(g3(5), 9)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
96 def test_closure(func, closure, exc):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
97 self.assertRaises(exc, new.function, func.func_code, {}, "", None, closure)
33116
3a4e73a5e434 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33100
diff changeset
98
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
99 test_closure(g, None, TypeError) # invalid closure
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
100 test_closure(g, (1,), TypeError) # non-cell in closure
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
101 test_closure(g, (1, 1), ValueError) # closure is wrong size
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
102 test_closure(f, g.func_closure, ValueError) # no closure needed
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
103
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
104 # Note: Jython will never have new.code()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
105 if hasattr(new, 'code'):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
106 def test_code(self):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
107 # bogus test of new.code()
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
108 def f(a): pass
33116
3a4e73a5e434 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33100
diff changeset
109
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
110 c = f.func_code
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
111 argcount = c.co_argcount
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
112 nlocals = c.co_nlocals
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
113 stacksize = c.co_stacksize
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
114 flags = c.co_flags
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
115 codestring = c.co_code
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
116 constants = c.co_consts
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
117 names = c.co_names
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
118 varnames = c.co_varnames
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
119 filename = c.co_filename
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
120 name = c.co_name
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
121 firstlineno = c.co_firstlineno
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
122 lnotab = c.co_lnotab
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
123 freevars = c.co_freevars
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
124 cellvars = c.co_cellvars
33116
3a4e73a5e434 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33100
diff changeset
125
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
126 d = new.code(argcount, nlocals, stacksize, flags, codestring,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
127 constants, names, varnames, filename, name,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
128 firstlineno, lnotab, freevars, cellvars)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
129
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
130 # test backwards-compatibility version with no freevars or cellvars
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
131 d = new.code(argcount, nlocals, stacksize, flags, codestring,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
132 constants, names, varnames, filename, name,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
133 firstlineno, lnotab)
33100
356887410bde Fix bug
Michael W. Hudson <mwh@python.net>
parents: 32333
diff changeset
134
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
135 # negative co_argcount used to trigger a SystemError
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
136 self.assertRaises(ValueError, new.code,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
137 -argcount, nlocals, stacksize, flags, codestring,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
138 constants, names, varnames, filename, name, firstlineno, lnotab)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
139
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
140 # negative co_nlocals used to trigger a SystemError
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
141 self.assertRaises(ValueError, new.code,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
142 argcount, -nlocals, stacksize, flags, codestring,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
143 constants, names, varnames, filename, name, firstlineno, lnotab)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
144
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
145 # non-string co_name used to trigger a Py_FatalError
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
146 self.assertRaises(TypeError, new.code,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
147 argcount, nlocals, stacksize, flags, codestring,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
148 constants, (5,), varnames, filename, name, firstlineno, lnotab)
33116
3a4e73a5e434 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33100
diff changeset
149
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
150 # new.code used to be a way to mutate a tuple...
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
151 class S(str):
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
152 pass
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
153 t = (S("ab"),)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
154 d = new.code(argcount, nlocals, stacksize, flags, codestring,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
155 constants, t, varnames, filename, name,
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
156 firstlineno, lnotab)
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
157 self.assert_(type(t[0]) is S, "eek, tuple changed under us!")
33100
356887410bde Fix bug
Michael W. Hudson <mwh@python.net>
parents: 32333
diff changeset
158
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
159 def test_main():
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
160 test_support.run_unittest(NewTest)
33100
356887410bde Fix bug
Michael W. Hudson <mwh@python.net>
parents: 32333
diff changeset
161
40680
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
162 if __name__ == "__main__":
5f8a54c804ff Port test_new.py to unittest.
Walter Dörwald <walter@livinglogic.de>
parents: 39921
diff changeset
163 test_main()