Skip to content

Commit dfb9daf

Browse files
author
joeljonsson
committed
added search for module to pythonTest
1 parent 16a81d8 commit dfb9daf

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

test/pythonTest.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
import os, sys
33
myPath = os.path.dirname(os.path.abspath(__file__))
44

5-
# Add path to build APR pythond module
6-
sys.path.insert(0, "../cmake-build-release")
5+
# Add path to location of the python APR module (your build folder)
6+
#sys.path.insert(0, "../cmake-build-release")
77

88
# Check if APR can be read and if gives correct dimensions
9-
import pyApr
9+
#import pyApr
1010
import numpy as np
11+
import fnmatch
1112

1213

1314
def main():
15+
"""
16+
If you get ImportErrors, or if you have more than one build containing a file pyApr.so, you may want to
17+
manually supply the path by changing the block below to
18+
sys.path.insert(0, '/path/to/dir/containing/module/')
19+
"""
20+
# -------------------------------------------------- #
21+
print("Searching for pyApr module...")
22+
basePath = os.path.join(myPath, os.pardir)
23+
for root, dirnames, filenames in os.walk(basePath):
24+
if fnmatch.filter(filenames, 'pyApr.so'):
25+
sys.path.insert(0, root)
26+
print('pyApr module found in {}'.format(root))
27+
# -------------------------------------------------- #
28+
29+
import pyApr
1430

1531
successes = 0
1632

@@ -34,26 +50,37 @@ def main():
3450

3551
print("Testing read APR...")
3652
try:
53+
apr = pyApr.AprShort()
3754
apr.read_apr( os.path.join(myPath, 'files/Apr/sphere_120/sphere_apr.h5') )
3855
successes += 1
3956
print("success!")
4057
except:
4158
print("**** failed ****")
4259

60+
4361
print("Testing write APR...")
4462
try:
4563
outpath = os.path.join(myPath, 'writeaprtest')
46-
apr.write_apr(outpath)
64+
65+
if apr:
66+
apr.write_apr(outpath)
67+
else:
68+
apr = pyApr.AprShort()
69+
apr.write_apr(outpath)
70+
4771
successes += 1
4872
print("success!")
4973

5074
outpath = os.path.join(myPath, 'writeaprtest_apr.h5')
5175
if os.path.exists(outpath):
76+
print('removing temporarily created APR file')
5277
os.remove(outpath)
53-
#print('{} found'.format(outpath))
78+
else:
79+
print('could not find temporarily created APR file for removal')
5480
except:
5581
print("**** failed ****")
5682

83+
5784
print("Testing piecewise constant pixel image reconstruction...")
5885
try:
5986
img = np.array(apr.reconstruct(), copy=False)
@@ -63,6 +90,7 @@ def main():
6390
except:
6491
print("**** failed ****")
6592

93+
6694
print("Testing smooth pixel image reconstruction...")
6795
try:
6896
img = np.array(apr.reconstruct_smooth(), copy=False)
@@ -72,8 +100,12 @@ def main():
72100
except:
73101
print("**** failed ****")
74102

103+
75104
print("Testing set APRParameters...")
76105
try:
106+
if not pars:
107+
pars = pyApr.APRParameters()
108+
77109
pars.Ip_th = 0
78110
pars.sigma_th = 0
79111
pars.sigma_th_max = 0

0 commit comments

Comments
 (0)