diff --git a/bob/io/base/hdf5.cpp b/bob/io/base/hdf5.cpp index cd9635188b2a534f916d72ed9fe82446664e44ad..d909e544b2433c30bd1d7520029ecec983fcf5b7 100644 --- a/bob/io/base/hdf5.cpp +++ b/bob/io/base/hdf5.cpp @@ -166,7 +166,9 @@ BOB_CATCH_MEMBER("hdf5 constructor", -1) static PyObject* PyBobIoHDF5File_repr(PyBobIoHDF5FileObject* self) { +BOB_TRY return PyString_FromFormat("%s(filename='%s')", Py_TYPE(self)->tp_name, self->f->filename().c_str()); +BOB_CATCH_MEMBER("__repr__", 0) } diff --git a/bob/io/base/test_hdf5.py b/bob/io/base/test_hdf5.py index 39ef7d1520678b54d78db9283907ca7e2fac7c11..376e2659f2f2a0b5120a320b340f73cee1677b74 100644 --- a/bob/io/base/test_hdf5.py +++ b/bob/io/base/test_hdf5.py @@ -458,6 +458,7 @@ def test_copy_constructor(): assert hdf5.filename != deep.filename assert hdf5.keys() != deep.keys() assert hdf5.cwd != deep.cwd + assert str(shallow) hdf5.cd("..") @@ -475,6 +476,9 @@ def test_copy_constructor(): def test_filename(): fn = shallow.filename nose.tools.assert_raises(RuntimeError, test_filename) + def test_repr(): + fn = str(shallow) + nose.tools.assert_raises(RuntimeError, test_repr) finally: os.unlink(tmpname)