Coverage for tests/test_butlerProxy.py: 35%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# LSST Data Management System
3# Copyright 2008, 2009, 2010 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
23import os
24import shutil
25import unittest
26import tempfile
27import lsst.utils.tests
29import lsst.daf.persistence as dafPersist
30import lsst.daf.base as dafBase
32from testLib import isValidDateTime, TypeWithProxy, TypeWithoutProxy
34# Define the root of the tests relative to this file
35ROOT = os.path.abspath(os.path.dirname(__file__))
38class ButlerProxyTestCase(unittest.TestCase):
39 """A test case for the data butler finding a Mapper in a root"""
41 inputDir = os.path.join(ROOT, 'root')
43 def setUp(self):
44 self.outputDir = tempfile.mkdtemp(dir=ROOT, prefix='ButlerProxyTestCase-')
45 self.butler = dafPersist.Butler(self.inputDir,
46 outPath=os.path.join(self.outputDir, "proxyOut"))
48 def tearDown(self):
49 del self.butler
50 if os.path.exists(self.outputDir):
51 shutil.rmtree(self.outputDir)
53 def testCheckProxy(self):
54 """Attempt to cycle a DateTime object through the butler
55 """
56 dt = dafBase.DateTime.now()
57 self.butler.put(dt, "dt", ccd=1)
59 # The next two types should not be castable to a DateTime object
60 # when the proxy is passed to a function
61 p1 = TypeWithoutProxy()
62 self.butler.put(p1, "p1", ccd=1)
64 p2 = TypeWithProxy()
65 self.butler.put(p2, "p2", ccd=1)
67 # First try with immediate read, this should obviously work
68 dt = self.butler.get("dt", ccd=1, immediate=True)
69 self.assertIsInstance(dt, dafBase.DateTime)
70 self.assertTrue(isValidDateTime(dt))
72 # Now try again with lazy read
73 dt = self.butler.get("dt", ccd=1, immediate=False)
74 self.assertIsInstance(dt, dafPersist.readProxy.ReadProxy)
75 self.assertTrue(isValidDateTime(dt))
77 # Now try with a type for which a proxy is not registered
78 p1 = self.butler.get("p1", ccd=1, immediate=True)
79 self.assertIsInstance(p1, TypeWithoutProxy)
80 with self.assertRaises(TypeError):
81 isValidDateTime(p1)
83 # Now try with a type for which a proxy was registered but
84 # that cannot convert to a DateTime
85 p2 = self.butler.get("p2", ccd=1, immediate=True)
86 self.assertIsInstance(p2, TypeWithProxy)
87 with self.assertRaises(TypeError):
88 isValidDateTime(p2)
90 # Finally try with an invalid DateTime
91 dt = dafBase.DateTime()
92 self.butler.put(dt, "dt", ccd=1)
94 dt = self.butler.get("dt", ccd=1, immediate=False)
95 self.assertIsInstance(dt, dafPersist.readProxy.ReadProxy)
96 self.assertFalse(isValidDateTime(dt))
99class TestMemory(lsst.utils.tests.MemoryTestCase):
100 pass
103def setup_module(module):
104 lsst.utils.tests.init()
107if __name__ == "__main__": 107 ↛ 108line 107 didn't jump to line 108, because the condition on line 107 was never true
108 lsst.utils.tests.init()
109 unittest.main()