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

check for mapper is not None before testing type #48

Merged
merged 1 commit into from
Mar 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/lsst/daf/persistence/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def _convertV1Args(self, root, mapper, mapperArgs):
(inputs, outputs) - values to be used for inputs and outputs in Butler.__init__
"""
# mapper ought to be an importable string or a class object (not a mapper class instance)
if not isinstance(mapper, basestring) and not inspect.isclass(mapper):
if mapper and not isinstance(mapper, basestring) and not inspect.isclass(mapper):
err = "mapper ought to be an importable string or a class object (not a mapper class instance)"
# TBD we might have to handle this. It'll be complicated because of e.g. outputRoot & calibRoot
self.log.warn(err)
Expand Down
21 changes: 21 additions & 0 deletions tests/testButler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,29 @@
import unittest
import lsst.daf.persistence as dp
import lsst.utils.tests
import os
import shutil

ROOT = os.path.abspath(os.path.dirname(__file__))


def setup_module(module):
lsst.utils.tests.init()


class TestMapper(dp.Mapper):
pass


class ButlerTest(unittest.TestCase):
"""Test case for basic Butler operations."""

testDir = os.path.join(ROOT, 'ButlerTest')

def tearDown(self):
if os.path.exists(self.testDir):
shutil.rmtree(self.testDir)

def testV1withV2InitApiRaises(self):
"""Test that a RuntimeError is raised when Butler v1 init api (root,
mapper, mapperArgs**) is used with Butler v2 init api
Expand All @@ -51,6 +65,13 @@ def testV1withV2InitApiRaises(self):
with self.assertRaises(RuntimeError):
dp.Butler(inputs='foo/bar', outputs='foo/baz')

def testV1RepoWithRootOnly(self):
repoDir = os.path.join(self.testDir, 'repo')
os.makedirs(repoDir)
with open(os.path.join(repoDir, '_mapper'), 'w') as f:
f.write('__main__.TestMapper')
butler = dp.Butler(repoDir)


class MemoryTester(lsst.utils.tests.MemoryTestCase):
pass
Expand Down