Coverage for tests/test_Storable.py : 36%
Hot-keys 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
|
# This file is part of afw. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # 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 GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>.
"""Test that we can inherit from Storable in Python. """
super().__init__() self._state = state
return "value = %s" % self._state
return "DemoStorable(%r)" % self._state
return hash(self._state)
return DemoStorable(self._state)
return DemoStorable(copy.deepcopy(self._state, memo))
return self._state == other._state
"""Test that we can inherit from C++ subclasses of Storable that are not Storable itself. """
return "Pythonic " + super().__repr__()
self.aList = [42] self.testbed = DemoStorable(self.aList)
shallow = copy.copy(self.testbed) self.assertIsNot(shallow, self.testbed) self.assertEqual(shallow, self.testbed)
deep = copy.deepcopy(self.testbed) self.assertIsNot(deep, self.testbed) self.assertEqual(deep, self.testbed)
cpp = cppLib.duplicate(self.testbed) self.assertIsInstance(cpp, Storable) self.assertIsInstance(cpp, DemoStorable) self.assertIsNot(cpp, self.testbed) self.assertEqual(cpp, self.testbed)
self.aList.append(43) self.assertEqual(shallow, DemoStorable([42, 43])) self.assertEqual(deep, DemoStorable([42])) self.assertEqual(cpp, DemoStorable([42]))
self.assertEqual(str(self.testbed), "value = [42]")
self.assertEqual(repr(self.testbed), "DemoStorable([42])") cppLib.assertPythonStorable(self.testbed, "DemoStorable([42])")
with self.assertRaises(TypeError): hash(self.testbed)
self.assertEqual(self.testbed, DemoStorable([42])) self.assertNotEqual(self.testbed, DemoStorable(0))
cppLib.keepStaticStorable(DemoStorable(3))
gc.collect()
retrieved = cppLib.keepStaticStorable() self.assertIsInstance(retrieved, Storable) self.assertIsInstance(retrieved, DemoStorable) self.assertEqual(retrieved, DemoStorable(3))
cppLib.keepStaticStorable(SpecializedStorable("Foo"))
gc.collect()
retrieved = cppLib.keepStaticStorable() self.assertIsInstance(retrieved, Storable) self.assertIsInstance(retrieved, cppLib.CppStorable) self.assertIsInstance(retrieved, SpecializedStorable) self.assertEqual(repr(retrieved), "Pythonic Foo") cppLib.assertPythonStorable(retrieved, "Pythonic Foo")
self.initstr = "Just a string" self.testbed = cppLib.CppStorable(self.initstr)
"""Test a Python-side state change in both C++ and Python. """ self.assertEqual(self.testbed.value, self.initstr) cppLib.assertCppValue(self.testbed, self.initstr)
newstr = "Stringly typed" self.testbed.value = newstr
self.assertEqual(self.testbed.value, newstr) cppLib.assertCppValue(self.testbed, newstr)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |