Skip to content

Commit

Permalink
Copy FrameSet returned by getFrameSet in Python
Browse files Browse the repository at this point in the history
In Python make sure the FrameSet returned by Transform.getFrameSet
is independent of the contained FrameSet by returning a copy.
Add a test for this.
The C++ API is unchanged because it returns a const FrameSet.
(Python does not respect `const`).
  • Loading branch information
r-owen committed Apr 20, 2017
1 parent db8d228 commit 249a70f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/lsst/afw/geom/transform/transform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ void declareTransform(py::module &mod, std::string const &fromName, std::string
cls.def("hasInverse", &Class::hasInverse);

cls.def("getFromEndpoint", &Class::getFromEndpoint);
cls.def("getFrameSet", &Class::getFrameSet);
// Return a copy of the contained FrameSet in order to assure changing the returned FrameSet
// will not affect the contained FrameSet (since Python ignores constness)
cls.def("getFrameSet", [](Class const &self) {
return self.getFrameSet()->copy();
});
cls.def("getToEndpoint", &Class::getToEndpoint);

cls.def("tranForward", (ToArray (Class::*)(FromArray const &) const) & Class::tranForward, "array"_a);
Expand Down
13 changes: 13 additions & 0 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,19 @@ def testTransforms(self):
self.checkOf(fromName, midName, toName)
self.checkOfChaining()

def testFrameSetIndependence(self):
"""Test that the FrameSet returned by getFrameSet is independent of the contained FrameSet
"""
baseFrame = makeGoodFrame("Generic", 2)
currFrame = makeGoodFrame("Generic", 2)
initialFrameSet = makeFrameSet(baseFrame, currFrame)
initialIdent = "Initial Ident"
initialFrameSet.setIdent(initialIdent)
transform = afwGeom.TransformGenericToGeneric(initialFrameSet)
extractedFrameSet = transform.getFrameSet()
extractedFrameSet.setIdent("Extracted Ident")
self.assertEqual(initialIdent, transform.getFrameSet().getIdent())


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

0 comments on commit 249a70f

Please sign in to comment.