summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel <dabi@blazemail.com>2013-06-06 00:42:55 +0200
committerCharles Harris <charlesr.harris@gmail.com>2013-08-15 18:40:54 -0600
commitebfccd27a895fc2e28c2f1a2792feaea5d3913d3 (patch)
treee8f6200fcf9c61b21cd4c64973cbedc642fdf3ec
parentb82c1df6f99c62a120dfd9d5c606110d593d96e7 (diff)
downloadnumpy-ebfccd27a895fc2e28c2f1a2792feaea5d3913d3.tar.gz
TST: Test that savetxt works with objects having a write method.
-rw-r--r--numpy/lib/tests/test_io.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index a4a76f952..4095dd813 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -401,6 +401,18 @@ class TestSaveTxt(TestCase):
[b'(3.142e+00+2.718e+00j) (3.142e+00+2.718e+00j)\n',
b'(3.142e+00+2.718e+00j) (3.142e+00+2.718e+00j)\n'])
+ def test_custom_writer(self):
+
+ class CustomWriter(list):
+ def write(self, text):
+ self.extend(text.split(b'\n'))
+
+ w = CustomWriter()
+ a = np.array([(1, 2), (3, 4)])
+ np.savetxt(w, a)
+ b = np.loadtxt(w)
+ assert_array_equal(a, b)
+
def _assert_floatstr_lines_equal(actual_lines, expected_lines):
"""A string comparison function that also works on Windows + Python 2.5.