Skip to content

Commit b77262b

Browse files
committed
Added nested class test
[SVN r14980]
1 parent 960ebb1 commit b77262b

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

test/Jamfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ bpl-test pickle1 ;
8888
bpl-test pickle2 ;
8989
bpl-test pickle3 ;
9090

91+
bpl-test nested ;
92+
9193
if $(TEST_BIENSTMAN_NON_BUGS)
9294
{
9395
bpl-test bienstman4 ;

test/nested.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#include <boost/python/module_init.hpp>
7+
#include <boost/python/class.hpp>
8+
#include <boost/python/operators.hpp>
9+
#include <boost/python/scope.hpp>
10+
#include "test_class.hpp"
11+
12+
typedef test_class<> X;
13+
typedef test_class<1> Y;
14+
15+
BOOST_PYTHON_MODULE_INIT(nested_ext)
16+
{
17+
using namespace boost::python;
18+
19+
// Establish X as the current scope.
20+
scope x_class(
21+
class_<X>("X", args<int>())
22+
.def(str(self))
23+
);
24+
25+
// Y will now be defined in the current scope
26+
class_<Y>("Y", args<int>())
27+
.def(str(self))
28+
;
29+
}
30+
31+
32+
#include "module_tail.cpp"
33+
34+
35+

test/nested.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'''
2+
>>> from nested_ext import *
3+
4+
>>> X
5+
<class 'nested_ext.X'>
6+
7+
>>> X.__module__
8+
'nested_ext'
9+
10+
>>> X.__name__
11+
'X'
12+
13+
>>> X.Y
14+
<class 'nested_ext.Y'>
15+
16+
>>> X.Y.__module__
17+
'nested_ext'
18+
19+
>>> X.Y.__name__
20+
'Y'
21+
22+
'''
23+
24+
def run(args = None):
25+
import sys
26+
import doctest
27+
28+
if args is not None:
29+
sys.argv = args
30+
return doctest.testmod(sys.modules.get(__name__))
31+
32+
if __name__ == '__main__':
33+
print "running..."
34+
import sys
35+
sys.exit(run()[0])

0 commit comments

Comments
 (0)