source: tags/ms_r18q1/BINDINGS/PYTHON/test.py

Last change on this file was 8848, checked in by epruesse, 12 years ago

Added Python bindings using SWIG

Build and clean targets are "bindings" and "bindings_clean"; they
are not added to all and clean yet. The "test.py" shows a bit of
the python usage of the interface. You need to have swig installed,
of course.

The bindings are not build from arb_prot.h like the perl bindings.
Rather, ARB.i defines the exported functions. This is to make the
interface smaller and have an avenue of keeping it stable in case
the library interface needs to be changed. It also cuts down on
compile time a lot.

The idea is to eventually build the perl bindings with SWIG as well.
I haven't figured out how to provide the BIO:: module with the
ARB module yet, though, which would be required for backwards
compatability with pre-existing amc scripts.

  • Property svn:executable set to *
File size: 1.1 KB
Line 
1#!/usr/bin/env python
2
3# load ARB and os libraries
4import ARB,os,sys
5
6OK = "OK"
7FAIL = "FAIL"
8
9##
10# define testcases
11##
12
13def open_nonexistant():
14  """try opening nonexistant db"""
15  err = FAIL
16  try:
17    arbdb = ARB.open("doesnotexist.arb","r")
18  except Exception as e:
19    err = OK
20  print "Exception on attempt to open noexistant DB: " + err
21  return err == OK
22
23def count_spec_in_demo_arb():
24  err = OK
25  # open the demo database
26  try:
27    arbdb = ARB.open(os.environ["ARBHOME"] + "/demo.arb","r")
28  except Exception as e:
29    err = FAIL
30  print "Opening demo.arb: " + err
31  if (err != OK): return False
32
33  # iterate through species and count
34  num = 0
35  err = OK
36  for species in arbdb.all_species():
37    num+=1
38  if (num != 100):
39    err = FAIL
40  print "Counting species (expecting 100): " + err
41  return err == OK
42
43  arbdb.close()
44
45##
46# run tests
47##
48
49print "Testing ARB-Python interface:"
50err = False
51err = err or not open_nonexistant()
52err = err or not count_spec_in_demo_arb()
53
54if (err == True):
55  print "Some tests failed!"
56  sys.exit(1)
57else:
58  print "All tests completed successfully. :)"
59   
Note: See TracBrowser for help on using the repository browser.