|
1 |
| -import numpy as np |
2 |
| -import numpy.ma as ma |
3 |
| -from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal, |
4 |
| - assert_raises, run_module_suite) |
5 |
| -from numpy.testing import assert_warns, assert_ |
6 |
| - |
7 | 1 | import sys
|
8 |
| - |
9 | 2 | import gzip
|
10 | 3 | import os
|
11 | 4 | import threading
|
12 |
| - |
13 | 5 | from tempfile import mkstemp, NamedTemporaryFile
|
14 | 6 | import time
|
15 | 7 | from datetime import datetime
|
16 | 8 |
|
| 9 | +import numpy as np |
| 10 | +import numpy.ma as ma |
17 | 11 | from numpy.lib._iotools import ConverterError, ConverterLockError, \
|
18 | 12 | ConversionWarning
|
19 | 13 | from numpy.compat import asbytes, asbytes_nested, bytes
|
20 | 14 |
|
| 15 | +from nose import SkipTest |
| 16 | +from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal, |
| 17 | + assert_raises, run_module_suite) |
| 18 | +from numpy.testing import assert_warns, assert_ |
| 19 | + |
21 | 20 | if sys.version_info[0] >= 3:
|
22 | 21 | from io import BytesIO
|
23 | 22 | def StringIO(s=""):
|
@@ -1311,25 +1310,28 @@ def test_recfromcsv(self):
|
1311 | 1310 | self.assertTrue(isinstance(test, np.recarray))
|
1312 | 1311 | assert_equal(test, control)
|
1313 | 1312 |
|
1314 |
| - def test_gft_filename(self): |
| 1313 | + def test_gft_using_filename(self): |
1315 | 1314 | # Test that we can load data from a filename as well as a file object
|
1316 |
| - data = '0 1 2\n3 4 5' |
1317 |
| - exp_res = np.arange(6).reshape((2,3)) |
1318 |
| - assert_array_equal(np.genfromtxt(StringIO(data)), exp_res) |
1319 |
| - f, name = mkstemp() |
1320 |
| - # Thanks to another windows brokeness, we can't use |
1321 |
| - # NamedTemporaryFile: a file created from this function cannot be |
1322 |
| - # reopened by another open call. So we first put the string |
1323 |
| - # of the test reference array, write it to a securely opened file, |
1324 |
| - # which is then read from by the loadtxt function |
1325 |
| - try: |
1326 |
| - os.write(f, asbytes(data)) |
1327 |
| - assert_array_equal(np.genfromtxt(name), exp_res) |
1328 |
| - finally: |
1329 |
| - os.close(f) |
1330 |
| - os.unlink(name) |
| 1315 | + wanted = np.arange(6).reshape((2,3)) |
| 1316 | + if sys.version_info[0] >= 3: |
| 1317 | + # python 3k is known to fail for '\r' |
| 1318 | + linesep = ('\n', '\r\n') |
| 1319 | + else: |
| 1320 | + linesep = ('\n', '\r\n', '\r') |
| 1321 | + |
| 1322 | + for sep in linesep: |
| 1323 | + data = '0 1 2' + sep + '3 4 5' |
| 1324 | + f, name = mkstemp() |
| 1325 | + # We can't use NamedTemporaryFile on windows, because we cannot |
| 1326 | + # reopen the file. |
| 1327 | + try: |
| 1328 | + os.write(f, asbytes(data)) |
| 1329 | + assert_array_equal(np.genfromtxt(name), wanted) |
| 1330 | + finally: |
| 1331 | + os.close(f) |
| 1332 | + os.unlink(name) |
1331 | 1333 |
|
1332 |
| - def test_gft_generator_source(self): |
| 1334 | + def test_gft_using_generator(self): |
1333 | 1335 | def count():
|
1334 | 1336 | for i in range(10):
|
1335 | 1337 | yield asbytes("%d" % i)
|
|
0 commit comments