forked from reflectometry/refl1d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·99 lines (77 loc) · 2.67 KB
/
test.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
"""
Run nose tests for Refl1D.
Usage:
./test.py
- run all tests
./test.py --with-coverage
- run all tests with coverage report
"""
import os, sys, subprocess
from glob import glob
import nose
from distutils.util import get_platform
platform = '.%s-%s'%(get_platform(),sys.version[:3])
# Make sure that we have a private version of mplconfig
mplconfig = os.path.join(os.getcwd(), '.mplconfig')
os.environ['MPLCONFIGDIR'] = mplconfig
if not os.path.exists(mplconfig): os.mkdir(mplconfig)
import matplotlib
matplotlib.use('Agg')
#print(matplotlib.__file__)
import pylab; pylab.hold(False)
def addpath(path):
"""
Add a directory to the python path environment, and to the PYTHONPATH
environment variable for subprocesses.
"""
path = os.path.abspath(path)
if 'PYTHONPATH' in os.environ:
PYTHONPATH = path + os.pathsep + os.environ['PYTHONPATH']
else:
PYTHONPATH = path
os.environ['PYTHONPATH'] = PYTHONPATH
sys.path.insert(0, path)
sys.dont_write_bytecode = True
sys.stderr = sys.stdout # Doctest doesn't see sys.stderr
#import numpy; numpy.seterr(all='raise')
# Check that we are running from the root.
root = os.path.abspath(os.getcwd())
assert os.path.exists(os.path.join(root, 'refl1d', 'abeles.py'))
# add bumps and periodictable to the path
try: import periodictable
except: addpath(os.path.join('..','periodictable'))
try: import bumps
except: addpath(os.path.join('..','bumps'))
# Force a rebuild
print("-"*70)
print("Building refl1d ...")
print("-"*70)
subprocess.call((sys.executable, "setup.py", "build"), shell=False)
print("-"*70)
# Add the build dir to the system path
build_path = os.path.join('build','lib'+platform)
addpath(build_path)
# Make sample data and models available
os.environ['REFL1D_DATA'] = os.path.join(root,'doc','examples')
# Set the nosetest args
nose_args = ['-v', '--all-modules',
'-m(^_?test_|_test$|^test$)',
'--with-doctest', '--doctest-extension=.rst',
'--doctest-options=+ELLIPSIS,+NORMALIZE_WHITESPACE',
'--cover-package=refl1d',
]
# exclude gui subdirectory if wx is not available
try: import wxversion
except: nose_args.append('-eview')
nose_args += sys.argv[1:] # allow coverage arguments
# Add targets
nose_args += [build_path, os.path.join('tests', 'refl1d')]
nose_args += glob('doc/g*/*.rst')
nose_args += glob('doc/examples/*/*.rst')
print("nosetests "+" ".join(nose_args))
if not nose.run(argv=nose_args): sys.exit(1)
## Run the command line version of Refl1D which should display help text.
#for p in ['bin/refl1d_cli.py']:
# ret = subprocess.call((sys.executable, p), shell=False)
# if ret != 0: sys.exit()