mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
Starting a test suite for the new Python module
This commit is contained in:
4
interfaces/cython/cantera/test/__init__.py
Normal file
4
interfaces/cython/cantera/test/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .test_thermo import *
|
||||
from .test_kinetics import *
|
||||
from .test_transport import *
|
||||
from .test_mixture import *
|
||||
11
interfaces/cython/cantera/test/test_kinetics.py
Normal file
11
interfaces/cython/cantera/test/test_kinetics.py
Normal 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)
|
||||
20
interfaces/cython/cantera/test/test_mixture.py
Normal file
20
interfaces/cython/cantera/test/test_mixture.py
Normal 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)
|
||||
29
interfaces/cython/cantera/test/test_thermo.py
Normal file
29
interfaces/cython/cantera/test/test_thermo.py
Normal 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)
|
||||
11
interfaces/cython/cantera/test/test_transport.py
Normal file
11
interfaces/cython/cantera/test/test_transport.py
Normal 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)
|
||||
12
interfaces/cython/cantera/test/utilities.py
Normal file
12
interfaces/cython/cantera/test/utilities.py
Normal 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)
|
||||
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user