blob: 89edafdd1903214fb57f618dc0863067c7406993 [file] [log] [blame]
Barry Warsaw924e5d51996-12-10 16:28:53 +00001import sys
2import new
3
4class Eggs:
5 def get_yolks(self):
6 return self.yolks
7
8m = new.module('Spam')
9m.Eggs = Eggs
10sys.modules['Spam'] = m
11import Spam
12
13def get_more_yolks(self):
14 return self.yolks + 3
15
16C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks})
17c = new.instance(C, {'yolks': 3})
18
19def break_yolks(self):
20 self.yolks = self.yolks - 2
21im = new.instancemethod(break_yolks, c, C)
22
23if c.get_yolks() <> 3 and c.get_more_yolks() <> 6:
24 print 'Broken call of hand-crafted class instance'
25im()
26if c.get_yolks() <> 1 and c.get_more_yolks() <> 4:
27 print 'Broken call of hand-crafted instance method'
28
29codestr = '''
30a = 1
31b = 2
32c = a + b
33'''
34
35ccode = compile(codestr, '<string>', 'exec')
36g = {'c': 0, '__builtins__': __builtins__}
37# this test could be more robust
38func = new.function(ccode, g)
39func()
40if g['c'] <> 3:
41 print 'Could not create a proper function object'
42
43# bogus test of new.code()
44new.code(3, 3, 3, codestr, (), (), (), "<string>", "<name>")