summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@googlemail.com>2012-03-04 16:51:21 +0100
committerCharles Harris <charlesr.harris@gmail.com>2012-05-02 20:47:53 -0600
commit3b0aeb2063ff043dee15d95d5103648862a54982 (patch)
tree31324c4aefc509e2418e2f8d075c6b70cfa648d4
parent03c65cf6142ff35b637e34c8143abe7477d17ac8 (diff)
downloadnumpy-3b0aeb2063ff043dee15d95d5103648862a54982.tar.gz
TST: fix string comparison test failures on Windows for Python 2.5.
This is caused by the inconsistent floating point handling of Python itself. On Windows with 2.5: >>> "%s" % 1e-6 '1e-006' With 2.6: >>> "%s" % 1e-6 '1e-06' Reviewed as PR-225.
-rw-r--r--numpy/lib/tests/test_io.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 4d8e12846..adb8db0ff 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -2,7 +2,7 @@ import numpy as np
import numpy.ma as ma
from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal,
assert_raises, run_module_suite)
-from numpy.testing import assert_warns, assert_
+from numpy.testing import assert_warns, assert_, build_err_msg
import sys
@@ -253,7 +253,7 @@ class TestSaveTxt(TestCase):
np.savetxt(c, a, fmt=' %+.3e')
c.seek(0)
lines = c.readlines()
- assert_equal(lines, asbytes_nested([
+ _assert_floatstr_lines_equal(lines, asbytes_nested([
' ( +3.142e+00+ +2.718e+00j) ( +3.142e+00+ +2.718e+00j)\n',
' ( +3.142e+00+ +2.718e+00j) ( +3.142e+00+ +2.718e+00j)\n']))
# One format for each real and imaginary part
@@ -261,7 +261,7 @@ class TestSaveTxt(TestCase):
np.savetxt(c, a, fmt=' %+.3e' * 2 * ncols)
c.seek(0)
lines = c.readlines()
- assert_equal(lines, asbytes_nested([
+ _assert_floatstr_lines_equal(lines, asbytes_nested([
' +3.142e+00 +2.718e+00 +3.142e+00 +2.718e+00\n',
' +3.142e+00 +2.718e+00 +3.142e+00 +2.718e+00\n']))
# One format for each complex number
@@ -269,11 +269,30 @@ class TestSaveTxt(TestCase):
np.savetxt(c, a, fmt=['(%.3e%+.3ej)'] * ncols)
c.seek(0)
lines = c.readlines()
- assert_equal(lines, asbytes_nested([
+ _assert_floatstr_lines_equal(lines, asbytes_nested([
'(3.142e+00+2.718e+00j) (3.142e+00+2.718e+00j)\n',
'(3.142e+00+2.718e+00j) (3.142e+00+2.718e+00j)\n']))
+def _assert_floatstr_lines_equal(actual_lines, expected_lines):
+ """A string comparison function that also works on Windows + Python 2.5.
+
+ This is necessary because Python 2.5 on Windows inserts an extra 0 in
+ the exponent of the string representation of floating point numbers.
+
+ Only used in TestSaveTxt.test_complex_arrays, no attempt made to make this
+ more generic.
+
+ Once Python 2.5 compatibility is dropped, simply use `assert_equal` instead
+ of this function.
+ """
+ for actual, expected in zip(actual_lines, expected_lines):
+ if actual != expected:
+ expected_win25 = expected.replace("e+00", "e+000")
+ if actual != expected_win25:
+ msg = build_err_msg([actual, expected], '', verbose=True)
+ raise AssertionError(msg)
+
class TestLoadTxt(TestCase):
def test_record(self):