8000 TST: test for different line endings in genfromtxt input file by matthew-brett · Pull Request #71 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TST: test for different line endings in genfromtxt input file #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 22 additions & 23 deletions numpy/lib/tests/test_io.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
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_

import sys

import gzip
import os
import threading

from tempfile import mkstemp, NamedTemporaryFile
import time
from datetime import datetime

import numpy as np
import numpy.ma as ma
from numpy.lib._iotools import ConverterError, ConverterLockError, \
ConversionWarning
from numpy.compat import asbytes, asbytes_nested, bytes

from nose import SkipTest
from numpy.ma.testutils import (TestCase, assert_equal, assert_array_equal,
assert_raises, run_module_suite)
from numpy.testing import assert_warns, assert_

if sys.version_info[0] >= 3:
from io import BytesIO
def StringIO(s=""):
Expand Down Expand Up @@ -1313,21 +1312,21 @@ def test_recfromcsv(self):

def test_gft_filename(self):
# Test that we can load data from a filename as well as a file object
data = '0 1 2\n3 4 5'
exp_res = np.arange(6).reshape((2,3))
assert_array_equal(np.genfromtxt(StringIO(data)), exp_res)
f, name = mkstemp()
# Thanks to another windows brokeness, we can't use
# NamedTemporaryFile: a file created from this function cannot be
# reopened by another open call. So we first put the string
# of the test reference array, write it to a securely opened file,
# which is then read from by the loadtxt function
try:
os.write(f, asbytes(data))
assert_array_equal(np.genfromtxt(name), exp_res)
finally:
os.close(f)
os.unlink(name)
wanted = np.arange(6).reshape((2,3))
is_py3 = sys.version_info[0] >= 3
for sep in ('\n', '\r\n', '\r'):
if sep == '\r' and is_py3:
raise SkipTest(r'Py3 version does not split lines on \r')
data = '0 1 2' + sep + '3 4 5'
f, name = mkstemp()
# We can't use NamedTemporaryFile on windows, because we cannot
# reopen the file.
try:
os.write(f, asbytes(data))
assert_array_equal(np.genfromtxt(name), wanted)
finally:
os.close(f)
os.unlink(name)

def test_gft_generator_source(self):
def count():
Expand Down
0