diff --git a/setup.py b/setup.py index eafe0729934582a5711bf237d5d3f07e0791ee73..7afc0cc6e73a737c23538927e3c66b5dddc64c40 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ package_dir = os.path.dirname(os.path.realpath(__file__)) package_dir = os.path.join(package_dir, 'xbob', 'io', 'include') include_dirs = [package_dir] -packages = ['bob-io >= 1.3'] +packages = ['bob-io >= 1.2.2'] version = '2.0.0a0' setup( diff --git a/xbob/io/hdf5.cpp b/xbob/io/hdf5.cpp index 0ff06035883b008c1eb4857763ad79d63a454808..c1761d4b0860801de38118a829f6591616e064fe 100644 --- a/xbob/io/hdf5.cpp +++ b/xbob/io/hdf5.cpp @@ -76,6 +76,23 @@ static void PyBobIoHDF5File_Delete (PyBobIoHDF5FileObject* o) { } +static bob::io::HDF5File::mode_t mode_from_char (char mode) { + + bob::io::HDF5File::mode_t new_mode = bob::io::HDF5File::inout; + + switch (mode) { + case 'r': new_mode = bob::io::HDF5File::in; break; + case 'a': new_mode = bob::io::HDF5File::inout; break; + case 'w': new_mode = bob::io::HDF5File::trunc; break; + case 'x': new_mode = bob::io::HDF5File::excl; break; + default: + PyErr_SetString(PyExc_RuntimeError, "Supported flags are 'r' (read-only), 'a' (read/write/append), 'w' (read/write/truncate) or 'x' (read/write/exclusive)"); + } + + return new_mode; + +} + /* The __init__(self) method */ static int PyBobIoHDF5File_Init(PyBobIoHDF5FileObject* self, PyObject *args, PyObject* kwds) { @@ -106,6 +123,8 @@ static int PyBobIoHDF5File_Init(PyBobIoHDF5FileObject* self, PyErr_Format(PyExc_ValueError, "file open mode string should have 1 element and be either 'r' (read), 'w' (write), 'a' (append), 'x' (exclusive)"); return -1; } + bob::io::HDF5File::mode_t mode_mode = mode_from_char(mode); + if (PyErr_Occurred()) return -1; #if PY_VERSION_HEX >= 0x03000000 const char* c_filename = PyBytes_AS_STRING(filename); @@ -114,7 +133,7 @@ static int PyBobIoHDF5File_Init(PyBobIoHDF5FileObject* self, #endif try { - self->f.reset(new bob::io::HDF5File(c_filename, mode)); + self->f.reset(new bob::io::HDF5File(c_filename, mode_mode)); } catch (std::exception& e) { PyErr_SetString(PyExc_RuntimeError, e.what()); diff --git a/xbob/io/test_hdf5.py b/xbob/io/test_hdf5.py index 92e47697ffa2c7cb0c42414b8d09a1b8d1a0245c..6f499b8c747929de811a3ed97ace299d97879672 100644 --- a/xbob/io/test_hdf5.py +++ b/xbob/io/test_hdf5.py @@ -15,6 +15,7 @@ import random import nose.tools from . import HDF5File, load, save, peek_all, test_utils +from .test_utils import bob_at_least def read_write_check(outfile, dname, data, dtype=None): """Tests scalar input/output on HDF5 files""" @@ -313,6 +314,7 @@ def test_string_support(): del outfile os.unlink(tmpname) +@bob_at_least('1.3.0a0') def test_string_attribute_support(): try: diff --git a/xbob/io/test_utils.py b/xbob/io/test_utils.py index f57e9c5cc9a69971f1f0d05b9ad525184f8e3414..103b9e7700e541999bd29a4895cc192cfa3a8f46 100644 --- a/xbob/io/test_utils.py +++ b/xbob/io/test_utils.py @@ -117,6 +117,31 @@ def ffmpeg_found(version_geq=None): return test_wrapper +def bob_at_least(version_geq): + '''Decorator to check if at least a certain version of Bob is installed + + To use this, decorate your test routine with something like: + + .. code-block:: python + + @bob_at_least('1.2.2') + + ''' + + def test_wrapper(test): + + @functools.wraps(test) + def wrapper(*args, **kwargs): + from .version import externals + inst = SV(externals['Bob'][0]) + if inst < version_geq: + raise nose.plugins.skip.SkipTest('Bob version installed (%s) is smaller than required for this test (%s)' % (externals['Bob'][0], version_geq)) + return test(*args, **kwargs) + + return wrapper + + return test_wrapper + def codec_available(codec): '''Decorator to check if a codec is available before enabling a test''' diff --git a/xbob/io/version.cpp b/xbob/io/version.cpp index 4a014f3f2321b3794ea963d73c98ef380965bd76..b09108755b67516f493ca1976cc9f278886d7562 100644 --- a/xbob/io/version.cpp +++ b/xbob/io/version.cpp @@ -276,12 +276,21 @@ static PyObject* matio_version() { #endif } +/** + * Bob version, API version and platform + */ +static PyObject* bob_version() { + return Py_BuildValue("sis", BOB_VERSION, BOB_API_VERSION, BOB_PLATFORM); +} + static PyObject* build_version_dictionary() { PyObject* retval = PyDict_New(); if (!retval) return 0; auto retval_ = make_safe(retval); + if (!dict_steal(retval, "Bob", bob_version())) return 0; + if (!dict_steal(retval, "HDF5", hdf5_version())) return 0; if (!dict_steal(retval, "FFmpeg", ffmpeg_version())) return 0;