2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 04:22:16 +00:00

Remove obsolete tests.

This commit is contained in:
Stefan Seefeld
2016-10-08 15:29:56 -04:00
parent 69ddfcae17
commit 4ce4821111
5 changed files with 0 additions and 338 deletions

View File

@@ -1,63 +0,0 @@
# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import printer
# So we can coerce portably across Python versions
bool = type(1 == 1)
'''
>>> from numpy_ext import *
>>> x = new_array()
>>> y = x.copy()
>>> p = _printer()
>>> check = p.check
>>> exercise_numarray(x, p)
>>> check(str(y))
>>> check(y.argmax());
>>> check(y.argmax(0));
>>> check(y.argmin());
>>> check(y.argmin(0));
>>> check(y.argsort());
>>> check(y.argsort(1));
>>> y.byteswap();
>>> check(y);
>>> check(y.diagonal());
>>> check(y.diagonal(1));
>>> check(y.diagonal(0, 0));
>>> check(y.diagonal(0, 1, 0));
>>> check(y.is_c_array());
# coerce because numarray still returns an int and the C++ interface forces
# the return type to bool
>>> check( bool(y.isbyteswapped()) );
>>> check(y.trace());
>>> check(y.trace(1));
>>> check(y.trace(0, 0));
>>> check(y.trace(0, 1, 0));
>>> check(y.new('D').getshape());
>>> check(y.new('D').type());
>>> y.sort();
>>> check(y);
>>> check(y.type());
>>> check(y.factory((1.2, 3.4)));
>>> check(y.factory((1.2, 3.4), "f8"))
>>> check(y.factory((1.2, 3.4), "f8", true))
>>> check(y.factory((1.2, 3.4), "f8", true, false))
>>> check(y.factory((1.2, 3.4), "f8", true, false, None))
>>> check(y.factory((1.2, 3.4), "f8", true, false, None, (1,2,1)))
>>> p.results
[]
>>> del p
'''

View File

@@ -1,39 +0,0 @@
# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
import printer
'''
>>> from numpy_ext import *
>>> x = new_array()
>>> x[1,1] = 0.0
>>> try: take_array(3)
... except TypeError: pass
... else: print('expected a TypeError')
>>> take_array(x)
>>> print(x)
[[1 2 3]
[4 0 6]
[7 8 9]]
>>> y = x.copy()
>>> p = _printer()
>>> check = p.check
>>> exercise(x, p)
>>> y[2,1] = 3
>>> check(y);
>>> check(y.astype('D'));
>>> check(y.copy());
>>> check(y.typecode());
>>> p.results
[]
>>> del p
'''

View File

@@ -1,136 +0,0 @@
// Copyright David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <boost/python/numeric.hpp>
#include <boost/python/tuple.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/str.hpp>
using namespace boost::python;
namespace py = boost::python;
// See if we can invoke array() from C++
numeric::array new_array()
{
return numeric::array(
py::make_tuple(
py::make_tuple(1,2,3)
, py::make_tuple(4,5,6)
, py::make_tuple(7,8,9)
)
);
}
// test argument conversion
void take_array(numeric::array /*x*/)
{
}
// A separate function to invoke the info() member. Must happen
// outside any doctests since this prints directly to stdout and the
// result text includes the address of the 'self' array.
void info(numeric::array const& z)
{
z.info();
}
namespace
{
object handle_error()
{
PyObject* type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback);
handle<> ty(type), v(value), tr(traceback);
return object("exception");
str format("exception type: %sn");
format += "exception value: %sn";
format += "traceback:n%s" ;
object ret = format % py::make_tuple(ty, v, tr);
return ret;
}
}
#define CHECK(expr) \
{ \
object result; \
try { result = object(expr); } \
catch(error_already_set) \
{ \
result = handle_error(); \
} \
check(result); \
}
// Tests which work on both Numeric and numarray array objects. Of
// course all of the operators "just work" since numeric::array
// inherits that behavior from object.
void exercise(numeric::array& y, object check)
{
y[py::make_tuple(2,1)] = 3;
CHECK(y);
CHECK(y.astype('D'));
CHECK(y.copy());
CHECK(y.typecode());
}
// numarray-specific tests. check is a callable object which we can
// use to record intermediate results, which are later compared with
// the results of corresponding python operations.
void exercise_numarray(numeric::array& y, object check)
{
CHECK(str(y));
CHECK(y.argmax());
CHECK(y.argmax(0));
CHECK(y.argmin());
CHECK(y.argmin(0));
CHECK(y.argsort());
CHECK(y.argsort(1));
y.byteswap();
CHECK(y);
CHECK(y.diagonal());
CHECK(y.diagonal(1));
CHECK(y.diagonal(0, 0));
CHECK(y.diagonal(0, 1, 0));
CHECK(y.is_c_array());
CHECK(y.isbyteswapped());
CHECK(y.trace());
CHECK(y.trace(1));
CHECK(y.trace(0, 0));
CHECK(y.trace(0, 1, 0));
CHECK(y.new_("D").getshape());
CHECK(y.new_("D").type());
y.sort();
CHECK(y);
CHECK(y.type());
CHECK(y.factory(py::make_tuple(1.2, 3.4)));
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8"));
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true));
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false));
CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object()));
CHECK (y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object(), py::make_tuple(1,2,1)));
}
BOOST_PYTHON_MODULE(numpy_ext)
{
def("new_array", new_array);
def("take_array", take_array);
def("exercise", exercise);
def("exercise_numarray", exercise_numarray);
def("set_module_and_type", &numeric::array::set_module_and_type);
def("get_module_name", &numeric::array::get_module_name);
def("info", info);
}
#include "module_tail.cpp"

View File

@@ -1,87 +0,0 @@
# Copyright David Abrahams 2004. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
false = 0;
true = 1;
import doctest, numeric_tests
def _count_failures(test_modules = (numeric_tests,)):
failures = 0
for m in test_modules:
failures += doctest.testmod(m)[0]
return failures
def _run(args = None):
import sys, numarray_tests, numeric_tests
if args is not None:
sys.argv = args
# See which of the numeric modules are installed
has_numeric = 0
try: import Numeric
except ImportError: pass
else:
has_numeric = 1
m = Numeric
has_numarray = 0
try: import numarray
except ImportError: pass
else:
has_numarray = 1
m = numarray
# Bail if neither one is installed
if not (has_numeric or has_numarray):
return 0
# test the info routine outside the doctest. See numpy.cpp for an
# explanation
import numpy_ext
if (has_numarray):
numpy_ext.info(m.array((1,2,3)))
failures = 0
#
# Run tests 4 different ways if both modules are installed, just
# to show that set_module_and_type() is working properly
#
# run all the tests with default module search
print('testing default extension module:', \
numpy_ext.get_module_name() or '[numeric support not installed]')
failures += _count_failures()
# test against Numeric if installed
if has_numeric:
print('testing Numeric module explicitly')
numpy_ext.set_module_and_type('Numeric', 'ArrayType')
failures += _count_failures()
if has_numarray:
print('testing numarray module explicitly')
numpy_ext.set_module_and_type('numarray', 'NDArray')
# Add the _numarray_tests to the list of things to test in
# this case.
failures += _count_failures((numarray_tests, numeric_tests))
# see that we can go back to the default
numpy_ext.set_module_and_type('', '')
print('testing default module again:', \
numpy_ext.get_module_name() or '[numeric support not installed]')
failures += _count_failures()
return failures
if __name__ == '__main__':
print("running...")
import sys
status = _run()
if (status == 0): print("Done.")
sys.exit(status)

View File

@@ -1,13 +0,0 @@
# Copyright David Abrahams 2006. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
class _printer(object):
def __init__(self):
self.results = [];
def __call__(self, *stuff):
for x in stuff:
self.results.append(str(x))
def check(self, x):
if self.results[0] != str(x):
print(' Expected:\n %s\n but the C++ interface gave:\n %s' % (x, self.results[0]))
del self.results[0]