mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 04:22:16 +00:00
Moved to python_v2_API_restructure branch
[SVN r15354]
This commit is contained in:
93
test/Jamfile
93
test/Jamfile
@@ -54,98 +54,5 @@ rule bpl-test ( name ? : files * )
|
||||
boost-python-runtest $(name) : $(py) <pyd>$(modules) ;
|
||||
}
|
||||
|
||||
bpl-test enum ;
|
||||
bpl-test minimal ;
|
||||
bpl-test docstring ;
|
||||
bpl-test exception_translator ;
|
||||
bpl-test pearu1 : test_cltree.py cltree.cpp ;
|
||||
bpl-test try : newtest.py m1.cpp m2.cpp ;
|
||||
bpl-test builtin_converters : test_builtin_converters.py test_builtin_converters.cpp ;
|
||||
bpl-test test_pointer_adoption ;
|
||||
bpl-test operators ;
|
||||
bpl-test callbacks ;
|
||||
bpl-test defaults ;
|
||||
|
||||
bpl-test object ;
|
||||
bpl-test list ;
|
||||
bpl-test long ;
|
||||
bpl-test dict ;
|
||||
bpl-test tuple ;
|
||||
bpl-test str ;
|
||||
|
||||
bpl-test virtual_functions ;
|
||||
bpl-test back_reference ;
|
||||
bpl-test implicit ;
|
||||
bpl-test data_members ;
|
||||
|
||||
bpl-test bienstman1 ;
|
||||
bpl-test bienstman2 ;
|
||||
bpl-test bienstman3 ;
|
||||
bpl-test multi_arg_constructor ;
|
||||
bpl-test iterator : iterator.py iterator.cpp input_iterator.cpp ;
|
||||
|
||||
bpl-test extract ;
|
||||
|
||||
bpl-test pickle1 ;
|
||||
bpl-test pickle2 ;
|
||||
bpl-test pickle3 ;
|
||||
|
||||
bpl-test nested ;
|
||||
|
||||
if $(TEST_BIENSTMAN_NON_BUGS)
|
||||
{
|
||||
bpl-test bienstman4 ;
|
||||
bpl-test bienstman5 ;
|
||||
}
|
||||
|
||||
# --- unit tests of library components ---
|
||||
|
||||
local UNIT_TEST_PROPERTIES =
|
||||
[ difference $(PYTHON_PROPERTIES) : <define>BOOST_PYTHON_DYNAMIC_LIB ] <define>BOOST_PYTHON_STATIC_LIB ;
|
||||
|
||||
run indirect_traits_test.cpp ;
|
||||
run destroy_test.cpp ;
|
||||
run pointer_type_id_test.cpp <lib>../../test/build/test_exec_monitor : : : $(UNIT_TEST_PROPERTIES) ;
|
||||
run member_function_cast.cpp ;
|
||||
run bases.cpp ;
|
||||
run if_else.cpp ;
|
||||
run pointee.cpp ;
|
||||
run result.cpp ;
|
||||
|
||||
compile string_literal.cpp ;
|
||||
compile borrowed.cpp : $(UNIT_TEST_PROPERTIES) ;
|
||||
compile object_manager.cpp : $(UNIT_TEST_PROPERTIES) ;
|
||||
|
||||
run upcast.cpp <lib>../../test/build/test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
;
|
||||
|
||||
run select_holder.cpp <lib>../../test/build/test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
;
|
||||
|
||||
|
||||
run select_from_python_test.cpp ../src/converter/type_id.cpp <lib>../../test/build/test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
;
|
||||
|
||||
run select_arg_to_python_test.cpp ../src/converter/type_id.cpp <lib>../../test/build/test_exec_monitor
|
||||
: # command-line args
|
||||
: # input files
|
||||
: $(UNIT_TEST_PROPERTIES)
|
||||
;
|
||||
|
||||
if $(TEST_EXPECTED_FAILURES)
|
||||
{
|
||||
compile-fail ./raw_pyobject_fail1.cpp : $(PYTHON_PROPERTIES) ;
|
||||
compile-fail ./raw_pyobject_fail2.cpp : $(PYTHON_PROPERTIES) ;
|
||||
compile-fail ./object_fail1.cpp : $(PYTHON_PROPERTIES) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -93,12 +93,12 @@ BOOST_PYTHON_MODULE_INIT(back_reference_ext)
|
||||
def("copy_Z", copy_Z, return_value_policy<copy_const_reference>());
|
||||
def("x_instances", &X::count);
|
||||
|
||||
class_<Y>("Y", args<int>())
|
||||
class_<Y>("Y", init<int>())
|
||||
.def("value", &Y::value)
|
||||
.def("set", &Y::set)
|
||||
;
|
||||
|
||||
class_<Z,std::auto_ptr<Z> >("Z", args<int>())
|
||||
class_<Z,std::auto_ptr<Z> >("Z", init<int>())
|
||||
.def("value", &Z::value)
|
||||
.def("set", &Z::set)
|
||||
;
|
||||
|
||||
@@ -17,6 +17,6 @@ BOOST_PYTHON_MODULE_INIT(bienstman3_ext)
|
||||
using namespace boost::python;
|
||||
|
||||
class_<V, boost::noncopyable>("V", no_init);
|
||||
class_<B>("B", args<const V&>());
|
||||
class_<B>("B", init<const V&>());
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ BOOST_PYTHON_MODULE_INIT(bienstman4_ext)
|
||||
class_<Type1>("T1")
|
||||
;
|
||||
|
||||
class_<Term>("Term", args<Type1&>())
|
||||
class_<Term>("Term", init<Type1&>())
|
||||
;
|
||||
|
||||
Type1 t1;
|
||||
|
||||
@@ -17,7 +17,7 @@ BOOST_PYTHON_MODULE_INIT(bienstman5_ext)
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
||||
class_<M>("M", args<std::complex<double> const&>())
|
||||
class_<M>("M", init<std::complex<double> const&>())
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,8 +137,8 @@ BOOST_PYTHON_MODULE_INIT(callbacks_ext)
|
||||
def("apply_to_string_literal", apply_to_string_literal);
|
||||
|
||||
|
||||
class_<X>("X", args<int>())
|
||||
.def_init(args<X const&>())
|
||||
class_<X>("X", init<int>())
|
||||
.def(init<X const&>())
|
||||
.def("value", &X::value)
|
||||
.def("set", &X::set)
|
||||
;
|
||||
|
||||
@@ -32,20 +32,20 @@ public:
|
||||
|
||||
class symbol_wrapper: public symbol {
|
||||
public:
|
||||
symbol_wrapper(PyObject* self): symbol() {
|
||||
name = "cltree.wrapped_symbol";
|
||||
symbol_wrapper(PyObject* self): symbol() {
|
||||
name = "cltree.wrapped_symbol";
|
||||
}
|
||||
};
|
||||
|
||||
class variable_wrapper: public variable {
|
||||
public:
|
||||
variable_wrapper(PyObject* self): variable() {
|
||||
variable_wrapper(PyObject* self): variable() {
|
||||
name = "cltree.wrapped_variable";
|
||||
}
|
||||
|
||||
// This constructor is introduced only because cannot use
|
||||
// boost::noncopyable, see below.
|
||||
variable_wrapper(PyObject* self,variable v): variable(v) {}
|
||||
variable_wrapper(PyObject* self,variable v): variable(v) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -22,14 +22,14 @@ double get_fair_value(X const& x) { return x.value(); }
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(data_members_ext)
|
||||
{
|
||||
class_<X>("X", args<int>())
|
||||
class_<X>("X", init<int>())
|
||||
.def("value", &X::value)
|
||||
.def("set", &X::set)
|
||||
.def_readonly("x", &X::x)
|
||||
.add_property("fair_value", &get_fair_value)
|
||||
;
|
||||
|
||||
class_<Y>("Y", args<int>())
|
||||
class_<Y>("Y", init<int>())
|
||||
.def("value", &Y::value)
|
||||
.def("set", &Y::set)
|
||||
.def_readwrite("x", &Y::x)
|
||||
|
||||
@@ -158,25 +158,17 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
|
||||
.def("barfoo", (object(*)(int, char, std::string, double))0, bar_stubs())
|
||||
;
|
||||
|
||||
class_<Y>("Y", no_init)
|
||||
class_<Y>("Y", init<>("doc of Y init")) // this should work
|
||||
.def("get_state", &Y::get_state)
|
||||
;
|
||||
|
||||
class_<X>("X")
|
||||
|
||||
# if (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
|
||||
.def(init<int, optional<char, std::string, double> >())
|
||||
.def(init<std::string, bool>())
|
||||
# else
|
||||
.def_init(args<int>())
|
||||
.def_init(args<int, char>())
|
||||
.def_init(args<int, char, std::string>())
|
||||
.def_init(args<int, char, std::string, double>())
|
||||
.def_init(args<std::string, bool>())
|
||||
# endif
|
||||
.def(init<int, optional<char, std::string, double> >("doc of init"))
|
||||
.def(init<std::string, bool>()[default_call_policies()]) // what's a good policy here?
|
||||
.def("get_state", &X::get_state)
|
||||
.def("bar", &X::bar, X_bar_stubs())
|
||||
.def("bar2", &X::bar2, X_bar_stubs2(), return_internal_reference<>())
|
||||
.def("bar2", &X::bar2, X_bar_stubs2("doc of X::bar2")[return_internal_reference<>()])
|
||||
.def("foo", (object(X::*)(std::string, bool) const)0, X_foo_2_stubs())
|
||||
.def("foo", (object(X::*)(int, bool) const)0, X_foo_2_stubs())
|
||||
.def("foo", (object(X::*)(list, list, bool) const)0, X_foo_3_stubs())
|
||||
|
||||
@@ -36,23 +36,24 @@ BOOST_PYTHON_MODULE_INIT(docstring_ext)
|
||||
"A simple test module for documentation strings\n"
|
||||
"Exercised by docstring.py"
|
||||
;
|
||||
|
||||
|
||||
class_<X>("X",
|
||||
"A simple class wrapper around a C++ int\n"
|
||||
"includes some error-checking"
|
||||
|
||||
, args<int>(),
|
||||
"this is the __init__ function\n"
|
||||
"its documentation has two lines."
|
||||
|
||||
, init<int>(
|
||||
"this is the __init__ function\n"
|
||||
"its documentation has two lines."
|
||||
)
|
||||
|
||||
)
|
||||
.def("value", &X::value,
|
||||
"gets the value of the object")
|
||||
;
|
||||
|
||||
|
||||
def("create", create, return_value_policy<manage_new_object>(),
|
||||
"creates a new X object");
|
||||
|
||||
|
||||
def("fact", fact, "compute the factorial");
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ BOOST_PYTHON_MODULE_INIT(extract_ext)
|
||||
;
|
||||
|
||||
object x_class(
|
||||
class_<X>("X", args<int>())
|
||||
class_<X>("X", init<int>())
|
||||
.def( "__repr__", x_rep));
|
||||
|
||||
// Instantiate an X object through the Python interface
|
||||
|
||||
@@ -27,7 +27,7 @@ BOOST_PYTHON_MODULE_INIT(implicit_ext)
|
||||
def("x_value", x_value);
|
||||
def("make_x", make_x);
|
||||
|
||||
class_<X>("X", args<int>())
|
||||
class_<X>("X", init<int>())
|
||||
.def("value", &X::value)
|
||||
.def("set", &X::set)
|
||||
;
|
||||
|
||||
@@ -138,7 +138,7 @@ BOOST_PYTHON_MODULE_INIT(list_ext)
|
||||
|
||||
def("exercise", exercise);
|
||||
|
||||
class_<X>("X", args<int>())
|
||||
class_<X>("X", init<int>())
|
||||
.def( "__repr__", x_rep)
|
||||
;
|
||||
}
|
||||
|
||||
18
test/m1.cpp
18
test/m1.cpp
@@ -96,7 +96,7 @@ PyObject* new_simple()
|
||||
|
||||
//
|
||||
// Declare some wrappers/unwrappers to test the low-level conversion
|
||||
// mechanism.
|
||||
// mechanism.
|
||||
//
|
||||
using boost::python::to_python_converter;
|
||||
|
||||
@@ -200,7 +200,7 @@ BOOST_PYTHON_MODULE_INIT(m1)
|
||||
{
|
||||
using namespace boost::python;
|
||||
using boost::shared_ptr;
|
||||
|
||||
|
||||
simple_to_python();
|
||||
|
||||
lvalue_from_pytype<int_from_noddy,&NoddyType>();
|
||||
@@ -208,14 +208,14 @@ BOOST_PYTHON_MODULE_INIT(m1)
|
||||
lvalue_from_pytype<
|
||||
#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 // doesn't support non-type member pointer parameters
|
||||
extract_member<SimpleObject, simple, &SimpleObject::x>
|
||||
#else
|
||||
#else
|
||||
extract_simple_object
|
||||
#endif
|
||||
#endif
|
||||
, &SimpleType
|
||||
>();
|
||||
|
||||
lvalue_from_pytype<extract_identity<SimpleObject>,&SimpleType>();
|
||||
|
||||
|
||||
def("new_noddy", new_noddy);
|
||||
def("new_simple", new_simple);
|
||||
|
||||
@@ -226,7 +226,7 @@ BOOST_PYTHON_MODULE_INIT(m1)
|
||||
def("f_const_ptr", f_const_ptr);
|
||||
|
||||
def("f2", f2);
|
||||
|
||||
|
||||
// Expose g()
|
||||
def("g", g , return_value_policy<copy_const_reference>()
|
||||
);
|
||||
@@ -249,7 +249,7 @@ BOOST_PYTHON_MODULE_INIT(m1)
|
||||
class_<B,bases<A>, shared_ptr<B> >("B")
|
||||
.def("name", &B::name)
|
||||
;
|
||||
|
||||
|
||||
class_<C,bases<A>, shared_ptr<C> >("C")
|
||||
.def("name", &C::name)
|
||||
;
|
||||
@@ -259,8 +259,8 @@ BOOST_PYTHON_MODULE_INIT(m1)
|
||||
;
|
||||
|
||||
class_<complicated>("complicated",
|
||||
args<simple const&,int>())
|
||||
.def_init(args<simple const&>())
|
||||
init<simple const&,int>())
|
||||
.def(init<simple const&>())
|
||||
.def("get_n", &complicated::get_n)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ BOOST_PYTHON_MODULE_INIT(multi_arg_constructor_ext)
|
||||
|
||||
class_<A, shared_ptr<A> >(
|
||||
"A"
|
||||
, args<double, double, double, double, double, double, double, double, double>()
|
||||
, init<double, double, double, double, double, double, double, double, double>()
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ BOOST_PYTHON_MODULE_INIT(nested_ext)
|
||||
|
||||
// Establish X as the current scope.
|
||||
scope x_class(
|
||||
class_<X>("X", args<int>())
|
||||
class_<X>("X", init<int>())
|
||||
.def(str(self))
|
||||
);
|
||||
|
||||
// Y will now be defined in the current scope
|
||||
class_<Y>("Y", args<int>())
|
||||
class_<Y>("Y", init<int>())
|
||||
.def(str(self))
|
||||
;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ std::ostream& operator<<(std::ostream& s, X const& x)
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(operators_ext)
|
||||
{
|
||||
class_<X>("X", args<int>())
|
||||
class_<X>("X", init<int>())
|
||||
.def("value", &X::value)
|
||||
.def(self - self)
|
||||
.def(self - int())
|
||||
@@ -77,7 +77,7 @@ BOOST_PYTHON_MODULE_INIT(operators_ext)
|
||||
.def(pow(int(),self))
|
||||
;
|
||||
|
||||
class_<test_class<1> >("Z", args<int>())
|
||||
class_<test_class<1> >("Z", init<int>())
|
||||
.def(int_(self))
|
||||
.def(float_(self))
|
||||
.def(complex_(self))
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace {
|
||||
BOOST_PYTHON_MODULE_INIT(pickle1_ext)
|
||||
{
|
||||
using namespace boost::python;
|
||||
class_<world>("world", args<const std::string&>())
|
||||
class_<world>("world", init<const std::string&>())
|
||||
.def("greet", &world::greet)
|
||||
.def_pickle(world_pickle_suite())
|
||||
;
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace { // Avoid cluttering the global namespace.
|
||||
BOOST_PYTHON_MODULE_INIT(pickle2_ext)
|
||||
{
|
||||
boost::python::class_<world>(
|
||||
"world", boost::python::args<const std::string&>())
|
||||
"world", boost::python::init<const std::string&>())
|
||||
.def("greet", &world::greet)
|
||||
.def("get_secret_number", &world::get_secret_number)
|
||||
.def("set_secret_number", &world::set_secret_number)
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace { // Avoid cluttering the global namespace.
|
||||
BOOST_PYTHON_MODULE_INIT(pickle3_ext)
|
||||
{
|
||||
boost::python::class_<world>(
|
||||
"world", boost::python::args<const std::string&>())
|
||||
"world", boost::python::init<const std::string&>())
|
||||
.def("greet", &world::greet)
|
||||
.def("get_secret_number", &world::get_secret_number)
|
||||
.def("set_secret_number", &world::set_secret_number)
|
||||
|
||||
@@ -26,7 +26,7 @@ struct inner
|
||||
{
|
||||
this->s = new_s;
|
||||
}
|
||||
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
@@ -42,7 +42,7 @@ struct A : Base
|
||||
{
|
||||
++a_instances;
|
||||
}
|
||||
|
||||
|
||||
~A()
|
||||
{
|
||||
--a_instances;
|
||||
@@ -65,7 +65,7 @@ struct B
|
||||
{
|
||||
B() : x(0) {}
|
||||
B(A* x_) : x(x_) {}
|
||||
|
||||
|
||||
inner const* adopt(A* x) { this->x = x; return &x->get_inner(); }
|
||||
|
||||
std::string a_content()
|
||||
@@ -96,29 +96,29 @@ BOOST_PYTHON_MODULE_INIT(test_pointer_adoption_ext)
|
||||
def("create", create, return_value_policy<manage_new_object>());
|
||||
|
||||
def("as_A", as_A, return_internal_reference<>());
|
||||
|
||||
|
||||
class_<Base>("Base")
|
||||
;
|
||||
|
||||
class_<A, bases<Base> >(no_init)
|
||||
|
||||
class_<A, bases<Base> >("A", no_init)
|
||||
.def("content", &A::content)
|
||||
.def("get_inner", &A::get_inner, return_internal_reference<>())
|
||||
;
|
||||
|
||||
class_<inner>(no_init)
|
||||
|
||||
class_<inner>("inner", no_init)
|
||||
.def("change", &inner::change)
|
||||
;
|
||||
|
||||
|
||||
class_<B>("B")
|
||||
.def_init(args<A*>(), with_custodian_and_ward_postcall<1,2>())
|
||||
|
||||
.def(init<A*>()[with_custodian_and_ward_postcall<1,2>()])
|
||||
|
||||
.def("adopt", &B::adopt
|
||||
// Adopt returns a pointer referring to a subobject of its 2nd argument (1st being "self")
|
||||
, return_internal_reference<2
|
||||
// Meanwhile, self holds a reference to the 2nd argument.
|
||||
, with_custodian_and_ward<1,2> >()
|
||||
)
|
||||
|
||||
|
||||
.def("a_content", &B::a_content)
|
||||
;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ int X::counter;
|
||||
|
||||
BOOST_PYTHON_MODULE_INIT(virtual_functions_ext)
|
||||
{
|
||||
class_<concrete, concrete_callback>("concrete", args<int>())
|
||||
class_<concrete, concrete_callback>("concrete", init<int>())
|
||||
.def("value", &concrete::value)
|
||||
.def("set", &concrete::set)
|
||||
.def("call_f", &concrete::call_f)
|
||||
@@ -97,14 +97,14 @@ BOOST_PYTHON_MODULE_INIT(virtual_functions_ext)
|
||||
;
|
||||
|
||||
class_<abstract, boost::noncopyable, boost::shared_ptr<abstract_callback>
|
||||
>("abstract", args<int>())
|
||||
>("abstract", init<int>())
|
||||
|
||||
.def("value", &abstract::value)
|
||||
.def("call_f", &abstract::call_f)
|
||||
.def("set", &abstract::set)
|
||||
;
|
||||
|
||||
class_<Y>("Y", args<int>())
|
||||
class_<Y>("Y", init<int>())
|
||||
.def("value", &Y::value)
|
||||
.def("set", &Y::set)
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user