Skip to content
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

Merged
merged 6 commits into from Aug 18, 2017
Merged

Conversation

timj
Copy link
Member

@timj timj commented Aug 15, 2017

@n8pease work in progress. In particular test_repository.TestBasics doesn't work and I don't know why...

@timj timj force-pushed the tickets/DM-11595 branch 4 times, most recently from a8129d1 to c3fd82c Compare August 18, 2017 00:18
* Use assertEqual rather than assertEquals
* Close a file handle that was open and use "with open"
@@ -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')
Copy link
Contributor

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?

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]
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Or maybe I'm faded from travel. I need to board... off I go.

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)))
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed; running tests from inside daf_persistence/python (as an example) fails

n8pease@Nates-MacBook-Pro ~/3/lsstsw/build/daf_persistence/python[tickets/DM-11595*]$ py.test ~/3/lsstsw/build/daf_persistence/tests/test_mapperImport.py 

def setup(self):
self.clean()
def setUp(self):
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='repoOfRepos-')
Copy link
Contributor

Choose a reason for hiding this comment

The 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"

@@ -374,10 +378,12 @@ class TestMultipleInputs(unittest.TestCase):
- verify dissimilar datasets with same id that were written to the repos

"""
def setUp(self):
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestMapperInference-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the prefix here should be "TestMultipleInputs"

self.testDir = os.path.join(ROOT, 'TestParentRepository')
if os.path.exists(self.testDir):
shutil.rmtree(self.testDir)
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestBasics-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix should be "TestParentRepository"

@@ -39,102 +39,105 @@
class TestCfgRelationship(unittest.TestCase):

def setUp(self):
self.tearDown()
self.testDir = tempfile.mkdtemp(dir=ROOT,
prefix="repositoryCfg-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix should be TestCfgRelationship

def setUp(self):
self.tearDown()
self.testDir = tempfile.mkdtemp(dir=ROOT,
prefix="repositoryCfg_TestNestedCfg-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you just used what was already there but the prefix here can probably just be TestNestedCfg

@@ -214,19 +216,18 @@ class TestCfgFileVersion(unittest.TestCase):
"""

def setUp(self):
self.tearDown()
self.testDir = tempfile.mkdtemp(dir=ROOT,
prefix="repositoryCfg-")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix -> TestCfgFileVersion

@@ -45,37 +46,37 @@ def setup_module(module):
class WriteOnceCompareSameTest(unittest.TestCase):

def setUp(self):
self.tearDown()
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix='safeFileIo-')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix -> "WriteOnceCompareSameTest"

if os.path.exists(self.testDir):
shutil.rmtree(self.testDir)
self.testDir = tempfile.mkdtemp(dir=ROOT, prefix="TestBasics-")
self.testDir = os.path.join(self.testDir, 'TestParentRepository')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line shouldn't be here? It's preventing files inside TestBasics-... (which should be TestParentRepository-...)
from getting removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course. Thanks for spotting that. I had to change many many lines...

@n8pease n8pease merged commit 9344225 into master Aug 18, 2017
@ktlim ktlim deleted the tickets/DM-11595 branch August 25, 2018 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants