Commit 61719634 authored by Manuel Günther's avatar Manuel Günther
Browse files

Implemented C++ test case (still working) using HDF5 interface

parent 24627630
Pipeline #3681 failed with stage
in 36 minutes and 18 seconds
......@@ -8,26 +8,55 @@
#include <bob.io.base/api.h>
#include <bob.extension/documentation.h>
#include <boost/format.hpp>
#include <boost/filesystem.hpp>
static auto s_test_api = bob::extension::FunctionDoc(
"_test_api",
"Some tests for API functions"
)
.add_prototype("");
static PyObject* _test_api(PyObject*){
.add_prototype("tempdir")
.add_parameter("tempdir", "str", "A temporary directory to write data to")
;
static PyObject* _test_api(PyObject*, PyObject *args, PyObject* kwds){
BOB_TRY
static char** kwlist = s_test_api.kwlist();
const char* tempdir;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s", kwlist, &tempdir)) return 0;
blitz::Array<uint8_t, 1> test_data(5);
for (int i = 0; i < 5; ++i){
test_data(i) = i+1;
}
auto h5file = bob::io::base::CodecRegistry::instance()->findByExtension(".hdf5");
boost::filesystem::path hdf5(tempdir); hdf5 /= std::string("test.h5");
auto output = h5file(hdf5.string().c_str(), 'w');
output->write(test_data);
output.reset();
auto input = h5file(hdf5.string().c_str(), 'r');
blitz::Array<uint8_t,1> read_data = input->read<uint8_t,1>(0);
input.reset();
if (blitz::any(test_data - read_data))
throw std::runtime_error("The CSV IO test did not succeed");
Py_RETURN_NONE;
BOB_CATCH_FUNCTION("_test_api", 0)
}
static PyMethodDef module_methods[] = {
{
s_test_api.name(),
(PyCFunction)_test_api,
METH_NOARGS,
s_test_api.doc(),
},
{0} /* Sentinel */
{
s_test_api.name(),
(PyCFunction)_test_api,
METH_VARARGS|METH_KEYWORDS,
s_test_api.doc(),
},
{0} /* Sentinel */
};
PyDoc_STRVAR(module_docstr, "Tests for bob::io::base");
......
from ._test import _test_api
from bob.io.base._test import _test_api
def test_cpp():
_test_api()
import tempfile
import shutil
def test_api():
temp_dir = tempfile.mkdtemp()
try:
_test_api(temp_dir)
finally:
shutil.rmtree(temp_dir)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment