Skip to content

Commit d67c037

Browse files
committed
Make testing work properly from py.test and ipython
1 parent de1fa1a commit d67c037

15 files changed

+38
-109
lines changed

NOTES

-6
This file was deleted.

NOTES.test

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
For any environment (include a dev ska). This also works in the source directory::
2+
3+
python
4+
import os
5+
os.environ['ENG_ARCHIVE'] = '/proj/sot/ska/data/eng_archive'
6+
import xija
7+
xija.test()
8+
9+
From the command line one can also do::
10+
11+
$ py.test [-v] xija

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
norecursedirs = .* alt_core build ctypes_example dist doc examples GUI_play ipynb models* nmass* pyside tests_no_pytest tmp twodof www

test3.py

-50
This file was deleted.

test_tmal.py

-8
This file was deleted.

test_tmal2.py

-20
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

xija/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from .files import files
44
from .version import version as __version__
55

6+
67
def test(*args, **kwargs):
78
"""Run self tests"""
8-
from . import tests
9-
tests.test(*args, **kwargs)
9+
import os
10+
import pytest
11+
os.chdir(os.path.join(os.path.dirname(__file__), '..'))
12+
pytest.main(args=['xija'] + list(args))

xija/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _get_cmd_states(self):
178178
self.datestart, self.datestop, dbi=dbi)
179179
break
180180
except IOError as err:
181-
logger.info('Warning: ' + err)
181+
logger.info('Warning: ' + str(err))
182182
pass
183183
else:
184184
# Both hdf5 and sybase failed

xija/tests/__init__.py

-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
"""
2-
Run self-tests
3-
"""
4-
5-
def test(*args, **kwargs):
6-
import os
7-
import pytest
8-
os.chdir(os.path.dirname(__file__))
9-
pytest.main(*args, **kwargs)

xija/tests/test_models.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
import numpy as np
44
import pytest
55

6-
from .. import ThermalModel, Node, HeatSink, SolarHeat, Pitch, Eclipse, __version__
6+
from xija import ThermalModel, Node, HeatSink, SolarHeat, Pitch, Eclipse, __version__
77
from numpy import sin, cos, abs
88

99
print
1010
print 'Version =', __version__
1111

12-
os.chdir(os.path.abspath(os.path.dirname(__file__)))
12+
CURRDIR = os.path.abspath(os.path.dirname(__file__))
13+
14+
15+
def abs_path(spec):
16+
return os.path.join(CURRDIR, spec)
1317

1418

1519
def test_dpa_real():
1620
mdl = ThermalModel('dpa', start='2012:001', stop='2012:007',
17-
model_spec='dpa.json')
21+
model_spec=abs_path('dpa.json'))
1822
# Check that cmd_states database can be read. Skip if not, probably
1923
# running test on a platform without access.
2024
try:
@@ -26,7 +30,7 @@ def test_dpa_real():
2630
mdl.make()
2731
mdl.calc()
2832
dpa = mdl.comp['1dpamzt']
29-
reffile = 'dpa_real.npz'
33+
reffile = abs_path('dpa_real.npz')
3034
if not os.path.exists(reffile):
3135
print 'Writing reference file', reffile
3236
np.savez(reffile, times=mdl.times, dvals=dpa.dvals,
@@ -45,7 +49,7 @@ def test_pitch_clip():
4549
Make sure the model still runs with no interpolation error.
4650
"""
4751
mdl = ThermalModel('dpa', start='2012:001', stop='2012:007',
48-
model_spec='dpa_clip.json')
52+
model_spec=abs_path('dpa_clip.json'))
4953
try:
5054
mdl._get_cmd_states()
5155
except:
@@ -58,7 +62,7 @@ def test_pitch_clip():
5862

5963
def test_dpa():
6064
mdl = ThermalModel('dpa', start='2012:001', stop='2012:007',
61-
model_spec='dpa.json')
65+
model_spec=abs_path('dpa.json'))
6266
times = (mdl.times - mdl.times[0]) / 10000.0
6367
mdl.comp['1dpamzt'].set_data(30.0)
6468
mdl.comp['sim_z'].set_data((100000 * sin(times)).astype(int))
@@ -77,20 +81,22 @@ def test_dpa():
7781
mdl.make()
7882
mdl.calc()
7983
dpa = mdl.comp['1dpamzt']
80-
if not os.path.exists('dpa.npz'):
84+
reffile = abs_path('dpa.npz')
85+
if not os.path.exists(reffile):
8186
print 'Writing reference file dpa.npz'
82-
np.savez('dpa.npz', times=mdl.times, dvals=dpa.dvals,
87+
np.savez(reffile, times=mdl.times, dvals=dpa.dvals,
8388
mvals=dpa.mvals)
8489

85-
regr = np.load('dpa.npz')
90+
regr = np.load(reffile)
8691
assert np.allclose(mdl.times, regr['times'])
8792
assert np.allclose(dpa.dvals, regr['dvals'])
8893
assert np.allclose(dpa.mvals, regr['mvals'])
8994

9095

9196
def test_data_types():
9297
for data_type in (int, float, np.float32, np.float64, np.int32, np.int64, np.complex64):
93-
mdl = ThermalModel('dpa', start='2012:001', stop='2012:007', model_spec='dpa.json')
98+
mdl = ThermalModel('dpa', start='2012:001', stop='2012:007',
99+
model_spec=abs_path('dpa.json'))
94100
dpa = mdl.comp['1dpamzt']
95101
dpa.set_data(data_type(30.0))
96102
if data_type is np.complex64:
@@ -102,7 +108,7 @@ def test_data_types():
102108

103109
def test_minusz():
104110
mdl = ThermalModel('minusz', start='2012:001', stop='2012:004',
105-
model_spec='minusz.json')
111+
model_spec=abs_path('minusz.json'))
106112
times = (mdl.times - mdl.times[0]) / 10000.0
107113
msids = ('tephin', 'tcylaft6', 'tcylfmzm', 'tmzp_my', 'tfssbkt1')
108114
for msid in msids:
@@ -127,7 +133,7 @@ def test_minusz():
127133

128134
def test_pftank2t():
129135
mdl = ThermalModel('pftank2t', start='2012:001', stop='2012:004',
130-
model_spec='pftank2t.json')
136+
model_spec=abs_path('pftank2t.json'))
131137
times = (mdl.times - mdl.times[0]) / 10000.0
132138
msids = ('pftank2t', 'pf0tank2t')
133139
for msid in msids:
@@ -138,7 +144,7 @@ def test_pftank2t():
138144
mdl.make()
139145
mdl.calc()
140146

141-
regrfile = 'pftank2t.npz'
147+
regrfile = abs_path('pftank2t.npz')
142148
if not os.path.exists(regrfile):
143149
print 'Writing reference file', regrfile
144150
kwargs = {msid: mdl.comp[msid].mvals for msid in msids}

0 commit comments

Comments
 (0)