8000 TST: test for different line endings in genfromtxt input file. Note · numpy/numpy@fe3852f · GitHub
[go: up one dir, main page]

Skip to content

Commit fe3852f

Browse files
matthew-brettcharris
authored andcommitted
TST: test for different line endings in genfromtxt input file. Note
that the test for '\r' is skipped for python 3k since it is known to fail.
1 parent 966038e commit fe3852f

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

numpy/lib/tests/test_io.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
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-
71
import sys
8-
92
import gzip
103
import os
114
import threading
12-
135
from tempfile import mkstemp, NamedTemporaryFile
146
import time
157
from datetime import datetime
168

9+
import numpy as np
10+
import numpy.ma as ma
1711
from numpy.lib._iotools import ConverterError, ConverterLockError, \
1812
ConversionWarning
1913
from numpy.compat import asbytes, asbytes_nested, bytes
2014

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+
2120
if sys.version_info[0] >= 3:
2221
from io import BytesIO
2322
def StringIO(s=""):
@@ -1311,25 +1310,28 @@ def test_recfromcsv(self):
13111310
self.assertTrue(isinstance(test, np.recarray))
13121311
assert_equal(test, control)
13131312

1314-
def test_gft_filename(self):
1313+
def test_gft_using_filename(self):
13151314
# 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)
13311333

1332-
def test_gft_generator_source(self):
1334+
def test_gft_using_generator(self):
13331335
def count():
13341336
for i in range(10):
13351337
yield asbytes("%d" % i)

0 commit comments

Comments
 (0)
0