/tags/rel-1-3-25/SWIG/Examples/python/weave/runme.py
Python | 72 lines | 51 code | 4 blank | 17 comment | 0 complexity | 0adf3761a3df8c00aabbc94caaa0b572 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1""" 2Test weave support for SWIG wrapped objects. 3 4This example requires that one has weave installed. Weave is 5distributed as part of SciPy (http://www.scipy.org). More information 6on Weave may be had from here: 7 8 http://www.scipy.org/documentation/weave 9 10As of November 22, 2004, this only works with weave from CVS. If 11there is a more recent release of SciPy after this date, it should 12work fine. 13 14""" 15 16import example 17import weave 18from weave import converters 19from 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. 23converters.default.insert(0, swig2_spec.swig2_converter()) 24 25def 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 71if __name__ == "__main__": 72 test()