Skip to content

Commit

Permalink
TST: Simplify assert_warns in test_io.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sethtroisi committed May 29, 2020
1 parent ba4e4b6 commit a1526ca
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions numpy/lib/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,16 +1824,11 @@ def test_invalid_raise(self):
data[10 * i] = "2, 2, 2, 2 2"
data.insert(0, "a, b, c, d, e")
mdata = TextIO("\n".join(data))
#

kwargs = dict(delimiter=",", dtype=None, names=True)
# XXX: is there a better way to get the return value of the
# callable in assert_warns ?
ret = {}

def f(_ret={}):
_ret['mtest'] = np.genfromtxt(mdata, invalid_raise=False, **kwargs)
assert_warns(ConversionWarning, f, _ret=ret)
mtest = ret['mtest']
def f():
return np.genfromtxt(mdata, invalid_raise=False, **kwargs)
mtest = assert_warns(ConversionWarning, f)
assert_equal(len(mtest), 45)
assert_equal(mtest, np.ones(45, dtype=[(_, int) for _ in 'abcde']))
#
Expand All @@ -1848,16 +1843,12 @@ def test_invalid_raise_with_usecols(self):
data[10 * i] = "2, 2, 2, 2 2"
data.insert(0, "a, b, c, d, e")
mdata = TextIO("\n".join(data))

kwargs = dict(delimiter=",", dtype=None, names=True,
invalid_raise=False)
# XXX: is there a better way to get the return value of the
# callable in assert_warns ?
ret = {}

def f(_ret={}):
_ret['mtest'] = np.genfromtxt(mdata, usecols=(0, 4), **kwargs)
assert_warns(ConversionWarning, f, _ret=ret)
mtest = ret['mtest']
def f():
return np.genfromtxt(mdata, usecols=(0, 4), **kwargs)
mtest = assert_warns(ConversionWarning, f)
assert_equal(len(mtest), 45)
assert_equal(mtest, np.ones(45, dtype=[(_, int) for _ in 'ae']))
#
Expand Down

0 comments on commit a1526ca

Please sign in to comment.