summaryrefslogtreecommitdiff
path: root/src/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/python')
-rw-r--r--src/python/gudhi/simplex_tree.pyx10
-rwxr-xr-xsrc/python/test/test_simplex_tree.py4
2 files changed, 11 insertions, 3 deletions
diff --git a/src/python/gudhi/simplex_tree.pyx b/src/python/gudhi/simplex_tree.pyx
index 8f760422..e1685ded 100644
--- a/src/python/gudhi/simplex_tree.pyx
+++ b/src/python/gudhi/simplex_tree.pyx
@@ -47,6 +47,7 @@ cdef class SimplexTree:
:returns: An empty or a copy simplex tree.
:rtype: SimplexTree
+ :raises TypeError: In case `other` is neither `None`, nor a `SimplexTree`.
:note: If the `SimplexTree` is a copy, it requires :func:`compute_persistence` to be launched again as the
persistence result is not copied.
"""
@@ -54,9 +55,12 @@ cdef class SimplexTree:
# The real cython constructor
def __cinit__(self, other = None):
cdef SimplexTree ostr
- if other and type(other) is SimplexTree:
- ostr = <SimplexTree> other
- self.thisptr = <intptr_t>(new Simplex_tree_interface_full_featured(dereference(ostr.get_ptr())))
+ if other:
+ if type(other) is SimplexTree:
+ ostr = <SimplexTree> other
+ self.thisptr = <intptr_t>(new Simplex_tree_interface_full_featured(dereference(ostr.get_ptr())))
+ else:
+ raise TypeError("`other` argument requires to be of type `SimplexTree`, or `None`.")
else:
self.thisptr = <intptr_t>(new Simplex_tree_interface_full_featured())
diff --git a/src/python/test/test_simplex_tree.py b/src/python/test/test_simplex_tree.py
index 2c2e09a2..a8180ce8 100755
--- a/src/python/test/test_simplex_tree.py
+++ b/src/python/test/test_simplex_tree.py
@@ -511,3 +511,7 @@ def test_simplex_tree_deep_copy_constructor():
# test double free
del st
del st_copy
+
+def test_simplex_tree_constructor_exception():
+ with pytest.raises(TypeError):
+ st = SimplexTree(other = "Construction from a string shall raise an exception")