mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-23 01:16:34 +03:00
Avoid ResourceWarning in tests in Python 3.2
This commit is contained in:
parent
43c8fce45c
commit
f8c4335f35
|
@ -182,7 +182,11 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
|
|||
filename = os.path.join(self.tmpdir, "data.txt")
|
||||
lo.export(filename)
|
||||
self.assertTrue(os.path.exists(filename))
|
||||
self.assertEqual(open(filename, "rb").read(), b("some data"))
|
||||
f = open(filename, "rb")
|
||||
try:
|
||||
self.assertEqual(f.read(), b("some data"))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def test_close_twice(self):
|
||||
lo = self.conn.lobject()
|
||||
|
@ -224,7 +228,11 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
|
|||
filename = os.path.join(self.tmpdir, "data.txt")
|
||||
lo.export(filename)
|
||||
self.assertTrue(os.path.exists(filename))
|
||||
self.assertEqual(open(filename, "rb").read(), b("some data"))
|
||||
f = open(filename, "rb")
|
||||
try:
|
||||
self.assertEqual(f.read(), b("some data"))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def test_close_after_commit(self):
|
||||
lo = self.conn.lobject()
|
||||
|
@ -279,7 +287,11 @@ class LargeObjectTests(LargeObjectMixin, unittest.TestCase):
|
|||
filename = os.path.join(self.tmpdir, "data.txt")
|
||||
lo.export(filename)
|
||||
self.assertTrue(os.path.exists(filename))
|
||||
self.assertEqual(open(filename, "rb").read(), b("some data"))
|
||||
f = open(filename, "rb")
|
||||
try:
|
||||
self.assertEqual(f.read(), b("some data"))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
decorate_all_tests(LargeObjectTests, skip_if_no_lo)
|
||||
decorate_all_tests(LargeObjectTests, skip_if_green)
|
||||
|
|
|
@ -121,5 +121,9 @@ def script_to_py3(script):
|
|||
if main("lib2to3.fixes", ['--no-diffs', '-w', '-n', f.name]):
|
||||
raise Exception('py3 conversion failed')
|
||||
|
||||
return open(f.name).read()
|
||||
f2 = open(f.name)
|
||||
try:
|
||||
return f2.read()
|
||||
finally:
|
||||
f2.close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user