Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / py / test / test_python.cpp
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_MODULE test_python
3 #include <boost/test/unit_test.hpp>
4
5 #include "py/python.hpp"
6 #include <string>
7
8 namespace py = boost::python;
9
10 BOOST_AUTO_TEST_CASE( execute_python )
11 {
12   get_py().run("x = 3");
13   int x = py::extract<int>(get_py().eval("x"));
14   BOOST_CHECK_EQUAL(x, 3);
15 }
16
17 BOOST_AUTO_TEST_CASE( lookup_python )
18 {
19   get_py().run("import os");
20   py::object splitext = get_py()["os.path.splitext"];
21   py::object result = splitext("/home/diane/foo.txt");
22   std::string ext = py::extract<std::string>(result[1]);
23   BOOST_CHECK_EQUAL(ext, ".txt");
24
25   get_py().run("from os.path import splitext");
26   py::object splitext2 = get_py()["splitext"];
27   py::object result2 = splitext("/home/diane/bar.txt");
28   std::string ext2 = py::extract<std::string>(result2[1]);
29   BOOST_CHECK_EQUAL(ext, ext2);
30 }