File: runme.py

package info (click to toggle)
swig1.3 1.3.24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,336 kB
  • ctags: 10,604
  • sloc: cpp: 27,917; ansic: 24,160; yacc: 4,412; python: 4,255; java: 4,156; makefile: 3,735; sh: 3,552; cs: 2,250; ruby: 2,150; lisp: 1,605; tcl: 1,136; perl: 980; php: 879; ml: 825
file content (72 lines) | stat: -rw-r--r-- 1,786 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Test weave support for SWIG wrapped objects.

This example requires that one has weave installed.  Weave is
distributed as part of SciPy (http://www.scipy.org).  More information
on Weave may be had from here:

 http://www.scipy.org/documentation/weave

As of November 22, 2004, this only works with weave from CVS.  If
there is a more recent release of SciPy after this date, it should
work fine.

"""

import example
import weave
from weave import converters
from weave import swig2_spec

# Weave does not support swig2 by default (yet).  So add this to the
# list of default converters to test.
converters.default.insert(0, swig2_spec.swig2_converter())

def test():
    """ A simple test case for weave."""
    a = example.Foo()
    a.x = 1
    b = example.Bar()
    b.y = 2
    c = example.FooBar()
    c.x = 1
    c.y = 2
    c.z = 3
    v = example.VectorBar()
    v.append(b)
    v.append(c)
    d = v[0]
    e = v[1]
    v = example.VectorFoo()
    v.append(a)
    v.append(c)
    f = v[0]
    g = v[1]
    
    code = """
    std::cout << a->x << std::endl;
    assert(a->x == 1);
    std::cout << b->y << std::endl;
    assert(b->y == 2);
    std::cout << c->x << std::endl;
    std::cout << c->y << std::endl;
    std::cout << c->z << std::endl;
    assert(c->x == 1);
    assert(c->y == 2);
    assert(c->z == 3);
    std::cout << d->y << std::endl;
    assert(d->y == 2);
    std::cout << e->y << std::endl;
    assert(e->y == 2);
    std::cout << f->x << std::endl;
    assert(f->x == 1);
    std::cout << g->x << std::endl;
    assert(g->x == 1);
    """
    weave.inline(code, ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
                 include_dirs=['.'], 
                 headers=['"example.h"'],
                 verbose=2)
    
if __name__ == "__main__":
    test()