root/trunk/examples/inherit/test.py

Revision 100, 1.2 kB (checked in by KirkMcDonald, 2 years ago)

* Class wrapping API replaced.
* Inheritance "shim" classes now automatically generated.
* Requires DMD 1.005 or newer. Breaks GDC support for the moment.
* Docs not yet updated to reflect changes.
* Copyright notices updated to 2007.

Line 
1 import os.path, sys
2 import distutils.util
3
4 # Append the directory in which the binaries were placed to Python's sys.path,
5 # then import the D DLL.
6 libDir = os.path.join('build', 'lib.%s-%s' % (
7     distutils.util.get_platform(),
8     '.'.join(str(v) for v in sys.version_info[:2])
9 ))
10 sys.path.append(os.path.abspath(libDir))
11
12 import inherit
13
14 b = inherit.Base(1)
15 d = inherit.Derived(2)
16
17 b.foo()
18 b.bar()
19 d.foo()
20 d.bar()
21
22 print "issubclass(inherit.Derived, inherit.Base)"
23 print issubclass(inherit.Derived, inherit.Base)
24
25 inherit.call_poly(b)
26 inherit.call_poly(d)
27
28 #w = inherit.WrapDerive()
29 #inherit.call_poly(w)
30
31 class PyClass(inherit.Derived):
32     def foo(self):
33         print 'PyClass.foo'
34
35 p = PyClass(3)
36 #print "The basic inheritance support breaks down here:"
37 inherit.call_poly(p)
38
39 print
40
41 b1 = inherit.return_poly_base()
42 print "inherit.return_poly_base returned instance of Base"
43 b1.foo()
44 b1.bar()
45 #assert type(b1) == inherit.Base
46 b2 = inherit.return_poly_derived()
47 b2a = inherit.return_poly_derived()
48 print "inherit.return_poly_derived returned instance of Derived"
49 #assert type(b2) == inherit.Derived
50 print "inherit.return_poly_derived returned the same object twice"
51 assert b2 is b2a
52
53 print
54 print '-------'
55 print 'SUCCESS'
56 print '-------'
Note: See TracBrowser for help on using the browser.