Added machinery for running Python unit tests
This commit is contained in:
parent
9d0d2ae7ef
commit
b0ccecf4e4
6 changed files with 378 additions and 6 deletions
|
|
@ -116,6 +116,11 @@ env = Environment(tools=toolchain+['textfile', 'subst', 'recursiveInstall', 'wix
|
|||
if os.name == 'nt' and 'TMP' in os.environ:
|
||||
env['ENV']['TMP'] = os.environ['TMP']
|
||||
|
||||
# Fix an issue with Unicode sneaking into the environment on Windows
|
||||
if os.name == 'nt':
|
||||
for key,val in env['ENV'].iteritems():
|
||||
env['ENV'][key] = str(val)
|
||||
|
||||
add_RegressionTest(env)
|
||||
|
||||
class defaults: pass
|
||||
|
|
|
|||
|
|
@ -8,21 +8,57 @@ localenv.Append(CPPPATH=['#ext/gtest/include', '#include'],
|
|||
LIBPATH='#build/lib',
|
||||
LIBS=['gtest'] + localenv['cantera_libs'])
|
||||
|
||||
def gtestRunner(target, source, env):
|
||||
localenv['ENV']['PYTHONPATH'] = Dir('#interfaces/python').abspath
|
||||
localenv['ENV']['CANTERA_DATA'] = Dir('#data/inputs').abspath
|
||||
|
||||
def testRunner(target, source, env):
|
||||
"""SCons Action to run a compiled test program"""
|
||||
program = source[0]
|
||||
code = subprocess.call([program.abspath])
|
||||
code = subprocess.call([program.abspath], env=env['ENV'])
|
||||
if not code:
|
||||
open(target[0].path, 'w').write(time.asctime()+'\n')
|
||||
return 0
|
||||
return code
|
||||
|
||||
def addTest(subdir, progName):
|
||||
|
||||
def scriptRunner(target, source, env):
|
||||
"""Scons Action to run a test script using the specified interpreter"""
|
||||
interpreter = env['test_interpreter']
|
||||
code = subprocess.call([interpreter, str(source[0])],
|
||||
env=env['ENV'])
|
||||
if not code:
|
||||
open(target[0].path, 'w').write(time.asctime()+'\n')
|
||||
return code
|
||||
|
||||
|
||||
def addTestProgram(subdir, progName):
|
||||
"""
|
||||
Compile a test program and create a targets for running
|
||||
and resetting the test.
|
||||
"""
|
||||
program = localenv.Program(pjoin(subdir, progName),
|
||||
pjoin(subdir, '%s.cpp' % progName))
|
||||
passedFile = File(pjoin(str(program[0].dir), '%s.passed' % program[0].name))
|
||||
run_program = localenv.Command(passedFile, program, gtestRunner)
|
||||
run_program = localenv.Command(passedFile, program, testRunner)
|
||||
Alias('newtest', run_program)
|
||||
if os.path.exists(passedFile.abspath):
|
||||
Alias('newtest-reset', localenv.Command('reset-%s%s' % (subdir, progName),
|
||||
[], [Delete(passedFile.abspath)]))
|
||||
|
||||
addTest('thermo', 'nasapoly')
|
||||
|
||||
def addTestScript(subdir, script, interpreter):
|
||||
"""
|
||||
Create targets for running and resetting a test script.
|
||||
"""
|
||||
testenv = localenv.Clone()
|
||||
testenv['test_interpreter'] = interpreter
|
||||
passedFile = File(pjoin(subdir, '%s.passed' % (script)))
|
||||
run_program = testenv.Command(passedFile, pjoin(subdir, script), scriptRunner)
|
||||
Alias('newtest', run_program)
|
||||
if os.path.exists(passedFile.abspath):
|
||||
Alias('newtest-reset', testenv.Command('reset-%s%s' % (subdir, script),
|
||||
[], [Delete(passedFile.abspath)]))
|
||||
|
||||
|
||||
# Instantiate tests
|
||||
addTestProgram('thermo', 'nasapoly')
|
||||
addTestScript('python', 'runTests.py', interpreter=sys.executable)
|
||||
|
|
|
|||
123
test/data/air-no-reactions.cti
Normal file
123
test/data/air-no-reactions.cti
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
units(length = "cm", time = "s", quantity = "mol", act_energy = "cal/mol")
|
||||
|
||||
ideal_gas(name = "air",
|
||||
elements = " O N Ar ",
|
||||
species = """ O O2 N NO NO2 N2O N2 AR """,
|
||||
initial_state = state(temperature = 300.0,
|
||||
pressure = OneAtm,
|
||||
mole_fractions = 'O2:0.21, N2:0.78, AR:0.01') )
|
||||
|
||||
ideal_gas(name = "notair",
|
||||
elements = " O N ",
|
||||
species = """ O O2 N NO NO2 N2O N2 """,
|
||||
initial_state = state(temperature = 900.0,
|
||||
pressure = 5*OneAtm,
|
||||
mass_fractions = 'O2:0.5, N2:0.5') )
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Species data
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
species(name = "O",
|
||||
atoms = " O:1 ",
|
||||
thermo = (
|
||||
NASA( [ 200.00, 1000.00], [ 3.168267100E+00, -3.279318840E-03,
|
||||
6.643063960E-06, -6.128066240E-09, 2.112659710E-12,
|
||||
2.912225920E+04, 2.051933460E+00] ),
|
||||
NASA( [ 1000.00, 3500.00], [ 2.569420780E+00, -8.597411370E-05,
|
||||
4.194845890E-08, -1.001777990E-11, 1.228336910E-15,
|
||||
2.921757910E+04, 4.784338640E+00] )
|
||||
),
|
||||
note = "L 1/90"
|
||||
)
|
||||
|
||||
species(name = "O2",
|
||||
atoms = " O:2 ",
|
||||
thermo = (
|
||||
NASA( [ 200.00, 1000.00], [ 3.782456360E+00, -2.996734160E-03,
|
||||
9.847302010E-06, -9.681295090E-09, 3.243728370E-12,
|
||||
-1.063943560E+03, 3.657675730E+00] ),
|
||||
NASA( [ 1000.00, 3500.00], [ 3.282537840E+00, 1.483087540E-03,
|
||||
-7.579666690E-07, 2.094705550E-10, -2.167177940E-14,
|
||||
-1.088457720E+03, 5.453231290E+00] )
|
||||
),
|
||||
note = "TPIS89"
|
||||
)
|
||||
|
||||
species(name = "N",
|
||||
atoms = " N:1 ",
|
||||
thermo = (
|
||||
NASA( [ 200.00, 1000.00], [ 2.500000000E+00, 0.000000000E+00,
|
||||
0.000000000E+00, 0.000000000E+00, 0.000000000E+00,
|
||||
5.610463700E+04, 4.193908700E+00] ),
|
||||
NASA( [ 1000.00, 6000.00], [ 2.415942900E+00, 1.748906500E-04,
|
||||
-1.190236900E-07, 3.022624500E-11, -2.036098200E-15,
|
||||
5.613377300E+04, 4.649609600E+00] )
|
||||
),
|
||||
note = "L 6/88"
|
||||
)
|
||||
|
||||
species(name = "NO",
|
||||
atoms = " N:1 O:1 ",
|
||||
thermo = (
|
||||
NASA( [ 200.00, 1000.00], [ 4.218476300E+00, -4.638976000E-03,
|
||||
1.104102200E-05, -9.336135400E-09, 2.803577000E-12,
|
||||
9.844623000E+03, 2.280846400E+00] ),
|
||||
NASA( [ 1000.00, 6000.00], [ 3.260605600E+00, 1.191104300E-03,
|
||||
-4.291704800E-07, 6.945766900E-11, -4.033609900E-15,
|
||||
9.920974600E+03, 6.369302700E+00] )
|
||||
),
|
||||
note = "RUS 78"
|
||||
)
|
||||
|
||||
species(name = "NO2",
|
||||
atoms = " N:1 O:2 ",
|
||||
thermo = (
|
||||
NASA( [ 200.00, 1000.00], [ 3.944031200E+00, -1.585429000E-03,
|
||||
1.665781200E-05, -2.047542600E-08, 7.835056400E-12,
|
||||
2.896617900E+03, 6.311991700E+00] ),
|
||||
NASA( [ 1000.00, 6000.00], [ 4.884754200E+00, 2.172395600E-03,
|
||||
-8.280690600E-07, 1.574751000E-10, -1.051089500E-14,
|
||||
2.316498300E+03, -1.174169500E-01] )
|
||||
),
|
||||
note = "L 7/88"
|
||||
)
|
||||
|
||||
species(name = "N2O",
|
||||
atoms = " N:2 O:1 ",
|
||||
thermo = (
|
||||
NASA( [ 200.00, 1000.00], [ 2.257150200E+00, 1.130472800E-02,
|
||||
-1.367131900E-05, 9.681980600E-09, -2.930718200E-12,
|
||||
8.741774400E+03, 1.075799200E+01] ),
|
||||
NASA( [ 1000.00, 6000.00], [ 4.823072900E+00, 2.627025100E-03,
|
||||
-9.585087400E-07, 1.600071200E-10, -9.775230300E-15,
|
||||
8.073404800E+03, -2.201720700E+00] )
|
||||
),
|
||||
note = "L 7/88"
|
||||
)
|
||||
|
||||
species(name = "N2",
|
||||
atoms = " N:2 ",
|
||||
thermo = (
|
||||
NASA( [ 300.00, 1000.00], [ 3.298677000E+00, 1.408240400E-03,
|
||||
-3.963222000E-06, 5.641515000E-09, -2.444854000E-12,
|
||||
-1.020899900E+03, 3.950372000E+00] ),
|
||||
NASA( [ 1000.00, 5000.00], [ 2.926640000E+00, 1.487976800E-03,
|
||||
-5.684760000E-07, 1.009703800E-10, -6.753351000E-15,
|
||||
-9.227977000E+02, 5.980528000E+00] )
|
||||
),
|
||||
note = "121286"
|
||||
)
|
||||
|
||||
species(name = "AR",
|
||||
atoms = " Ar:1 ",
|
||||
thermo = (
|
||||
NASA( [ 300.00, 1000.00], [ 2.500000000E+00, 0.000000000E+00,
|
||||
0.000000000E+00, 0.000000000E+00, 0.000000000E+00,
|
||||
-7.453750000E+02, 4.366000000E+00] ),
|
||||
NASA( [ 1000.00, 5000.00], [ 2.500000000E+00, 0.000000000E+00,
|
||||
0.000000000E+00, 0.000000000E+00, 0.000000000E+00,
|
||||
-7.453750000E+02, 4.366000000E+00] )
|
||||
),
|
||||
note = "120186"
|
||||
)
|
||||
181
test/data/air-no-reactions.xml
Normal file
181
test/data/air-no-reactions.xml
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
<?xml version="1.0"?>
|
||||
<ctml>
|
||||
<validate reactions="yes" species="yes"/>
|
||||
|
||||
<!-- phase air -->
|
||||
<phase dim="3" id="air">
|
||||
<elementArray datasrc="elements.xml">O N Ar </elementArray>
|
||||
<speciesArray datasrc="#species_data">O O2 N NO NO2 N2O N2 AR </speciesArray>
|
||||
<state>
|
||||
<temperature units="K">300.0</temperature>
|
||||
<pressure units="Pa">101325.0</pressure>
|
||||
<moleFractions>O2:0.21, N2:0.78, AR:0.01</moleFractions>
|
||||
</state>
|
||||
<thermo model="IdealGas"/>
|
||||
<kinetics model="GasKinetics"/>
|
||||
<transport model="None"/>
|
||||
</phase>
|
||||
|
||||
<!-- phase notair -->
|
||||
<phase dim="3" id="notair">
|
||||
<elementArray datasrc="elements.xml">O N </elementArray>
|
||||
<speciesArray datasrc="#species_data">O O2 N NO NO2 N2O N2 </speciesArray>
|
||||
<state>
|
||||
<temperature units="K">900.0</temperature>
|
||||
<pressure units="Pa">506625.0</pressure>
|
||||
<massFractions>O2:0.5, N2:0.5</massFractions>
|
||||
</state>
|
||||
<thermo model="IdealGas"/>
|
||||
<kinetics model="GasKinetics"/>
|
||||
<transport model="None"/>
|
||||
</phase>
|
||||
|
||||
<!-- species definitions -->
|
||||
<speciesData id="species_data">
|
||||
|
||||
<!-- species O -->
|
||||
<species name="O">
|
||||
<atomArray>O:1 </atomArray>
|
||||
<note>L 1/90</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.168267100E+00, -3.279318840E-03, 6.643063960E-06, -6.128066240E-09,
|
||||
2.112659710E-12, 2.912225920E+04, 2.051933460E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.569420780E+00, -8.597411370E-05, 4.194845890E-08, -1.001777990E-11,
|
||||
1.228336910E-15, 2.921757910E+04, 4.784338640E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species O2 -->
|
||||
<species name="O2">
|
||||
<atomArray>O:2 </atomArray>
|
||||
<note>TPIS89</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.782456360E+00, -2.996734160E-03, 9.847302010E-06, -9.681295090E-09,
|
||||
3.243728370E-12, -1.063943560E+03, 3.657675730E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="3500.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.282537840E+00, 1.483087540E-03, -7.579666690E-07, 2.094705550E-10,
|
||||
-2.167177940E-14, -1.088457720E+03, 5.453231290E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species N -->
|
||||
<species name="N">
|
||||
<atomArray>N:1 </atomArray>
|
||||
<note>L 6/88</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.500000000E+00, 0.000000000E+00, 0.000000000E+00, 0.000000000E+00,
|
||||
0.000000000E+00, 5.610463700E+04, 4.193908700E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="6000.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.415942900E+00, 1.748906500E-04, -1.190236900E-07, 3.022624500E-11,
|
||||
-2.036098200E-15, 5.613377300E+04, 4.649609600E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species NO -->
|
||||
<species name="NO">
|
||||
<atomArray>O:1 N:1 </atomArray>
|
||||
<note>RUS 78</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
4.218476300E+00, -4.638976000E-03, 1.104102200E-05, -9.336135400E-09,
|
||||
2.803577000E-12, 9.844623000E+03, 2.280846400E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="6000.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.260605600E+00, 1.191104300E-03, -4.291704800E-07, 6.945766900E-11,
|
||||
-4.033609900E-15, 9.920974600E+03, 6.369302700E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species NO2 -->
|
||||
<species name="NO2">
|
||||
<atomArray>O:2 N:1 </atomArray>
|
||||
<note>L 7/88</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.944031200E+00, -1.585429000E-03, 1.665781200E-05, -2.047542600E-08,
|
||||
7.835056400E-12, 2.896617900E+03, 6.311991700E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="6000.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
4.884754200E+00, 2.172395600E-03, -8.280690600E-07, 1.574751000E-10,
|
||||
-1.051089500E-14, 2.316498300E+03, -1.174169500E-01</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species N2O -->
|
||||
<species name="N2O">
|
||||
<atomArray>O:1 N:2 </atomArray>
|
||||
<note>L 7/88</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="200.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.257150200E+00, 1.130472800E-02, -1.367131900E-05, 9.681980600E-09,
|
||||
-2.930718200E-12, 8.741774400E+03, 1.075799200E+01</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="6000.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
4.823072900E+00, 2.627025100E-03, -9.585087400E-07, 1.600071200E-10,
|
||||
-9.775230300E-15, 8.073404800E+03, -2.201720700E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species N2 -->
|
||||
<species name="N2">
|
||||
<atomArray>N:2 </atomArray>
|
||||
<note>121286</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="300.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
3.298677000E+00, 1.408240400E-03, -3.963222000E-06, 5.641515000E-09,
|
||||
-2.444854000E-12, -1.020899900E+03, 3.950372000E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="5000.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.926640000E+00, 1.487976800E-03, -5.684760000E-07, 1.009703800E-10,
|
||||
-6.753351000E-15, -9.227977000E+02, 5.980528000E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
|
||||
<!-- species AR -->
|
||||
<species name="AR">
|
||||
<atomArray>Ar:1 </atomArray>
|
||||
<note>120186</note>
|
||||
<thermo>
|
||||
<NASA Tmax="1000.0" Tmin="300.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.500000000E+00, 0.000000000E+00, 0.000000000E+00, 0.000000000E+00,
|
||||
0.000000000E+00, -7.453750000E+02, 4.366000000E+00</floatArray>
|
||||
</NASA>
|
||||
<NASA Tmax="5000.0" Tmin="1000.0" P0="100000.0">
|
||||
<floatArray name="coeffs" size="7">
|
||||
2.500000000E+00, 0.000000000E+00, 0.000000000E+00, 0.000000000E+00,
|
||||
0.000000000E+00, -7.453750000E+02, 4.366000000E+00</floatArray>
|
||||
</NASA>
|
||||
</thermo>
|
||||
</species>
|
||||
</speciesData>
|
||||
<reactionData id="reaction_data"/>
|
||||
</ctml>
|
||||
18
test/python/runTests.py
Normal file
18
test/python/runTests.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
"""
|
||||
Unit tests for the Cantera Python module.
|
||||
|
||||
This script gathers all the tests defined in all of the test<foo>.py
|
||||
files, runs them, and prints a report.
|
||||
"""
|
||||
import unittest
|
||||
|
||||
import Cantera
|
||||
|
||||
if __name__ == '__main__':
|
||||
print '\n* INFO: using Cantera module found at this location:'
|
||||
print '* ', repr(Cantera.__file__), '\n'
|
||||
|
||||
loader = unittest.TestLoader()
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
suite = loader.loadTestsFromName('testThermo')
|
||||
runner.run(suite)
|
||||
9
test/python/testThermo.py
Normal file
9
test/python/testThermo.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import unittest
|
||||
|
||||
import Cantera as ct
|
||||
|
||||
class ImportTest(unittest.TestCase):
|
||||
def testCtiImport(self):
|
||||
gas = ct.importPhase('test/data/air-no-reactions.cti', 'air')
|
||||
|
||||
self.assertAlmostEqual(gas.temperature(), 300)
|
||||
Loading…
Add table
Reference in a new issue