testgit: use with statements to open files.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2014-07-18 23:10:22 +00:00
parent 74ab2d9fc7
commit d66aa22c12
No known key found for this signature in database
GPG key ID: BF535D811F52F68B

View file

@ -13,9 +13,8 @@ import unittest
class TestGitTransactions(unittest.TestCase):
def setUp(self):
self.tempdir = tempfile.TemporaryDirectory()
fp = open(self.tempdir.name + "/schema", "w")
fp.write("fmt:0:newfol schema file:\ntxn:git\n")
fp.close()
with open(self.tempdir.name + "/schema", "w") as fp:
fp.write("fmt:0:newfol schema file:\ntxn:git\n")
self.db = newfol.database.Database.load(self.tempdir.name)
def tearDown(self):
@ -58,9 +57,8 @@ class TestGitTransactions(unittest.TestCase):
data = None
try:
os.chdir(self.tempdir.name)
fp = os.popen("git log --pretty=format:" + fmt + " -n1")
data = fp.read()
fp.close()
with os.popen("git log --pretty=format:" + fmt + " -n1") as fp:
data = fp.read()
finally:
os.chdir(cwd)
return data