Skip to content

Commit bf824c1

Browse files
Tyler Kieftstefanseefeld
authored andcommitted
Ensure all doctests run
1 parent 01ab510 commit bf824c1

File tree

14 files changed

+88
-81
lines changed

14 files changed

+88
-81
lines changed

test/args.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Copyright David Abrahams 2004. Distributed under the Boost
22
# Software License, Version 1.0. (See accompanying
33
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4-
from __future__ import print_function
54
"""
65
>>> from args_ext import *
76
8-
>>> raw(3, 4, foo = 'bar', baz = 42)
9-
((3, 4), {'foo': 'bar', 'baz': 42})
7+
>>> args, kwargs = raw(3, 4, foo = 'bar', baz = 42)
8+
>>> args
9+
(3, 4)
10+
>>> kwargs['foo']
11+
'bar'
12+
>>> kwargs['baz']
13+
42
1014
1115
Prove that we can handle empty keywords and non-keywords
12-
16+
1317
>>> raw(3, 4)
1418
((3, 4), {})
1519
@@ -76,7 +80,7 @@
7680
... else: print('expected an exception: unknown keyword')
7781
7882
Exercise member functions using default stubs
79-
83+
8084
>>> q.f1(z = 'nix', y = .125, x = 2)
8185
(2, 0.125, 'nix')
8286
>>> q.f1(y = .125, x = 2)
@@ -123,10 +127,16 @@
123127
1
124128
125129
>>> y = Y(value = 33)
126-
>>> y.raw(this = 1, that = 'the other')[1]
127-
{'this': 1, 'that': 'the other'}
130+
>>> _, kwargs = y.raw(this = 1, that = 'the other')
131+
>>> kwargs['this']
132+
1
133+
>>> kwargs['that']
134+
'the other'
128135
129136
"""
137+
138+
from __future__ import print_function
139+
130140
def run(args = None):
131141
import sys
132142
import doctest
@@ -143,6 +153,3 @@ def run(args = None):
143153
import args_ext
144154
help(args_ext)
145155
sys.exit(status)
146-
147-
148-

test/dict.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ object new_dict()
2121
object data_dict()
2222
{
2323
dict tmp1;
24-
tmp1["key1"] = "value1";
2524

2625
dict tmp2;
2726
tmp2["key2"] = "value2";
2827
tmp1[1] = tmp2;
28+
29+
tmp1["key1"] = "value1";
30+
2931
return tmp1;
3032
}
3133

@@ -60,22 +62,20 @@ void work_with_dict(dict data1, dict data2)
6062
void test_templates(object print)
6163
{
6264
std::string key = "key";
63-
65+
6466
dict tmp;
65-
tmp[1] = "a test string";
66-
print(tmp.get(1));
67-
//print(tmp[1]);
6867
tmp[1.5] = 13;
6968
print(tmp.get(1.5));
69+
tmp[1] = "a test string";
70+
print(tmp.get(1));
7071
print(tmp.get(44));
7172
print(tmp);
7273
print(tmp.get(2,"default"));
7374
print(tmp.setdefault(3,"default"));
7475

7576
BOOST_ASSERT(!tmp.has_key(key));
76-
//print(tmp[3]);
7777
}
78-
78+
7979
BOOST_PYTHON_MODULE(dict_ext)
8080
{
8181
def("new_dict", new_dict);

test/dict.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright David Abrahams 2004. Distributed under the Boost
22
# Software License, Version 1.0. (See accompanying
33
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4-
from __future__ import print_function
54
"""
65
>>> from dict_ext import *
76
>>> def printer(*args):
@@ -22,22 +21,24 @@
2221
>>> print(dict_from_sequence([(1,1),(2,2),(3,3)]))
2322
{1: 1, 2: 2, 3: 3}
2423
>>> test_templates(printer) #doctest: +NORMALIZE_WHITESPACE
25-
a test string
2624
13
25+
a test string
2726
None
2827
{1.5: 13, 1: 'a test string'}
2928
default
3029
default
3130
"""
3231

32+
from __future__ import print_function
33+
3334
def run(args = None):
3435
import sys
3536
import doctest
3637

3738
if args is not None:
3839
sys.argv = args
3940
return doctest.testmod(sys.modules.get(__name__))
40-
41+
4142
if __name__ == '__main__':
4243
print("running...")
4344
import sys

test/fabscript

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@ src = module('..src')
2121
python_libs=python.instance().libs
2222
features |= runpath(src.bpl.path, base='')
2323

24-
def extension_test(name, ext=[], script=None, np=False,
24+
def extension_test(name, exts=[], script=None, numpy=False,
2525
features=features, condition=None):
2626
"""Create a Python extension test `name`.
2727
Arguments:
2828
* name: the name of the test.
29-
* ext: extensions to be compiled, <name> if none are given.
29+
* exts: extensions to be compiled, <name> if none are given.
3030
* script: the test script to execute, <name>.py if none is given.
31-
* np: if true, add boost_numpy to sources
31+
* numpy: if true, add boost_numpy to sources
3232
* features: pre-defined features
3333
* condition: any condition under which to run the test
3434
Return:
3535
* the test artefact"""
3636

3737
features=features.copy()
3838
extensions = []
39-
libs = [src.bnl, src.bpl] if np else [src.bpl]
40-
for e in ext or [name]:
41-
if type(e) is str: # build from a single source file
42-
n = e if e != name else e + '_ext'
43-
s = [e + '.cpp']
39+
libs = [src.bnl, src.bpl] if numpy else [src.bpl]
40+
for ext in exts or [name]:
41+
if type(ext) is str: # build from a single source file
42+
ext_name = ext if ext != name else ext + '_ext'
43+
sources = [ext + '.cpp']
4444
else: # build from a list of source files
45-
n = e[0] if e[0] != name else e[0] + '_ext'
46-
s = [n + '.cpp' for n in e]
47-
e = extension(n, s + libs, features=features)
48-
features |= pythonpath(e.path, base='')
49-
extensions.append(e)
45+
ext_name = ext[0] if ext[0] != name else ext[0] + '_ext'
46+
sources = [source + '.cpp' for source in ext]
47+
ext = extension(ext_name, sources + libs, features=features)
48+
features |= pythonpath(ext.path, base='')
49+
extensions.append(ext)
5050
if not script:
5151
script = name+'.py'
5252
return test(name, script, run=python.run, dependencies=extensions,
@@ -167,7 +167,7 @@ for t in ['numpy/dtype',
167167
'numpy/ndarray',
168168
'numpy/indexing',
169169
'numpy/shapes']:
170-
tests.append(extension_test(t, np=True,
170+
tests.append(extension_test(t, numpy=True,
171171
condition=set.define.contains('HAS_NUMPY')))
172172

173173
default = report('report', tests, fail_on_failures=True)

test/iterator.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright David Abrahams 2004. Distributed under the Boost
22
# Software License, Version 1.0. (See accompanying
33
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4-
from __future__ import print_function
54
'''
65
>>> from iterator_ext import *
76
>>> from input_iterator import *
@@ -25,7 +24,7 @@
2524
2625
Range2 wraps a transform_iterator which doubles the elements it
2726
traverses. This proves we can wrap input iterators
28-
27+
2928
>>> z2 = range2(x)
3029
>>> for y in z2:
3130
... print(y)
@@ -56,20 +55,23 @@
5655
>>> ll.push_back(x)
5756
>>> for a in ll: #doctest: +NORMALIZE_WHITESPACE
5857
... for b in a:
59-
... print(b, end='')
58+
... print(b, end=' ')
6059
... print('')
6160
...
6261
1 3 5
6362
1 3 5 7
6463
'''
64+
65+
from __future__ import print_function
66+
6567
def run(args = None):
6668
import sys
6769
import doctest
6870

6971
if args is not None:
7072
sys.argv = args
7173
return doctest.testmod(sys.modules.get(__name__))
72-
74+
7375
if __name__ == '__main__':
7476
print("running...")
7577
import sys

test/list.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright David Abrahams 2004. Distributed under the Boost
22
# Software License, Version 1.0. (See accompanying
33
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4-
from __future__ import print_function
54
'''
65
>>> from list_ext import *
76
@@ -41,7 +40,7 @@
4140
['h', 'e', 'l', 'l', 'o', '.']
4241
4342
tuples do not automatically convert to lists when passed as arguments
44-
43+
4544
>>> try: append_list(letters, (1,2))
4645
... except TypeError: pass
4746
... else: print('expected an exception')
@@ -51,7 +50,7 @@
5150
['h', 'e', 'l', 'l', 'o', '.', [1, 2]]
5251
5352
Check that subclass functions are properly called
54-
53+
5554
>>> class mylist(list):
5655
... def append(self, o):
5756
... list.append(self, o)
@@ -103,14 +102,16 @@
103102
['y', 'x', 'o', 'l', 'l', 'h', 'e', '.']
104103
'''
105104

105+
from __future__ import print_function
106+
106107
def run(args = None):
107108
import sys
108109
import doctest
109110

110111
if args is not None:
111112
sys.argv = args
112113
return doctest.testmod(sys.modules.get(__name__))
113-
114+
114115
if __name__ == '__main__':
115116
print("running...")
116117
import sys

test/long.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Copyright David Abrahams 2004. Distributed under the Boost
22
# Software License, Version 1.0. (See accompanying
33
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4-
import sys
5-
if (sys.version_info.major >= 3):
6-
long = int
74
'''
85
>>> from long_ext import *
96
>>> print(new_long())
@@ -20,6 +17,10 @@
2017
>>> x = Y(long(4294967295))
2118
'''
2219

20+
import sys
21+
if (sys.version_info.major >= 3):
22+
long = int
23+
2324
def run(args = None):
2425
import sys
2526
import doctest

test/map_indexing_suite.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright Joel de Guzman 2004. Distributed under the Boost
22
# Software License, Version 1.0. (See accompanying
33
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4-
from __future__ import print_function
54
'''
65
76
#####################################################################
@@ -25,17 +24,17 @@
2524
2625
# test that a string is implicitly convertible
2726
# to an X
28-
>>> x_value('bochi bochi')
27+
>>> x_value('bochi bochi')
2928
'gotya bochi bochi'
3029
3130
#####################################################################
3231
# Iteration
3332
#####################################################################
3433
>>> def print_xmap(xmap):
3534
... s = '[ '
36-
... for x in xmap:
35+
... for x in xmap:
3736
... s += repr(x)
38-
... s += ' '
37+
... s += ' '
3938
... s += ']'
4039
... print(s)
4140
@@ -135,7 +134,7 @@
135134
>>> assert not 12345 in xm
136135
137136
#####################################################################
138-
# Some references to the container elements
137+
# Some references to the container elements
139138
#####################################################################
140139
141140
>>> z0 = xm['joel']
@@ -156,7 +155,7 @@
156155
kiwi
157156
158157
#####################################################################
159-
# Delete some container element
158+
# Delete some container element
160159
#####################################################################
161160
162161
>>> del xm['tenji']
@@ -168,7 +167,7 @@
168167
[ (joel, apple) (kim, kiwi) (mariel, grape) ]
169168
170169
#####################################################################
171-
# Show that the references are still valid
170+
# Show that the references are still valid
172171
#####################################################################
173172
>>> z0 # proxy
174173
apple
@@ -199,7 +198,7 @@
199198
>>> print_xmap(tm)
200199
[ (joel, aaa) (kimpo, bbb) ]
201200
>>> for el in tm: #doctest: +NORMALIZE_WHITESPACE
202-
... print(el.key(), end='')
201+
... print(el.key(), end=' ')
203202
... dom = el.data()
204203
joel kimpo
205204
@@ -216,11 +215,12 @@
216215
4
217216
218217
#####################################################################
219-
# END....
218+
# END....
220219
#####################################################################
221220
222221
'''
223222

223+
from __future__ import print_function
224224

225225
def run(args = None):
226226
import sys
@@ -236,8 +236,3 @@ def run(args = None):
236236
status = run()[0]
237237
if (status == 0): print("Done.")
238238
sys.exit(status)
239-
240-
241-
242-
243-

0 commit comments

Comments
 (0)