Starting a test suite for the new Python module

This commit is contained in:
Ray Speth
2012-09-06 19:56:43 +00:00
parent 062ab1dad9
commit 1758c86a3f
7 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,4 @@
from .test_thermo import *
from .test_kinetics import *
from .test_transport import *
from .test_mixture import *

View File

@@ -0,0 +1,11 @@
import unittest
import cantera as ct
from . import utilities
class TestKinetics(utilities.CanteraTest):
def setUp(self):
self.phase = ct.Solution('h2o2.xml')
def test_nReactions(self):
self.assertEqual(self.phase.nReactions, 27)

View File

@@ -0,0 +1,20 @@
import unittest
import cantera as ct
from . import utilities
class TestMixture(utilities.CanteraTest):
@classmethod
def setUpClass(cls):
cls.phase1 = ct.Solution('h2o2.xml')
cls.phase2 = ct.Solution('air.xml')
def test_properties(self):
mix = ct.Mixture([(self.phase1, 1.0), (self.phase2, 2.0)])
self.assertEqual(mix.nSpecies, self.phase1.nSpecies + self.phase2.nSpecies)
mix.temperature = 350
self.assertEqual(mix.temperature, 350)
mix.pressure = 2e5
self.assertEqual(mix.pressure, 2e5)

View File

@@ -0,0 +1,29 @@
import unittest
import numpy as np
import cantera as ct
from . import utilities
class TestThermoPhase(utilities.CanteraTest):
def setUp(self):
self.phase = ct.Solution('h2o2.xml')
def test_nSpecies(self):
self.assertEqual(self.phase.nSpecies, 9)
def test_setComposition(self):
X = np.zeros(self.phase.nSpecies)
X[2] = 1.0
self.phase.setMoleFractions(X)
Y = self.phase.massFractions
self.assertEqual(list(X), list(Y))
def test_badLength(self):
X = np.zeros(5)
with self.assertRaises(ValueError):
self.phase.setMoleFractions(X)
def test_getState(self):
self.assertNear(self.phase.pressure, ct.OneAtm)
self.assertNear(self.phase.temperature, 300)

View File

@@ -0,0 +1,11 @@
import unittest
import cantera as ct
from . import utilities
class TestTransport(utilities.CanteraTest):
def setUp(self):
self.phase = ct.Solution('h2o2.xml')
def test_viscosity(self):
self.assertTrue(self.phase.viscosity > 0.0)

View File

@@ -0,0 +1,12 @@
import numpy as np
import unittest
class CanteraTest(unittest.TestCase):
def assertNear(self, a, b, rtol=1e-8, atol=1e-12, msg=None):
cmp = 2 * abs(a - b)/(abs(a) + abs(b) + atol)
if cmp > rtol:
message = ('AssertNear: %.14g - %.14g = %.14g\n' % (a, b, a-b) +
'Relative error of %10e exceeds rtol = %10e' % (cmp, rtol))
if msg:
message = msg + '\n' + message
self.fail(message)

View File

@@ -26,7 +26,7 @@ setup(name="Cantera",
author="Raymond Speth",
author_email="speth@mit.edu",
url="http://code.google.com/p/cantera",
packages = ["cantera"],
packages = ["cantera", "cantera.test"],
cmdclass = {'build_ext': build_ext},
ext_modules = exts,
package_data = {'cantera': dataFiles})