Handle bad representations of geometry flags

If geometry flags are specified rather that can't be cast to integers,
intercept the ValueError raised by Python and raise a more sensible
exception.

Fixes #446
This commit is contained in:
Bryan W. Weber 2017-06-13 19:03:21 -04:00
parent d920f2eb2c
commit 6bf74d179b
No known key found for this signature in database
GPG key ID: 3A93E209C87E1FE7
3 changed files with 22 additions and 1 deletions

View file

@ -847,7 +847,12 @@ class TransportData(object):
def __init__(self, label, geometry, wellDepth, collisionDiameter,
dipoleMoment, polarizability, zRot, comment=None):
if int(geometry) not in (0,1,2):
try:
geometry = int(geometry)
except ValueError:
raise InputParseError("Bad geometry flag '{0}' for species '{1}', is the flag a float "
"or character? It should be an integer.".format(geometry, label))
if geometry not in (0, 1, 2):
raise InputParseError("Bad geometry flag '{0}' for species '{1}'".format(geometry, label))
self.label = label

View file

@ -348,6 +348,13 @@ class chemkinConverterTest(utilities.CanteraTest):
outName=pjoin(self.test_work_dir, 'h2o2_transport_bad_geometry.cti'),
quiet=True)
def test_transport_float_geometry(self):
with self.assertRaises(ck2cti.InputParseError):
convertMech(pjoin(self.test_data_dir, 'h2o2.inp'),
transportFile=pjoin(self.test_data_dir, 'h2o2-float-geometry-tran.dat'),
outName=pjoin(self.test_work_dir, 'h2o2_transport_float_geometry.cti'),
quiet=True)
def test_empty_reaction_section(self):
convertMech(pjoin(self.test_data_dir, 'h2o2_emptyReactions.inp'),
outName=pjoin(self.test_work_dir, 'h2o2_emptyReactions.cti'),

View file

@ -0,0 +1,9 @@
AR 0 136.500 3.330 0.000 0.000 0.000
H 0.00 145.000 2.050 0.000 0.000 0.000
H2 1.00 38.000 2.920 0.000 0.790 280.000
H2O 2.00 572.400 2.605 1.844 0.000 4.000
H2O2 2 107.400 3.458 0.000 0.000 3.800
HO2 2 107.400 3.458 0.000 0.000 1.000 ! *
O 0 80.000 2.750 0.000 0.000 0.000
O2 1 107.400 3.458 0.000 1.600 3.800
OH 1 80.000 2.750 0.000 0.000 0.000