LALInference  4.1.6.1-fe68b98
SWIGTestLALInferencePython.py
Go to the documentation of this file.
1 # Check SWIG Python bindings for LALInference
2 # Author: Karl Wette, 2011--2014
3 
4 import os
5 import sys
6 import inspect
7 import gc
8 
9 import pytest
10 
11 # check module load
12 print("checking module load ...", file=sys.stderr)
13 import lal
14 import lalinference
15 from lalinference import globalvar as lalinferenceglobalvar
16 from lal import globalvar as lalglobalvar
17 
18 print("PASSED module load", file=sys.stderr)
19 
20 
21 # -- configure error handling
22 
23 # set error handlers
25  lal.swig_set_nice_error_handlers()
26 
27 
29  if "NASTY_ERROR_HANDLERS" in os.environ:
30  lal.swig_set_nasty_error_handlers()
31  else:
32  lal.swig_set_nice_error_handlers()
33 
34 
36 
37 
38 # -- check for memory leaks
39 
40 
42  # pytest's rewrite of assert() can keep references
43  # to SWIGLAL objects around; find and clear them
44  frame = inspect.currentframe()
45  try:
46  for v in frame.f_back.f_locals:
47  if v.startswith("@py_assert"):
48  frame.f_back.f_locals[v] = None
49  finally:
50  del frame
51 
52  # garbage collector should free all SWIGLAL objects
53  gc.collect()
54 
55  # check that all LAL memory has been freed
56  lal.CheckMemoryLeaks()
57 
58 
59 # -- tests
60 
61 
63  """check object parent tracking"""
64 
65  print("checking object parent tracking ...", file=sys.stderr)
66  a = lalinference.swig_lalinference_test_parent_map_struct()
67  for i in range(0, 7):
68  b = a.s
69  c = lalinferenceglobalvar.swig_lalinference_test_parent_map.s
70  lalinferenceglobalvar.swig_lalinference_test_parent_map.s = (
71  lalglobalvar.swig_lal_test_struct_const
72  )
73  del c
74  del b
75  del a
77  print("PASSED object parent tracking", file=sys.stderr)
78 
79 
80 if __name__ == "__main__":
81  args = sys.argv[1:] or [
82  "-v",
83  "-rs",
84  "--junit-xml=junit-SWIGTestLALInferencePython.xml",
85  ]
86  sys.exit(pytest.main(args=[__file__] + args))
def test_object_parent_tracking()
check object parent tracking