Coverage for tests/test_pybind11.py : 80%

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
# # LSST Data Management System # Copyright 2008-2016 LSST/AURA # # 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/>. #
"""A test case basic pybind11 wrapping"""
def testReturnNone(self): result = self.example.get1() self.assertIsNone(result)
def testReturnSelf(self): result = self.example.get2() self.assertIs(result, self.example)
def testReturnCopy(self): result = self.example.get3() self.assertIsNot(result, self.example) self.assertIsInstance(result, _example.Example) result.setValue("bar") self.assertEqual(self.example.getValue(), "foo")
def testListEqualityComparison(self): self.assertNotEqual(self.example, [3, 4, 5]) # should not throw self.assertNotEqual([3, 4, 5], self.example) # should not throw
except TypeError: self.fail(msg)
function, "5") # should fail to convert even numeric strings # We should be able to coerce integers with different signedness and size to any numeric # type argument (as long as we don't trigger overflow) msg="Failure passing numpy.%s to %s" % (name, function.__name__))
"""If we pass an integer that doesn't fit in the C++ argument type, we should raise OverflowError""" self.checkNumeric(function) tooBig = 2**(size + 1) self.assertRaises(OverflowError, function, tooBig)
"""Test our customized numeric scalar typemaps, including support for NumPy scalars."""
def testExtendedIntegers(self): for size in (8, 16, 32, 64): self.checkInteger(getattr(_example, "accept_int%d" % size), size) self.checkInteger(getattr(_example, "accept_uint%d" % size), size) self.checkInteger(getattr(_example, "accept_cref_int%d" % size), size) self.checkInteger(getattr(_example, "accept_cref_uint%d" % size), size) # Test that we choose the floating point overload when we pass a float, # and we get the integer overload when we pass an int. # We can't ever distinguish between different kinds of ints or different # kinds of floats in an overloading context, but that's a Pybind11 limitation.
"""Test the 1-axis (2 argument) version of cppIndex """ # loop over various sizes # note that when size == 0 no indices are valid, but the "invalid indices" tests still run # loop over all valid indices # the negative index that points to the same element as ind # for example if size = 3 and ind = 2 then negind = -1
# invalid indices (the two closest to zero)
"""Test the 2-axis (4 argument) version of cppindex """ # loop over various sizes # if either size is 0 then no pairs of indices are valid, # but the "both indices invalid" tests still run # the first (closest to 0) invalid negative indices
# loop over all valid indices # negative indices that point to the same element as the positive index
# both indeces valid
# one index invalid
# both indices invalid (just test the invalid indices closest to 0)
setup_module(sys.modules[__name__]) unittest.main() |