import source from 1.3.40
[external/swig.git] / Examples / python / weave / runme.py
1 """
2 Test weave support for SWIG wrapped objects.
3
4 This example requires that one has weave installed.  Weave is
5 distributed as part of SciPy (http://www.scipy.org).  More information
6 on Weave may be had from here:
7
8  http://www.scipy.org/documentation/weave
9
10 As of November 22, 2004, this only works with weave from CVS.  If
11 there is a more recent release of SciPy after this date, it should
12 work fine.
13
14 """
15
16 import example
17 import weave
18 from weave import converters
19 from weave import swig2_spec
20
21 # Weave does not support swig2 by default (yet).  So add this to the
22 # list of default converters to test.
23 converters.default.insert(0, swig2_spec.swig2_converter())
24
25 def test():
26     """ A simple test case for weave."""
27     a = example.Foo()
28     a.x = 1
29     b = example.Bar()
30     b.y = 2
31     c = example.FooBar()
32     c.x = 1
33     c.y = 2
34     c.z = 3
35     v = example.VectorBar()
36     v.append(b)
37     v.append(c)
38     d = v[0]
39     e = v[1]
40     v = example.VectorFoo()
41     v.append(a)
42     v.append(c)
43     f = v[0]
44     g = v[1]
45     
46     code = """
47     std::cout << a->x << std::endl;
48     assert(a->x == 1);
49     std::cout << b->y << std::endl;
50     assert(b->y == 2);
51     std::cout << c->x << std::endl;
52     std::cout << c->y << std::endl;
53     std::cout << c->z << std::endl;
54     assert(c->x == 1);
55     assert(c->y == 2);
56     assert(c->z == 3);
57     std::cout << d->y << std::endl;
58     assert(d->y == 2);
59     std::cout << e->y << std::endl;
60     assert(e->y == 2);
61     std::cout << f->x << std::endl;
62     assert(f->x == 1);
63     std::cout << g->x << std::endl;
64     assert(g->x == 1);
65     """
66     weave.inline(code, ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
67                  include_dirs=['.'], 
68                  headers=['"example.h"'],
69                  verbose=2)
70     
71 if __name__ == "__main__":
72     test()