From 43dbc112b3609b91da0eb37d47b9b3712c8e7abb Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Wed, 4 Jul 2018 23:51:42 +0200 Subject: [PATCH] fix python tests --- build/get_python_include.py | 2 +- examples/getting_started_listing_03.py | 6 +++++- examples/getting_started_listing_04.py | 7 +++++-- examples/guide_histogram_pickle.py | 7 +++++-- examples/guide_mixed_cpp_python.py | 7 +++++-- examples/guide_numpy_support.py | 8 ++++++-- examples/guide_python_axis_representation.py | 12 ++++++++---- examples/guide_python_histogram.py | 6 +++++- include/boost/histogram/detail/utility.hpp | 4 ++-- test/python_suite_test.py | 4 +++- 10 files changed, 45 insertions(+), 18 deletions(-) diff --git a/build/get_python_include.py b/build/get_python_include.py index d616d5cf..725d8252 100644 --- a/build/get_python_include.py +++ b/build/get_python_include.py @@ -1,3 +1,3 @@ from distutils import sysconfig import sys -sys.stdout.write(sysconfig.get_python_inc()) \ No newline at end of file +sys.stdout.write(sysconfig.get_python_inc() + "\n") diff --git a/examples/getting_started_listing_03.py b/examples/getting_started_listing_03.py index 733db994..332f622b 100644 --- a/examples/getting_started_listing_03.py +++ b/examples/getting_started_listing_03.py @@ -1,3 +1,7 @@ +import sys +import os +sys.path.append(os.getcwd()) + #[ getting_started_listing_03 import histogram as hg @@ -53,4 +57,4 @@ except ImportError: # [ 0 0 0 0 0 2 0 0 0 0 0 0] # [ 0 0 0 0 0 1 0 0 0 0 0 0]] -#] \ No newline at end of file +#] diff --git a/examples/getting_started_listing_04.py b/examples/getting_started_listing_04.py index 5132ab9a..ae428951 100644 --- a/examples/getting_started_listing_04.py +++ b/examples/getting_started_listing_04.py @@ -1,6 +1,9 @@ -#[ getting_started_listing_04 - from __future__ import print_function +import sys +import os +sys.path.append(os.getcwd()) + +#[ getting_started_listing_04 import histogram as hg # make 1-d histogram with 5 logarithmic bins from 1e0 to 1e5 diff --git a/examples/guide_histogram_pickle.py b/examples/guide_histogram_pickle.py index 7dd3aa10..18f6f4d0 100644 --- a/examples/guide_histogram_pickle.py +++ b/examples/guide_histogram_pickle.py @@ -1,6 +1,9 @@ -#[ guide_histogram_pickle - from __future__ import print_function +import sys +import os +sys.path.append(os.getcwd()) + +#[ guide_histogram_pickle import histogram as hg import pickle diff --git a/examples/guide_mixed_cpp_python.py b/examples/guide_mixed_cpp_python.py index d09857d7..e0b42ce0 100644 --- a/examples/guide_mixed_cpp_python.py +++ b/examples/guide_mixed_cpp_python.py @@ -1,6 +1,9 @@ -#[ guide_mixed_cpp_python_part_py - from __future__ import print_function +import sys +import os +sys.path.append(os.getcwd()) + +#[ guide_mixed_cpp_python_part_py import histogram as bh import cpp_filler diff --git a/examples/guide_numpy_support.py b/examples/guide_numpy_support.py index acb3c402..a7c756c1 100644 --- a/examples/guide_numpy_support.py +++ b/examples/guide_numpy_support.py @@ -1,5 +1,9 @@ -#[ guide_numpy_support +from __future__ import print_function +import sys +import os +sys.path.append(os.getcwd()) +#[ guide_numpy_support import histogram as hg import numpy as np @@ -35,7 +39,7 @@ try: plt.savefig("example_2d_python.png") except ImportError: # ok, no matplotlib, then just print the full count matrix - print count_matrix + print(count_matrix) # output of the print looks something like this, the two right-most rows # and two down-most columns represent under-/overflow bins diff --git a/examples/guide_python_axis_representation.py b/examples/guide_python_axis_representation.py index 882e6bb8..06d15cbf 100644 --- a/examples/guide_python_axis_representation.py +++ b/examples/guide_python_axis_representation.py @@ -1,5 +1,9 @@ -#[ guide_python_axis_representation +from __future__ import print_function +import sys +import os +sys.path.append(os.getcwd()) +#[ guide_python_axis_representation import histogram as hg import numpy as np @@ -11,8 +15,8 @@ for idx, (lower, upper) in enumerate(ax): if idx == len(ax)-1: xedge2.append(upper) -print xedge1 -print xedge2 +print(xedge1) +print(xedge2) # prints: # [ 0. 0.2 0.4 0.6 0.8 1. ] @@ -21,7 +25,7 @@ print xedge2 # sequences constructed from an axis use its iterator, the result differs xedge3 = list(ax) -print xedge3 +print(xedge3) # prints: # [(0., 0.2), (0.2, 0.4), (0.4, 0.6), (0.8, 1.0)] diff --git a/examples/guide_python_histogram.py b/examples/guide_python_histogram.py index eb4f2c34..75462bcc 100644 --- a/examples/guide_python_histogram.py +++ b/examples/guide_python_histogram.py @@ -1,5 +1,9 @@ -#[ guide_python_histogram from __future__ import print_function +import sys +import os +sys.path.append(os.getcwd()) + +#[ guide_python_histogram import histogram as hg # make 1-d histogram with 5 logarithmic bins from 1e0 to 1e5 diff --git a/include/boost/histogram/detail/utility.hpp b/include/boost/histogram/detail/utility.hpp index bcef1dcb..aaa96e70 100644 --- a/include/boost/histogram/detail/utility.hpp +++ b/include/boost/histogram/detail/utility.hpp @@ -42,8 +42,8 @@ inline void lin(std::size_t &out, std::size_t &stride, const int axis_size, const int axis_shape, int j) noexcept { - BOOST_ASSERT_MSG(stride == 0 || (-1 <= j && j <= axis_size), - "index must be in range [-1, size], check your logic"); + BOOST_ASSERT_MSG(stride == 0 || -1 <= j, + "index must be => -1 for this algorithm, check input"); j += (j < 0) * (axis_size + 2); // wrap around if j < 0 out += j * stride; #ifndef _MSC_VER diff --git a/test/python_suite_test.py b/test/python_suite_test.py index 1b4e23e6..4c24d93c 100644 --- a/test/python_suite_test.py +++ b/test/python_suite_test.py @@ -6,6 +6,9 @@ # (See accompanying file LICENSE_1_0.txt # or copy at http://www.boost.org/LICENSE_1_0.txt) +import sys +import os +sys.path.append(os.getcwd()) import unittest from math import pi from histogram import HAVE_NUMPY @@ -14,7 +17,6 @@ from histogram.axis import (regular, regular_log, regular_sqrt, regular_cos, regular_pow, circular, variable, category, integer) import pickle -import sys if sys.version_info.major == 3: from io import BytesIO else: