Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
FIX: pytest.raises does not support str argument
Using the second argument to pytest.raises as a string is deprecated
since pytest versiono 4.0 and has been removed since pytest 5.1:
https://docs.pytest.org/en/latest/changelog.html#pytest-5-1-0-2019-08-15
  • Loading branch information
otizonaizit committed Apr 17, 2020
1 parent 8105cd1 commit bd216ab
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 28 deletions.
34 changes: 17 additions & 17 deletions mdp/test/test_Convolution2DNode.py
Expand Up @@ -18,13 +18,13 @@ def testConvolution2DNodeFunctionality():
filters = numx.empty((3,1,1))
filters[:,0,0] = [1.,2.,3.]
x = numx_rand.random((10,3,4))

for mode in ['valid', 'same', 'full']:
for boundary in ['fill', 'wrap', 'symm']:
node = mdp.nodes.Convolution2DNode(filters, approach='linear', mode=mode,
boundary=boundary, output_2d=False)
y = node.execute(x)

assert_equal(y.shape, (x.shape[0], 3, x.shape[1], x.shape[2]))
for n_flt in range(3):
assert_array_equal(x*(n_flt+1.), y[:,n_flt,:,:])
Expand All @@ -33,21 +33,21 @@ def testConvolution2DNodeFunctionality():
def testConvolution2DNode_2D3Dinput():
filters = numx.empty((3,1,1))
filters[:,0,0] = [1.,2.,3.]

# 1) input 2D/3D
x = numx_rand.random((10,12))
x = numx_rand.random((10,12))
node = mdp.nodes.Convolution2DNode(filters, approach='linear',
input_shape=(3,4), output_2d=False)
y = node.execute(x)
assert_equal(y.shape, (x.shape[0], 3, 3, 4))
x = numx.random.random((10,3,4))

x = numx.random.random((10,3,4))
node = mdp.nodes.Convolution2DNode(filters, output_2d=False)
y = node.execute(x)
assert_equal(y.shape, (x.shape[0], 3, 3, 4))

# 2) output 2D/3D
x = numx.random.random((10,12))
x = numx.random.random((10,12))
node = mdp.nodes.Convolution2DNode(filters, approach='linear',
input_shape=(3,4), output_2d=True)
y = node.execute(x)
Expand All @@ -60,7 +60,7 @@ def testConvolution2DNode_fft():
filters = numx.empty((3,1,1))
filters[:,0,0] = [1.,2.,3.]
x = numx.random.random((10,3,4))

for mode in ['valid', 'same', 'full']:
node = mdp.nodes.Convolution2DNode(filters, approach='fft', mode=mode,
output_2d=False)
Expand All @@ -80,21 +80,21 @@ def testConvolution2DNode_fft():
boundary='fill', output_2d=False)
y_fft = node_fft.execute(x)
y_lin = node_lin.execute(x)

assert_array_almost_equal(y_fft, y_lin, 6)

@requires_signal
def testConvolution2DNode_in_Flow():
filters = numx.empty((3,1,1))
filters[:,0,0] = [1.,2.,3.]

# with 3D input
x = numx.random.random((10,3,4))
x = numx.random.random((10,3,4))
node = mdp.nodes.Convolution2DNode(filters, output_2d=True)
flow = mdp.Flow([node, mdp.nodes.PCANode(output_dim=3)])
flow.train(x)
flow.execute(x)

# with 2D input
x = numx.random.random((10,12))
node = mdp.nodes.Convolution2DNode(filters, input_shape=(3,4), output_2d=True)
Expand All @@ -109,15 +109,15 @@ def testConvolution2DNode_arguments():
# filters must be 3D
filters = numx.random.random((5,4))
pytest.raises(mdp.NodeException,
"mdp.nodes.Convolution2DNode(filters)")
mdp.nodes.Convolution2DNode, filters)
filters = numx.random.random((5,4,2,2))
pytest.raises(mdp.NodeException,
"mdp.nodes.Convolution2DNode(filters)")
mdp.nodes.Convolution2DNode, filters)
# filters must be array
filters = [[[2.]]]
pytest.raises(mdp.NodeException,
"mdp.nodes.Convolution2DNode(filters)")
mdp.nodes.Convolution2DNode, filters)

filters = numx.random.random((1,1,1))
with pytest.raises(mdp.NodeException):
mdp.nodes.Convolution2DNode(filters, approach='bug')
Expand Down
2 changes: 1 addition & 1 deletion mdp/test/test_FANode.py
Expand Up @@ -75,5 +75,5 @@ def test_FANode_singular_cov():
fanode = mdp.nodes.FANode(output_dim=3)
fanode.train(x)
# the matrix x is singular
pytest.raises(mdp.NodeException, "fanode.stop_training()")
pytest.raises(mdp.NodeException, fanode.stop_training)

3 changes: 1 addition & 2 deletions mdp/test/test_PCANode.py
Expand Up @@ -232,5 +232,4 @@ def test_PCANode_no_eigenvalues_left():
mat = numx.zeros((100,4), dtype='d')
pca = mdp.nodes.PCANode(svd=True, reduce=True)
pca.train(mat)
pytest.raises(mdp.NodeException, 'pca.stop_training()')

pytest.raises(mdp.NodeException, pca.stop_training)
9 changes: 6 additions & 3 deletions mdp/test/test_metaclass_and_extensions.py
Expand Up @@ -39,7 +39,8 @@ def _train(self, x, foo=None):
assert get_signature(cnode._train) == 'self, x, foo'
cnode.train(X, foo=42)
assert cnode.foo == 42
pytest.raises(AttributeError, 'cnode.foo2')
with pytest.raises(AttributeError):
_ = cnode.foo2


def test_signatures_more_arguments():
Expand All @@ -59,7 +60,8 @@ def _train(self, x, foo=None):
cnode.train._undecorated_(cnode, X, foo=42)
cnode.train(X, foo=42)
assert cnode.foo == 42
pytest.raises(AttributeError, 'cnode.foo2')
with pytest.raises(AttributeError):
_ = cnode.foo2


def test_signatures_less_arguments():
Expand All @@ -82,7 +84,8 @@ def _train(self, x):
cnode.train._undecorated_(cnode, X)
cnode.train(X)
assert cnode.moo == 3
pytest.raises(AttributeError, 'cnode.foo')
with pytest.raises(AttributeError):
_ = cnode.foo


def test_simple_extension():
Expand Down
10 changes: 5 additions & 5 deletions mdp/test/test_nodes_generic.py
Expand Up @@ -262,16 +262,16 @@ def _test(node):
# raises an appropriate error
# case 1: both in the constructor
pytest.raises(InconsistentDimException,
'klass(input_dim=inp.shape[1], output_dim=output_dim, *args)')
klass, *args, input_dim=inp.shape[1], output_dim=output_dim)
# case 2: first input_dim, then output_dim
node = klass(input_dim=inp.shape[1], *args)
pytest.raises(InconsistentDimException,
'node.output_dim = output_dim')
with pytest.raises(InconsistentDimException):
node.output_dim = output_dim
# case 3: first output_dim, then input_dim
node = klass(output_dim=output_dim, *args)
node.output_dim = output_dim
pytest.raises(InconsistentDimException,
'node.input_dim = inp.shape[1]')
with pytest.raises(InconsistentDimException):
node.input_dim = inp.shape[1]

# check that output_dim is set to whatever the output dim is
node = klass(*args)
Expand Down

0 comments on commit bd216ab

Please sign in to comment.