[Test/Python] Fix warnings about unclosed files
This commit is contained in:
parent
58110351af
commit
3914ede44a
4 changed files with 16 additions and 9 deletions
|
|
@ -1876,8 +1876,8 @@ class Parser(object):
|
|||
|
||||
lines.append('')
|
||||
|
||||
f = open(outName, 'w')
|
||||
f.write('\n'.join(lines))
|
||||
with open(outName, 'w') as f:
|
||||
f.write('\n'.join(lines))
|
||||
|
||||
def showHelp(self):
|
||||
print("""
|
||||
|
|
@ -1954,7 +1954,8 @@ duplicate transport data) to be ignored.
|
|||
if transportFile:
|
||||
if not os.path.exists(transportFile):
|
||||
raise IOError('Missing transport file: {0!r}'.format(transportFile))
|
||||
lines = [strip_nonascii(line) for line in open(transportFile, 'rU')]
|
||||
with open(transportFile, 'rU') as f:
|
||||
lines = [strip_nonascii(line) for line in f]
|
||||
self.parseTransportData(lines, transportFile, 1)
|
||||
|
||||
# Transport validation: make sure all species have transport data
|
||||
|
|
|
|||
|
|
@ -342,7 +342,8 @@ class chemkinConverterTest(utilities.CanteraTest):
|
|||
def test_reaction_comments1(self):
|
||||
convertMech('../data/pdep-test.inp',
|
||||
outName='pdep_test.cti', quiet=True)
|
||||
text = open('pdep_test.cti').read()
|
||||
with open('pdep_test.cti') as f:
|
||||
text = f.read()
|
||||
self.assertIn('Generic mechanism header', text)
|
||||
self.assertIn('Single PLOG reaction', text)
|
||||
self.assertIn('PLOG with duplicate rates and negative A-factors', text)
|
||||
|
|
@ -351,7 +352,8 @@ class chemkinConverterTest(utilities.CanteraTest):
|
|||
convertMech('../data/explicit-third-bodies.inp',
|
||||
thermoFile='../data/dummy-thermo.dat',
|
||||
outName='explicit_third_bodies.cti', quiet=True)
|
||||
text = open('explicit_third_bodies.cti').read()
|
||||
with open('explicit_third_bodies.cti') as f:
|
||||
text = f.read()
|
||||
self.assertIn('An end of line comment', text)
|
||||
self.assertIn('A comment after the last reaction', text)
|
||||
|
||||
|
|
|
|||
|
|
@ -633,13 +633,15 @@ class TestReaction(utilities.CanteraTest):
|
|||
self.assertEqual(eq1, eq2)
|
||||
|
||||
def test_listFromCti(self):
|
||||
R = ct.Reaction.listFromCti(open('../../build/data/h2o2.cti').read())
|
||||
with open('../../build/data/h2o2.cti') as f:
|
||||
R = ct.Reaction.listFromCti(f.read())
|
||||
eq1 = [r.equation for r in R]
|
||||
eq2 = [r.equation for r in self.gas.reactions()]
|
||||
self.assertEqual(eq1, eq2)
|
||||
|
||||
def test_listFromXml(self):
|
||||
R = ct.Reaction.listFromCti(open('../../build/data/h2o2.xml').read())
|
||||
with open('../../build/data/h2o2.xml') as f:
|
||||
R = ct.Reaction.listFromCti(f.read())
|
||||
eq1 = [r.equation for r in R]
|
||||
eq2 = [r.equation for r in self.gas.reactions()]
|
||||
self.assertEqual(eq1, eq2)
|
||||
|
|
|
|||
|
|
@ -858,13 +858,15 @@ class TestSpecies(utilities.CanteraTest):
|
|||
set(self.gas.species_names))
|
||||
|
||||
def test_listFromCti(self):
|
||||
S = ct.Species.listFromCti(open('../../build/data/h2o2.cti').read())
|
||||
with open('../../build/data/h2o2.cti') as f:
|
||||
S = ct.Species.listFromCti(f.read())
|
||||
|
||||
self.assertEqual({sp.name for sp in S},
|
||||
set(self.gas.species_names))
|
||||
|
||||
def test_listFromXml(self):
|
||||
S = ct.Species.listFromXml(open('../../build/data/h2o2.xml').read())
|
||||
with open('../../build/data/h2o2.xml') as f:
|
||||
S = ct.Species.listFromXml(f.read())
|
||||
|
||||
self.assertEqual({sp.name for sp in S},
|
||||
set(self.gas.species_names))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue