diff options
author | Tyler Reddy <tyler.je.reddy@gmail.com> | 2019-04-12 14:08:24 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2019-04-13 11:28:44 -0700 |
commit | e88d0196568863ef03869b393e619ec89e85f93a (patch) | |
tree | d159d51ca8781f012542eb26e19b4394c22a4eb4 | |
parent | 87c126d794ac01d6a874ce345ab7d31f08ff1964 (diff) | |
download | numpy-e88d0196568863ef03869b393e619ec89e85f93a.tar.gz |
TST: unit test for gh-13200
-rw-r--r-- | numpy/lib/tests/test_io.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 835344429..030488b77 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -22,7 +22,7 @@ from numpy.ma.testutils import assert_equal from numpy.testing import ( assert_warns, assert_, assert_raises_regex, assert_raises, assert_allclose, assert_array_equal, temppath, tempdir, IS_PYPY, - HAS_REFCOUNT, suppress_warnings, assert_no_gc_cycles, + HAS_REFCOUNT, suppress_warnings, assert_no_gc_cycles, assert_no_warnings ) @@ -1391,6 +1391,19 @@ M 33 21.99 control = np.array([(1, 2), (3, 4)], dtype=[('col1', int), ('col2', int)]) assert_equal(test, control) + def test_file_is_closed_on_error(self): + # gh-13200 + with tempdir() as tmpdir: + fpath = os.path.join(tmpdir, "test.csv") + with open(fpath, "wb") as f: + f.write(u'\N{GREEK PI SYMBOL}'.encode('utf8')) + + # ResourceWarnings are emitted from a destructor, so won't be + # detected by regular propagation to errors. + with assert_no_warnings(): + with pytest.raises(UnicodeDecodeError): + np.genfromtxt(fpath, encoding="ascii") + def test_autonames_and_usecols(self): # Tests names and usecols data = TextIO('A B C D\n aaaa 121 45 9.1') |