-
Notifications
You must be signed in to change notification settings - Fork 8
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-11595: Use mkdtemp for test directories #73
Changes from 2 commits
6f02669
a2dbb12
5d0e458
60d0db9
e4d5b8b
9344225
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import pickle | ||
import shutil | ||
import unittest | ||
import tempfile | ||
import lsst.utils.tests | ||
|
||
import lsst.daf.persistence as dafPersist | ||
|
@@ -38,15 +39,16 @@ class MapperImportTestCase(unittest.TestCase): | |
"""A test case for the data butler finding a Mapper in a root""" | ||
|
||
def setUp(self): | ||
if os.path.exists(os.path.join(ROOT, 'root/out')): | ||
shutil.rmtree(os.path.join(ROOT, 'root/out')) | ||
self.testDir = os.path.join(ROOT, 'root') | ||
self.rootPath = tempfile.mkdtemp(dir=self.testDir, prefix="out-") | ||
self.outPath = os.path.split(self.rootPath)[1] | ||
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. by removing the absolute part of the path and passing only the temp dir name to the outPath iarg, you're creating an output repository relative to the current working dir. Which would be fine, but in tearDown you're deleting self.rootPath, not self.outPath, so outpath will never get cleaned up. Right? I think you can just pass self.rootPath to the outPath iarg. |
||
|
||
self.butler = dafPersist.Butler(os.path.join(ROOT, "root"), outPath="out") | ||
self.butler = dafPersist.Butler(self.testDir, outPath=self.outPath) | ||
|
||
def tearDown(self): | ||
del self.butler | ||
if os.path.exists(os.path.join(ROOT, 'root/out')): | ||
shutil.rmtree(os.path.join(ROOT, 'root/out')) | ||
if os.path.exists(self.rootPath): | ||
shutil.rmtree(self.rootPath) | ||
|
||
def testMapperClass(self): | ||
repository = self.butler._repos.outputs()[0].repo | ||
|
@@ -56,8 +58,8 @@ def checkIO(self, butler, bbox, ccd): | |
butler.put(bbox, "x", ccd=ccd) | ||
y = butler.get("x", ccd=ccd, immediate=True) | ||
self.assertEqual(bbox, y) | ||
self.assert_(os.path.exists( | ||
os.path.join(ROOT, "root", "out", "foo%d.pickle" % ccd))) | ||
self.assertTrue(os.path.exists( | ||
os.path.join(self.rootPath, "foo%d.pickle" % ccd))) | ||
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 think this will fail if the current working dir is not the same as the directory above outpath? 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. confirmed; running tests from inside
|
||
|
||
def testIO(self): | ||
bbox = [[3, 4], [5, 6]] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
import os | ||
import shutil | ||
import unittest | ||
import tempfile | ||
|
||
import yaml | ||
|
||
|
@@ -98,15 +99,12 @@ def map_str(self, dataId, write): | |
|
||
class ReposInButler(unittest.TestCase): | ||
|
||
def clean(self): | ||
if os.path.exists(os.path.join(ROOT, 'repoOfRepos')): | ||
shutil.rmtree(os.path.join(ROOT, 'repoOfRepos')) | ||
|
||
def setup(self): | ||
self.clean() | ||
def setUp(self): | ||
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='repoOfRepos-') | ||
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. not your bug but while your here you could fix "repoOfRepos" to accurately show the test class name "reposInButler" |
||
|
||
def tearDown(self): | ||
self.clean() | ||
if os.path.exists(self.testDir): | ||
shutil.rmtree(self.testDir) | ||
|
||
# disable this test until we work more on repo of repos; starting with DM-6227 | ||
@unittest.expectedFailure | ||
|
@@ -122,15 +120,14 @@ def test(self): | |
} | ||
|
||
# create a cfg of a repository for our repositories | ||
storageCfg = dp.PosixStorage.cfg(root=os.path.join(ROOT, 'repoOfRepos')) | ||
storageCfg = dp.PosixStorage.cfg(root=self.testDir) | ||
accessCfg = dp.Access.cfg(storageCfg=storageCfg) | ||
mapperCfg = dp.RepositoryMapper.cfg(policy=repoMapperPolicy) | ||
# Note that right now a repo is either input OR output, there is no input-output repo, this design | ||
# is result of butler design conversations. Right now, if a user wants to write to and then read from | ||
# a repo, a repo can have a parent repo with the same access (and mapper) parameters as itself. | ||
repoOfRepoCfg = dp.Repository.cfg(mode='rw', | ||
storageCfg=dp.PosixStorage.cfg(root=os.path.join(ROOT, | ||
'repoOfRepos')), | ||
storageCfg=dp.PosixStorage.cfg(root=self.testDir), | ||
mapper=dp.RepositoryMapper.cfg(policy=repoMapperPolicy)) | ||
|
||
repoButler = dp.Butler(outputs=repoOfRepoCfg) | ||
|
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.
nit: I think inputDir would be more accurate?