1996-12-23 19:39:42 -04:00
|
|
|
from test_support import verbose
|
1996-12-10 12:28:53 -04:00
|
|
|
import sys
|
|
|
|
import new
|
|
|
|
|
|
|
|
class Eggs:
|
|
|
|
def get_yolks(self):
|
|
|
|
return self.yolks
|
|
|
|
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'new.module()'
|
1996-12-10 12:28:53 -04:00
|
|
|
m = new.module('Spam')
|
1996-12-23 19:39:42 -04:00
|
|
|
if verbose:
|
|
|
|
print m
|
1996-12-10 12:28:53 -04:00
|
|
|
m.Eggs = Eggs
|
|
|
|
sys.modules['Spam'] = m
|
|
|
|
import Spam
|
|
|
|
|
|
|
|
def get_more_yolks(self):
|
|
|
|
return self.yolks + 3
|
|
|
|
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'new.classobj()'
|
1996-12-10 12:28:53 -04:00
|
|
|
C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
|
1996-12-23 19:39:42 -04:00
|
|
|
if verbose:
|
|
|
|
print C
|
|
|
|
print 'new.instance()'
|
1996-12-10 12:28:53 -04:00
|
|
|
c = new.instance(C, {'yolks': 3})
|
1996-12-23 19:39:42 -04:00
|
|
|
if verbose:
|
|
|
|
print c
|
1996-12-10 12:28:53 -04:00
|
|
|
|
|
|
|
def break_yolks(self):
|
|
|
|
self.yolks = self.yolks - 2
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'new.instancemethod()'
|
1996-12-10 12:28:53 -04:00
|
|
|
im = new.instancemethod(break_yolks, c, C)
|
1996-12-23 19:39:42 -04:00
|
|
|
if verbose:
|
|
|
|
print im
|
1996-12-10 12:28:53 -04:00
|
|
|
|
|
|
|
if c.get_yolks() <> 3 and c.get_more_yolks() <> 6:
|
|
|
|
print 'Broken call of hand-crafted class instance'
|
|
|
|
im()
|
|
|
|
if c.get_yolks() <> 1 and c.get_more_yolks() <> 4:
|
|
|
|
print 'Broken call of hand-crafted instance method'
|
|
|
|
|
|
|
|
codestr = '''
|
|
|
|
a = 1
|
|
|
|
b = 2
|
|
|
|
c = a + b
|
|
|
|
'''
|
|
|
|
|
|
|
|
ccode = compile(codestr, '<string>', 'exec')
|
|
|
|
g = {'c': 0, '__builtins__': __builtins__}
|
|
|
|
# this test could be more robust
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'new.function()'
|
1996-12-10 12:28:53 -04:00
|
|
|
func = new.function(ccode, g)
|
1996-12-23 19:39:42 -04:00
|
|
|
if verbose:
|
|
|
|
print func
|
1996-12-10 12:28:53 -04:00
|
|
|
func()
|
|
|
|
if g['c'] <> 3:
|
|
|
|
print 'Could not create a proper function object'
|
|
|
|
|
|
|
|
# bogus test of new.code()
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'new.code()'
|
1997-01-27 19:25:37 -04:00
|
|
|
d = new.code(3, 3, 3, 3, codestr, (), (), (), "<string>", "<name>", 1, "")
|
1996-12-23 19:39:42 -04:00
|
|
|
if verbose:
|
|
|
|
print d
|