PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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