-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DM-11771: Close files that have been left hanging #66
Changes from 4 commits
634ea21
e93ede0
90ff523
c48ea16
b2174f4
aa61098
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,9 @@ | |
|
||
from builtins import range | ||
import collections | ||
import gc | ||
import os | ||
import sqlite3 | ||
import unittest | ||
import tempfile | ||
|
||
|
@@ -390,15 +392,39 @@ def testPackageName(self): | |
|
||
class ParentRegistryTestCase(unittest.TestCase): | ||
|
||
@staticmethod | ||
def _createRegistry(path): | ||
cmd = """CREATE TABLE x( | ||
id INT, | ||
visit INT, | ||
filter TEXT, | ||
snap INT, | ||
raft TEXT, | ||
sensor TEXT, | ||
channel TEXT, | ||
taiObs TEXT, | ||
expTime REAL | ||
); | ||
""" | ||
conn = sqlite3.connect(path) | ||
conn.cursor().execute(cmd) | ||
conn.commit() | ||
conn.close() | ||
|
||
def setUp(self): | ||
self.ROOT = tempfile.mkdtemp(dir=ROOT, prefix="ParentRegistryTestCase-") | ||
self.repoARoot = os.path.join(self.ROOT, 'a') | ||
args = dafPersist.RepositoryArgs(root=self.repoARoot, mapper=MinMapper1) | ||
butler = dafPersist.Butler(outputs=args) | ||
with open(os.path.join(self.repoARoot, 'registry.sqlite3'), 'w') as f: | ||
f.write('123') | ||
self._createRegistry(os.path.join(self.repoARoot, 'registry.sqlite3')) | ||
del butler | ||
|
||
def tearDown(self): | ||
# the butler sql registry closes its database connection in __del__. To trigger __del__ we explicitly | ||
# collect the garbage here. If we find having or closing the open database connection is a problem in | ||
# production code, we may need to add api to butler to explicity release database connections (and | ||
# maybe other things like in-memory cached objects). | ||
gc.collect() | ||
if os.path.exists(self.ROOT): | ||
shutil.rmtree(self.ROOT) | ||
|
||
|
@@ -413,16 +439,19 @@ def test(self): | |
registryA = butler._repos.inputs()[0].repo._mapper.registry | ||
registryB = butler._repos.outputs()[0].repo._mapper.registry | ||
self.assertEqual(id(registryA), id(registryB)) | ||
del registryA | ||
del registryB | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am guessing that these three |
||
del butler | ||
|
||
with open(os.path.join(repoBRoot, 'registry.sqlite3'), 'w') as f: | ||
f.write('123') | ||
self._createRegistry(os.path.join(repoBRoot, 'registry.sqlite3')) | ||
butler = dafPersist.Butler(inputs=self.repoARoot, outputs=repoBRoot) | ||
# see above; don't copy this way of getting the registry. | ||
registryA = butler._repos.inputs()[0].repo._mapper.registry | ||
registryB = butler._repos.outputs()[0].repo._mapper.registry | ||
self.assertNotEqual(id(registryA), id(registryB)) | ||
|
||
del registryA | ||
del registryB | ||
del butler | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these make a difference now? The variables will disappear at end of scope and the |
||
|
||
class MissingPolicyKeyTestCase(unittest.TestCase): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be needed, but keeping it means that the linter won't complain about
butler
only being used once.