Skip to content

Commit

Permalink
improve excepion, add test for v1 api with v2 api
Browse files Browse the repository at this point in the history
  • Loading branch information
n8pease committed Feb 17, 2017
1 parent 718f58e commit a211d6c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
5 changes: 3 additions & 2 deletions python/lsst/daf/persistence/butler.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ def __init__(self, root=None, mapper=None, inputs=None, outputs=None, **mapperAr
isV1Args = inputs is None and outputs is None
if isV1Args:
inputs, outputs = self._convertV1Args(root=root, mapper=mapper, mapperArgs=mapperArgs)
elif root:
elif root or mapper or mapperArgs:
raise RuntimeError(
'root is a deprecated parameter and may not be used with the parameters input and output')
'Butler version 1 API (root, mapper, **mapperArgs) may ' +
'not be used with version 2 API (inputs, outputs)')

self.datasetTypeAliasDict = {}

Expand Down
61 changes: 61 additions & 0 deletions tests/testButler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python -*- coding: UTF-8 -*-

#
# LSST Data Management System
# Copyright 2016 LSST Corporation.
#
# This product includes software developed by the
# LSST Project (http://www.lsst.org/).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the LSST License Statement and
# the GNU General Public License along with this program. If not,
# see <http://www.lsstcorp.org/LegalNotices/>.
#

import unittest
import lsst.daf.persistence as dp
import lsst.utils.tests


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


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

def testV1withV2InitApiRaises(self):
"""Test that a RuntimeError is raised when Butler v1 init api (root,
mapper, mapperArgs**) is used with Butler v2 init api
(inputs, outputs)."""
with self.assertRaises(RuntimeError):
dp.Butler(root='foo/bar', inputs='foo/bar')
with self.assertRaises(RuntimeError):
dp.Butler(mapper='lsst.obs.base.CameraMapper', inputs='foo/bar')
with self.assertRaises(RuntimeError):
dp.Butler(inputs='foo/bar', calibRoot='foo/baz')
with self.assertRaises(RuntimeError):
dp.Butler(root='foo/bar', outputs='foo/bar')
with self.assertRaises(RuntimeError):
dp.Butler(mapper='lsst.obs.base.CameraMapper', outputs='foo/bar')
with self.assertRaises(RuntimeError):
dp.Butler(inputs='foo/bar', outputs='foo/baz')


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


if __name__ == '__main__':
lsst.utils.tests.init()
unittest.main()

0 comments on commit a211d6c

Please sign in to comment.