Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_new.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 7f6d19fc5aca |
| children | aedd2d0dcb31 |
| rev | line source |
|---|---|
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
1 from test_support import verbose |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
2 import sys |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
3 import new |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
4 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
5 class Eggs: |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
6 def get_yolks(self): |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
7 return self.yolks |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
8 |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
9 print 'new.module()' |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
10 m = new.module('Spam') |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
11 if verbose: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
12 print m |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
13 m.Eggs = Eggs |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
14 sys.modules['Spam'] = m |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
15 import Spam |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
16 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
17 def get_more_yolks(self): |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
18 return self.yolks + 3 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
19 |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
20 print 'new.classobj()' |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
21 C = new.classobj('Spam', (Spam.Eggs,), {'get_more_yolks': get_more_yolks}) |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
22 if verbose: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
23 print C |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
24 print 'new.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
|
25 c = new.instance(C, {'yolks': 3}) |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
26 if verbose: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
27 print 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
|
28 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
29 def break_yolks(self): |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
30 self.yolks = self.yolks - 2 |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
31 print 'new.instancemethod()' |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
32 im = new.instancemethod(break_yolks, c, C) |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
33 if verbose: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
34 print im |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
35 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
36 if c.get_yolks() <> 3 and c.get_more_yolks() <> 6: |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
37 print 'Broken call of hand-crafted class instance' |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
38 im() |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
39 if c.get_yolks() <> 1 and c.get_more_yolks() <> 4: |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
40 print 'Broken call of hand-crafted instance method' |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
41 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
42 codestr = ''' |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
43 a = 1 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
44 b = 2 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
45 c = a + b |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
46 ''' |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
47 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
48 ccode = compile(codestr, '<string>', 'exec') |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
49 g = {'c': 0, '__builtins__': __builtins__} |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
50 # this test could be more robust |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
51 print 'new.function()' |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
52 func = new.function(ccode, g) |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
53 if verbose: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
54 print func |
|
4663
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
55 func() |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
56 if g['c'] <> 3: |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
57 print 'Could not create a proper function object' |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
58 |
|
4ee4b8bb67c7
A test of the `new' module. The new.code() test is fairly bogus since
Barry Warsaw <barry@python.org>
parents:
diff
changeset
|
59 # bogus test of new.code() |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
60 print 'new.code()' |
|
5051
7f6d19fc5aca
new.code() has grown another foot, eh, another two arguments.
Guido van Rossum <guido@python.org>
parents:
4997
diff
changeset
|
61 d = new.code(3, 3, 3, 3, codestr, (), (), (), "<string>", "<name>", 1, "") |
|
4825
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
62 if verbose: |
|
b8a97ad5f7ce
test_rotor.py: New test of the rotor module.
Barry Warsaw <barry@python.org>
parents:
4663
diff
changeset
|
63 print d |
