summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_code.py12
-rw-r--r--Lib/test/test_compile.py4
-rw-r--r--Lib/test/test_compiler.py2
-rw-r--r--Lib/test/test_copy.py4
-rw-r--r--Lib/test/test_decorators.py10
-rw-r--r--Lib/test/test_dis.py16
-rw-r--r--Lib/test/test_extcall.py2
-rw-r--r--Lib/test/test_funcattrs.py69
-rw-r--r--Lib/test/test_grammar.py32
-rw-r--r--Lib/test/test_hotshot.py4
-rw-r--r--Lib/test/test_inspect.py4
-rw-r--r--Lib/test/test_keywordonlyarg.py8
-rw-r--r--Lib/test/test_marshal.py2
-rw-r--r--Lib/test/test_new.py12
-rw-r--r--Lib/test/test_profilehooks.py2
-rw-r--r--Lib/test/test_pyclbr.py2
-rw-r--r--Lib/test/test_scope.py4
-rw-r--r--Lib/test/test_struct.py2
-rw-r--r--Lib/test/test_support.py2
-rw-r--r--Lib/test/test_sys.py2
-rw-r--r--Lib/test/test_trace.py8
-rw-r--r--Lib/test/test_univnewlines.py2
-rw-r--r--Lib/test/test_urllib.py2
23 files changed, 94 insertions, 113 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py
index 4f43f5d..7512263 100644
--- a/Lib/test/test_code.py
+++ b/Lib/test/test_code.py
@@ -6,7 +6,7 @@
... return g
...
->>> dump(f.func_code)
+>>> dump(f.__code__)
name: f
argcount: 1
kwonlyargcount: 0
@@ -18,7 +18,7 @@ nlocals: 2
flags: 3
consts: ('None', '<code object g>')
->>> dump(f(4).func_code)
+>>> dump(f(4).__code__)
name: g
argcount: 1
kwonlyargcount: 0
@@ -37,7 +37,7 @@ consts: ('None',)
... return c
...
->>> dump(h.func_code)
+>>> dump(h.__code__)
name: h
argcount: 2
kwonlyargcount: 0
@@ -54,7 +54,7 @@ consts: ('None',)
... print(obj.attr2)
... print(obj.attr3)
->>> dump(attrs.func_code)
+>>> dump(attrs.__code__)
name: attrs
argcount: 1
kwonlyargcount: 0
@@ -72,7 +72,7 @@ consts: ('None',)
... 53
... 0x53
->>> dump(optimize_away.func_code)
+>>> dump(optimize_away.__code__)
name: optimize_away
argcount: 0
kwonlyargcount: 0
@@ -88,7 +88,7 @@ consts: ("'doc string'", 'None')
... return a,b,k1
...
->>> dump(keywordonly_args.func_code)
+>>> dump(keywordonly_args.__code__)
name: keywordonly_args
argcount: 2
kwonlyargcount: 1
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index 1acb4a1..022f7c0 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -235,7 +235,7 @@ if 1:
g = +9223372036854775807 # 1 << 63 - 1
h = -9223372036854775807 # 1 << 63 - 1
- for variable in self.test_32_63_bit_values.func_code.co_consts:
+ for variable in self.test_32_63_bit_values.__code__.co_consts:
if variable is not None:
self.assertTrue(isinstance(variable, int))
@@ -315,7 +315,7 @@ if 1:
f2 = lambda x=2: x
return f1, f2
f1, f2 = f()
- self.assertNotEqual(id(f1.func_code), id(f2.func_code))
+ self.assertNotEqual(id(f1.__code__), id(f2.__code__))
def test_unicode_encoding(self):
code = u"# -*- coding: utf-8 -*-\npass\n"
diff --git a/Lib/test/test_compiler.py b/Lib/test/test_compiler.py
index bbd7511..8535f42 100644
--- a/Lib/test/test_compiler.py
+++ b/Lib/test/test_compiler.py
@@ -160,7 +160,7 @@ class CompilerTest(unittest.TestCase):
c = compiler.compile(sourcecode, '<string>', 'exec')
dct = {}
exec(c, dct)
- self.assertEquals(dct['f'].func_annotations, expected)
+ self.assertEquals(dct['f'].__annotations__, expected)
def testWith(self):
# SF bug 1638243
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index cb075c3..fd6109c 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -83,7 +83,7 @@ class TestCopy(unittest.TestCase):
def f():
pass
tests = [None, 42, 2**100, 3.14, True, False, 1j,
- "hello", u"hello\u1234", f.func_code,
+ "hello", u"hello\u1234", f.__code__,
NewStyle, xrange(10), Classic, max]
for x in tests:
self.assert_(copy.copy(x) is x, repr(x))
@@ -256,7 +256,7 @@ class TestCopy(unittest.TestCase):
def f():
pass
tests = [None, 42, 2**100, 3.14, True, False, 1j,
- "hello", u"hello\u1234", f.func_code,
+ "hello", u"hello\u1234", f.__code__,
NewStyle, xrange(10), Classic, max]
for x in tests:
self.assert_(copy.deepcopy(x) is x, repr(x))
diff --git a/Lib/test/test_decorators.py b/Lib/test/test_decorators.py
index 56aa5e1..2558247 100644
--- a/Lib/test/test_decorators.py
+++ b/Lib/test/test_decorators.py
@@ -27,7 +27,7 @@ class DbcheckError (Exception):
def dbcheck(exprstr, globals=None, locals=None):
"Decorator to implement debugging assertions"
def decorate(func):
- expr = compile(exprstr, "dbcheck-%s" % func.func_name, "eval")
+ expr = compile(exprstr, "dbcheck-%s" % func.__name__, "eval")
def check(*args, **kwds):
if not eval(expr, globals, locals):
raise DbcheckError(exprstr, func, args, kwds)
@@ -40,12 +40,12 @@ def dbcheck(exprstr, globals=None, locals=None):
def countcalls(counts):
"Decorator to count calls to a function"
def decorate(func):
- func_name = func.func_name
+ func_name = func.__name__
counts[func_name] = 0
def call(*args, **kwds):
counts[func_name] += 1
return func(*args, **kwds)
- call.func_name = func_name
+ call.__name__ = func_name
return call
return decorate
@@ -63,7 +63,7 @@ def memoize(func):
except TypeError:
# Unhashable argument
return func(*args)
- call.func_name = func.func_name
+ call.__name__ = func.__name__
return call
# -----------------------------------------------
@@ -131,7 +131,7 @@ class TestDecorators(unittest.TestCase):
@countcalls(counts)
def double(x):
return x * 2
- self.assertEqual(double.func_name, 'double')
+ self.assertEqual(double.__name__, 'double')
self.assertEqual(counts, dict(double=0))
diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py
index ab70778..bb8638b 100644
--- a/Lib/test/test_dis.py
+++ b/Lib/test/test_dis.py
@@ -19,8 +19,8 @@ dis_f = """\
%-4d 10 LOAD_CONST 1 (1)
13 RETURN_VALUE
-"""%(_f.func_code.co_firstlineno + 1,
- _f.func_code.co_firstlineno + 2)
+"""%(_f.__code__.co_firstlineno + 1,
+ _f.__code__.co_firstlineno + 2)
def bug708901():
@@ -43,9 +43,9 @@ dis_bug708901 = """\
>> 25 POP_BLOCK
>> 26 LOAD_CONST 0 (None)
29 RETURN_VALUE
-"""%(bug708901.func_code.co_firstlineno + 1,
- bug708901.func_code.co_firstlineno + 2,
- bug708901.func_code.co_firstlineno + 3)
+"""%(bug708901.__code__.co_firstlineno + 1,
+ bug708901.__code__.co_firstlineno + 2,
+ bug708901.__code__.co_firstlineno + 3)
def bug1333982(x=[]):
@@ -78,9 +78,9 @@ dis_bug1333982 = """\
%-4d 48 LOAD_CONST 0 (None)
51 RETURN_VALUE
-"""%(bug1333982.func_code.co_firstlineno + 1,
- bug1333982.func_code.co_firstlineno + 2,
- bug1333982.func_code.co_firstlineno + 3)
+"""%(bug1333982.__code__.co_firstlineno + 1,
+ bug1333982.__code__.co_firstlineno + 2,
+ bug1333982.__code__.co_firstlineno + 3)
_BIG_LINENO_FORMAT = """\
%3d 0 LOAD_GLOBAL 0 (spam)
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 3e0426f..453f464 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -274,6 +274,6 @@ for name in ['za', 'zade', 'zabk', 'zabdv', 'zabdevk']:
for kwargs in ['', 'a', 'd', 'ad', 'abde']:
kwdict = {}
for k in kwargs: kwdict[k] = k + k
- print(func.func_name, args, sortdict(kwdict), '->', end=' ')
+ print(func.__name__, args, sortdict(kwdict), '->', end=' ')
try: func(*args, **kwdict)
except TypeError as err: print(err)
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py
index 2f4b67a..528ca18 100644
--- a/Lib/test/test_funcattrs.py
+++ b/Lib/test/test_funcattrs.py
@@ -47,7 +47,7 @@ else: raise TestFailed, 'func.__dict__ = None expected TypeError'
d = {'hello': 'world'}
b.__dict__ = d
-if b.func_dict is not d:
+if b.__dict__ is not d:
raise TestFailed, 'func.__dict__ assignment to dictionary failed'
if b.hello != 'world':
raise TestFailed, 'attribute after func.__dict__ assignment failed'
@@ -179,12 +179,12 @@ except TypeError: pass
else: raise TestFailed
try:
- del another.func_dict
+ del another.__dict__
except TypeError: pass
else: raise TestFailed
try:
- another.func_dict = None
+ another.__dict__ = None
except TypeError: pass
else: raise TestFailed
@@ -195,7 +195,7 @@ else: raise TestFailed
# This isn't specifically related to function attributes, but it does test a
# core dump regression in funcobject.c
-del another.func_defaults
+del another.__defaults__
def foo():
pass
@@ -212,7 +212,7 @@ if foo==bar:
d={}
d[foo] = 1
-foo.func_code = temp.func_code
+foo.__code__ = temp.__code__
d[foo]
@@ -236,45 +236,31 @@ def cantset(obj, name, value, exception=(AttributeError, TypeError)):
def test_func_closure():
a = 12
def f(): print(a)
- c = f.func_closure
+ c = f.__closure__
verify(isinstance(c, tuple))
verify(len(c) == 1)
verify(c[0].__class__.__name__ == "cell") # don't have a type object handy
- cantset(f, "func_closure", c)
+ cantset(f, "__closure__", c)
def test_func_doc():
def f(): pass
verify(f.__doc__ is None)
- verify(f.func_doc is None)
f.__doc__ = "hello"
verify(f.__doc__ == "hello")
- verify(f.func_doc == "hello")
del f.__doc__
verify(f.__doc__ is None)
- verify(f.func_doc is None)
- f.func_doc = "world"
- verify(f.__doc__ == "world")
- verify(f.func_doc == "world")
- del f.func_doc
- verify(f.func_doc is None)
- verify(f.__doc__ is None)
def test_func_globals():
def f(): pass
- verify(f.func_globals is globals())
- cantset(f, "func_globals", globals())
+ verify(f.__globals__ is globals())
+ cantset(f, "__globals__", globals())
def test_func_name():
def f(): pass
verify(f.__name__ == "f")
- verify(f.func_name == "f")
f.__name__ = "g"
verify(f.__name__ == "g")
- verify(f.func_name == "g")
- f.func_name = "h"
- verify(f.__name__ == "h")
- verify(f.func_name == "h")
- cantset(f, "func_globals", 1)
+ cantset(f, "__globals__", 1)
cantset(f, "__name__", 1)
# test that you can access func.__name__ in restricted mode
s = """def f(): pass\nf.__name__"""
@@ -288,25 +274,25 @@ def test_func_code():
def f1(): print(a)
def g1(): print(b)
def f2(): print(a, b)
- verify(type(f.func_code) is types.CodeType)
- f.func_code = g.func_code
- cantset(f, "func_code", None)
+ verify(type(f.__code__) is types.CodeType)
+ f.__code__ = g.__code__
+ cantset(f, "__code__", None)
# can't change the number of free vars
- cantset(f, "func_code", f1.func_code, exception=ValueError)
- cantset(f1, "func_code", f.func_code, exception=ValueError)
- cantset(f1, "func_code", f2.func_code, exception=ValueError)
- f1.func_code = g1.func_code
+ cantset(f, "__code__", f1.__code__, exception=ValueError)
+ cantset(f1, "__code__", f.__code__, exception=ValueError)
+ cantset(f1, "__code__", f2.__code__, exception=ValueError)
+ f1.__code__ = g1.__code__
def test_func_defaults():
def f(a, b): return (a, b)
- verify(f.func_defaults is None)
- f.func_defaults = (1, 2)
- verify(f.func_defaults == (1, 2))
+ verify(f.__defaults__ is None)
+ f.__defaults__ = (1, 2)
+ verify(f.__defaults__ == (1, 2))
verify(f(10) == (10, 2))
def g(a=1, b=2): return (a, b)
- verify(g.func_defaults == (1, 2))
- del g.func_defaults
- verify(g.func_defaults is None)
+ verify(g.__defaults__ == (1, 2))
+ del g.__defaults__
+ verify(g.__defaults__ is None)
try:
g()
except TypeError:
@@ -317,18 +303,13 @@ def test_func_defaults():
def test_func_dict():
def f(): pass
a = f.__dict__
- b = f.func_dict
verify(a == {})
- verify(a is b)
f.hello = 'world'
verify(a == {'hello': 'world'})
- verify(f.func_dict is a is f.__dict__)
- f.func_dict = {}
- verify(not hasattr(f, "hello"))
+ verify(a is f.__dict__)
f.__dict__ = {'world': 'hello'}
verify(f.world == "hello")
- verify(f.__dict__ is f.func_dict == {'world': 'hello'})
- cantset(f, "func_dict", None)
+ verify(f.__dict__ == {'world': 'hello'})
cantset(f, "__dict__", None)
def test_im_class():
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 4a480aa..cb37021 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -162,18 +162,18 @@ class GrammarTests(unittest.TestCase):
def f3(two, arguments): pass
def f4(two, (compound, (argument, list))): pass
def f5((compound, first), two): pass
- self.assertEquals(f2.func_code.co_varnames, ('one_argument',))
- self.assertEquals(f3.func_code.co_varnames, ('two', 'arguments'))
+ self.assertEquals(f2.__code__.co_varnames, ('one_argument',))
+ self.assertEquals(f3.__code__.co_varnames, ('two', 'arguments'))
if sys.platform.startswith('java'):
- self.assertEquals(f4.func_code.co_varnames,
+ self.assertEquals(f4.__code__.co_varnames,
('two', '(compound, (argument, list))', 'compound', 'argument',
'list',))
- self.assertEquals(f5.func_code.co_varnames,
+ self.assertEquals(f5.__code__.co_varnames,
('(compound, first)', 'two', 'compound', 'first'))
else:
- self.assertEquals(f4.func_code.co_varnames,
+ self.assertEquals(f4.__code__.co_varnames,
('two', '.1', 'compound', 'argument', 'list'))
- self.assertEquals(f5.func_code.co_varnames,
+ self.assertEquals(f5.__code__.co_varnames,
('.0', 'two', 'compound', 'first'))
def a1(one_arg,): pass
def a2(two, args,): pass
@@ -209,9 +209,9 @@ class GrammarTests(unittest.TestCase):
# ceval unpacks the formal arguments into the first argcount names;
# thus, the names nested inside tuples must appear after these names.
if sys.platform.startswith('java'):
- self.assertEquals(v3.func_code.co_varnames, ('a', '(b, c)', 'rest', 'b', 'c'))
+ self.assertEquals(v3.__code__.co_varnames, ('a', '(b, c)', 'rest', 'b', 'c'))
else:
- self.assertEquals(v3.func_code.co_varnames, ('a', '.1', 'rest', 'b', 'c'))
+ self.assertEquals(v3.__code__.co_varnames, ('a', '.1', 'rest', 'b', 'c'))
self.assertEquals(v3(1, (2, 3), 4), (1, 2, 3, (4,)))
def d01(a=1): pass
d01()
@@ -302,23 +302,23 @@ class GrammarTests(unittest.TestCase):
# argument annotation tests
def f(x) -> list: pass
- self.assertEquals(f.func_annotations, {'return': list})
+ self.assertEquals(f.__annotations__, {'return': list})
def f(x:int): pass
- self.assertEquals(f.func_annotations, {'x': int})
+ self.assertEquals(f.__annotations__, {'x': int})
def f(*x:str): pass
- self.assertEquals(f.func_annotations, {'x': str})
+ self.assertEquals(f.__annotations__, {'x': str})
def f(**x:float): pass
- self.assertEquals(f.func_annotations, {'x': float})
+ self.assertEquals(f.__annotations__, {'x': float})
def f(x, y:1+2): pass
- self.assertEquals(f.func_annotations, {'y': 3})
+ self.assertEquals(f.__annotations__, {'y': 3})
def f(a, (b:1, c:2, d)): pass
- self.assertEquals(f.func_annotations, {'b': 1, 'c': 2})
+ self.assertEquals(f.__annotations__, {'b': 1, 'c': 2})
def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6): pass
- self.assertEquals(f.func_annotations,
+ self.assertEquals(f.__annotations__,
{'b': 1, 'c': 2, 'e': 3, 'g': 6})
def f(a, (b:1, c:2, d), e:3=4, f=5, *g:6, h:7, i=8, j:9=10,
**k:11) -> 12: pass
- self.assertEquals(f.func_annotations,
+ self.assertEquals(f.__annotations__,
{'b': 1, 'c': 2, 'e': 3, 'g': 6, 'h': 7, 'j': 9,
'k': 11, 'return': 12})
diff --git a/Lib/test/test_hotshot.py b/Lib/test/test_hotshot.py
index 2751b3f..5480257 100644
--- a/Lib/test/test_hotshot.py
+++ b/Lib/test/test_hotshot.py
@@ -85,8 +85,8 @@ class HotShotTestCase(unittest.TestCase):
x = 1
def g():
f()
- f_lineno = f.func_code.co_firstlineno
- g_lineno = g.func_code.co_firstlineno
+ f_lineno = f.__code__.co_firstlineno
+ g_lineno = g.__code__.co_firstlineno
events = [(ENTER, ("test_hotshot", g_lineno, "g")),
(LINE, ("test_hotshot", g_lineno+1, "g")),
(ENTER, ("test_hotshot", f_lineno, "f")),
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index 296e259..5e03218 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -53,7 +53,7 @@ class TestPredicates(IsTestBase):
self.istest(inspect.isbuiltin, 'sys.exit')
self.istest(inspect.isbuiltin, '[].append')
self.istest(inspect.isclass, 'mod.StupidGit')
- self.istest(inspect.iscode, 'mod.spam.func_code')
+ self.istest(inspect.iscode, 'mod.spam.__code__')
self.istest(inspect.isframe, 'tb.tb_frame')
self.istest(inspect.isfunction, 'mod.spam')
self.istest(inspect.ismethod, 'mod.StupidGit.abuse')
@@ -210,7 +210,7 @@ class TestRetrievingSourceCode(GetSourceBase):
m.__file__ = "<string>" # hopefully not a real filename...
m.__loader__ = "dummy" # pretend the filename is understood by a loader
exec("def x(): pass", m.__dict__)
- self.assertEqual(inspect.getsourcefile(m.x.func_code), '<string>')
+ self.assertEqual(inspect.getsourcefile(m.x.__code__), '<string>')
del sys.modules[name]
inspect.getmodule(compile('a=10','','single'))
diff --git a/Lib/test/test_keywordonlyarg.py b/Lib/test/test_keywordonlyarg.py
index 0ace785..2e1f8bd 100644
--- a/Lib/test/test_keywordonlyarg.py
+++ b/Lib/test/test_keywordonlyarg.py
@@ -135,12 +135,12 @@ class KeywordOnlyArgTestCase(unittest.TestCase):
def foo(p1,p2=0, *, k1, k2=0):
return p1 + p2 + k1 + k2
- self.assertEquals(2, foo.func_code.co_kwonlyargcount)
- self.assertEquals({"k2":0}, foo.func_kwdefaults)
- foo.func_kwdefaults = {"k1":0}
+ self.assertEquals(2, foo.__code__.co_kwonlyargcount)
+ self.assertEquals({"k2":0}, foo.__kwdefaults__)
+ foo.__kwdefaults__ = {"k1":0}
try:
foo(1,k1=10)
- self.fail("func_kwdefaults is not properly changed")
+ self.fail("__kwdefaults__ is not properly changed")
except TypeError:
pass
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 6c98022..9c58c12 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -144,7 +144,7 @@ class ExceptionTestCase(unittest.TestCase):
class CodeTestCase(unittest.TestCase):
def test_code(self):
- co = ExceptionTestCase.test_exceptions.func_code
+ co = ExceptionTestCase.test_exceptions.__code__
new = marshal.loads(marshal.dumps(co))
self.assertEqual(co, new)
diff --git a/Lib/test/test_new.py b/Lib/test/test_new.py
index e2d26fa..797a8c3 100644
--- a/Lib/test/test_new.py
+++ b/Lib/test/test_new.py
@@ -79,18 +79,18 @@ class NewTest(unittest.TestCase):
return x + y
return g
g = f(4)
- new.function(f.func_code, {}, "blah")
- g2 = new.function(g.func_code, {}, "blah", (2,), g.func_closure)
+ new.function(f.__code__, {}, "blah")
+ g2 = new.function(g.__code__, {}, "blah", (2,), g.__closure__)
self.assertEqual(g2(), 6)
- g3 = new.function(g.func_code, {}, "blah", None, g.func_closure)
+ g3 = new.function(g.__code__, {}, "blah", None, g.__closure__)
self.assertEqual(g3(5), 9)
def test_closure(func, closure, exc):
- self.assertRaises(exc, new.function, func.func_code, {}, "", None, closure)
+ self.assertRaises(exc, new.function, func.__code__, {}, "", None, closure)
test_closure(g, None, TypeError) # invalid closure
test_closure(g, (1,), TypeError) # non-cell in closure
test_closure(g, (1, 1), ValueError) # closure is wrong size
- test_closure(f, g.func_closure, ValueError) # no closure needed
+ test_closure(f, g.__closure__, ValueError) # no closure needed
# Note: Jython will never have new.code()
if hasattr(new, 'code'):
@@ -98,7 +98,7 @@ class NewTest(unittest.TestCase):
# bogus test of new.code()
def f(a): pass
- c = f.func_code
+ c = f.__code__
argcount = c.co_argcount
kwonlyargcount = c.co_kwonlyargcount
nlocals = c.co_nlocals
diff --git a/Lib/test/test_profilehooks.py b/Lib/test/test_profilehooks.py
index 53f882a..0f5616d 100644
--- a/Lib/test/test_profilehooks.py
+++ b/Lib/test/test_profilehooks.py
@@ -324,7 +324,7 @@ def ident(function):
if hasattr(function, "f_code"):
code = function.f_code
else:
- code = function.func_code
+ code = function.__code__
return code.co_firstlineno, code.co_name
diff --git a/Lib/test/test_pyclbr.py b/Lib/test/test_pyclbr.py
index 478083e..1edda75 100644
--- a/Lib/test/test_pyclbr.py
+++ b/Lib/test/test_pyclbr.py
@@ -140,7 +140,7 @@ class PyclbrTest(TestCase):
if isinstance(item, ClassType):
return item.__module__ == module.__name__
if isinstance(item, FunctionType):
- return item.func_globals is module.__dict__
+ return item.__globals__ is module.__dict__
return False
for name in dir(module):
item = getattr(module, name)
diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py
index 31e57e5..b9dc711 100644
--- a/Lib/test/test_scope.py
+++ b/Lib/test/test_scope.py
@@ -518,10 +518,10 @@ self.assert_(X.passed)
return lambda: x + 1
g = f(3)
- self.assertRaises(TypeError, eval, g.func_code)
+ self.assertRaises(TypeError, eval, g.__code__)
try:
- exec(g.func_code, {})
+ exec(g.__code__, {})
except TypeError:
pass
else:
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 21cba89..0678761 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -54,7 +54,7 @@ def with_warning_restore(func):
# Grrr, we need this function to warn every time. Without removing
# the warningregistry, running test_tarfile then test_struct would fail
# on 64-bit platforms.
- globals = func.func_globals
+ globals = func.__globals__
if '__warningregistry__' in globals:
del globals['__warningregistry__']
warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning)
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 8b5f73c..6fbb3cc 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -341,7 +341,7 @@ def run_with_locale(catstr, *locales):
finally:
if locale and orig_locale:
locale.setlocale(category, orig_locale)
- inner.func_name = func.func_name
+ inner.__name__ = func.__name__
inner.__doc__ = func.__doc__
return inner
return decorator
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 897c6b0..36cca2c 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -230,7 +230,7 @@ class SysModuleTest(unittest.TestCase):
self.assertRaises(TypeError, sys._getframe, 42, 42)
self.assertRaises(ValueError, sys._getframe, 2000000000)
self.assert_(
- SysModuleTest.test_getframe.im_func.func_code \
+ SysModuleTest.test_getframe.im_func.__code__ \
is sys._getframe().f_code
)
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 7b5ac7d..b1778dd 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -226,14 +226,14 @@ class TraceTestCase(unittest.TestCase):
sys.settrace(tracer.trace)
func()
sys.settrace(None)
- self.compare_events(func.func_code.co_firstlineno,
+ self.compare_events(func.__code__.co_firstlineno,
tracer.events, func.events)
def run_test2(self, func):
tracer = Tracer()
func(tracer.trace)
sys.settrace(None)
- self.compare_events(func.func_code.co_firstlineno,
+ self.compare_events(func.__code__.co_firstlineno,
tracer.events, func.events)
def test_01_basic(self):
@@ -313,7 +313,7 @@ class RaisingTraceFuncTestCase(unittest.TestCase):
def g(frame, why, extra):
if (why == 'line' and
- frame.f_lineno == f.func_code.co_firstlineno + 2):
+ frame.f_lineno == f.__code__.co_firstlineno + 2):
raise RuntimeError, "i am crashing"
return g
@@ -344,7 +344,7 @@ class JumpTracer:
self.done = False
def trace(self, frame, event, arg):
- if not self.done and frame.f_code == self.function.func_code:
+ if not self.done and frame.f_code == self.function.__code__:
firstLine = frame.f_code.co_firstlineno
if frame.f_lineno == firstLine + self.jumpFrom:
# Cope with non-integer self.jumpTo (because of
diff --git a/Lib/test/test_univnewlines.py b/Lib/test/test_univnewlines.py
index e91bde7..922c184 100644
--- a/Lib/test/test_univnewlines.py
+++ b/Lib/test/test_univnewlines.py
@@ -83,7 +83,7 @@ class TestGenericUnivNewlines(unittest.TestCase):
namespace = {}
execfile(test_support.TESTFN, namespace)
func = namespace['line3']
- self.assertEqual(func.func_code.co_firstlineno, 3)
+ self.assertEqual(func.__code__.co_firstlineno, 3)
self.assertEqual(namespace['line4'], FATX)
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index eb962d2..16c612e 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -295,7 +295,7 @@ class QuotingTests(unittest.TestCase):
def test_default_safe(self):
# Test '/' is default value for 'safe' parameter
- self.assertEqual(urllib.quote.func_defaults[0], '/')
+ self.assertEqual(urllib.quote.__defaults__[0], '/')
def test_safe(self):
# Test setting 'safe' parameter does what it should do