Skip to content
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

Replace unittest calls with pytest #207

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion slycot/tests/test_ab01.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from numpy import array
from numpy.testing import assert_allclose, assert_equal

from scipy.linalg.lapack import dorgqr

from slycot.analysis import ab01nd
Expand Down
6 changes: 3 additions & 3 deletions slycot/tests/test_ab04md.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from slycot import analysis
import numpy as np

from numpy.testing import assert_allclose

from slycot import analysis


class test_ab04md:
class Test_ab04md:
"""Test ab04md.
Example data taken from
Expand Down
13 changes: 4 additions & 9 deletions slycot/tests/test_ab08n.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# ===================================================
# ab08n* tests

import unittest
from slycot import analysis
import numpy as np

from numpy.testing import assert_allclose, assert_equal
from scipy.linalg import eig
from numpy.testing import assert_equal, assert_allclose

from slycot import analysis


class test_ab08nX(unittest.TestCase):
class Test_ab08nX:
""" Test regular pencil construction ab08nX with input parameters
according to example in documentation """

Expand Down Expand Up @@ -77,7 +76,3 @@ def test_ab08nz(self):
Ac, Bc, Cc, Dc = [M.astype(np.complex128) for M in [self.A, self.B,
self.C, self.D]]
self.ab08nX(analysis.ab08nz, Ac, Bc, Cc, Dc)


if __name__ == "__main__":
unittest.main()
14 changes: 5 additions & 9 deletions slycot/tests/test_ab13bd.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# ===================================================
# ab08n* tests

import unittest
from slycot import analysis
import numpy as np
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
from scipy import linalg, signal

from slycot import analysis

from scipy import linalg
from scipy import signal
from numpy.testing import assert_equal, assert_allclose, assert_array_equal

class test_ab13bd(unittest.TestCase):
class Test_ab13bd:
""" Test regular pencil construction ab08nX with input parameters
according to example in documentation """

Expand Down Expand Up @@ -118,6 +117,3 @@ def test_ab13bd_2norm_dcase(self):
print(h2norm, h2norm_Lo)
assert_allclose(h2norm_Lo, h2norm, atol=1e-5)


if __name__ == "__main__":
unittest.main()
3 changes: 1 addition & 2 deletions slycot/tests/test_ab13md.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np
from numpy.testing import assert_allclose, assert_array_less

import pytest
from numpy.testing import assert_allclose, assert_array_less

from slycot import ab13md

Expand Down
149 changes: 70 additions & 79 deletions slycot/tests/test_ag08bd.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# ===================================================
# ag08bd tests
"""Verify ag08bd with input parameters according to example in documentation."""

import unittest
from slycot import analysis
import numpy as np

from numpy.testing import assert_almost_equal, assert_equal

from slycot import analysis

# test1 input parameters

test1_l = 9
Expand Down Expand Up @@ -47,77 +45,70 @@
[ 0, 0, 0]])


class test_ag08bd(unittest.TestCase):
"""Verify ag08bd with input parameters according to example in documentation."""

def test1_ag08bd(self):
"""test [A-lambda*E]

B,C,D must have correct dimensions according to l,n,m and p, but cannot
have zero length in any dimenstion. Then the wrapper will complain.
The length is then set to one.
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=0,p=0,A=test1_A,E=test1_E,B=np.zeros((test1_l,1)),C=np.zeros((1,test1_n)),D=np.zeros((1,1)),equil=test1_equil, tol=test1_tol)

assert_equal(Af, np.zeros((0,0)))
assert_equal(Ef, np.zeros((0,0)))
assert_equal(nrank, 9)
assert_equal(niz, 6)
assert_equal(infz, [0,3])
assert_equal(kronr, [])
assert_equal(infe, [3,3,3])
assert_equal(kronl, [])

def test2_ag08bd(self):
"""test [A-lambda*E;C]

B,D must have correct dimensions as before
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=0,p=test1_p,A=test1_A,E=test1_E,B=np.zeros((test1_l,1)),C=test1_C,D=np.zeros((test1_p,1)),equil=test1_equil, tol=test1_tol)

assert_equal(Af, np.zeros((0,0)))
assert_equal(Ef, np.zeros((0,0)))
assert_equal(nrank, 9)
assert_equal(niz, 4)
assert_equal(infz, [0,2])
assert_equal(kronr, [])
assert_equal(infe, [1,3,3])
assert_equal(kronl, [0,1,1])

def test3_ag08bd(self):
"""test [A-lambda*E,B]

C,D must have correct dimensions as before
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=test1_m,p=0,A=test1_A,E=test1_E,B=test1_B,C=np.zeros((1,test1_n)),D=np.zeros((1,test1_m)),equil=test1_equil, tol=test1_tol)

assert_equal(Af, np.zeros((0,0)))
assert_equal(Ef, np.zeros((0,0)))
assert_equal(nrank, 9)
assert_equal(niz, 0)
assert_equal(infz, [])
assert_equal(kronr, [2,2,2])
assert_equal(infe, [1,1,1])
assert_equal(kronl, [])

def test4_ag08bd(self):
"""test [A-lambda*E,B;C,D]"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=test1_m,p=test1_p,A=test1_A,E=test1_E,B=test1_B,C=test1_C,D=test1_D,equil=test1_equil, tol=test1_tol)

# Af-lambda*Ef==0. => lambda==1. => Finite Smith zero of S(lambda) == 1.
assert Af.shape == (1, 1)
assert_almost_equal(Af, Ef)
assert_equal(nrank, 11)
assert_equal(niz, 2)
assert_equal(infz, [0,1])
assert_equal(kronr, [2])
assert_equal(infe, [1,1,1,1,3])
assert_equal(kronl, [1])


if __name__ == "__main__":
unittest.main()
def test1_ag08bd():
"""test [A-lambda*E]

B,C,D must have correct dimensions according to l,n,m and p, but cannot
have zero length in any dimenstion. Then the wrapper will complain.
The length is then set to one.
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=0,p=0,A=test1_A,E=test1_E,B=np.zeros((test1_l,1)),C=np.zeros((1,test1_n)),D=np.zeros((1,1)),equil=test1_equil, tol=test1_tol)

assert_equal(Af, np.zeros((0,0)))
assert_equal(Ef, np.zeros((0,0)))
assert_equal(nrank, 9)
assert_equal(niz, 6)
assert_equal(infz, [0,3])
assert_equal(kronr, [])
assert_equal(infe, [3,3,3])
assert_equal(kronl, [])

def test2_ag08bd():
"""test [A-lambda*E;C]

B,D must have correct dimensions as before
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=0,p=test1_p,A=test1_A,E=test1_E,B=np.zeros((test1_l,1)),C=test1_C,D=np.zeros((test1_p,1)),equil=test1_equil, tol=test1_tol)

assert_equal(Af, np.zeros((0,0)))
assert_equal(Ef, np.zeros((0,0)))
assert_equal(nrank, 9)
assert_equal(niz, 4)
assert_equal(infz, [0,2])
assert_equal(kronr, [])
assert_equal(infe, [1,3,3])
assert_equal(kronl, [0,1,1])

def test3_ag08bd():
"""test [A-lambda*E,B]

C,D must have correct dimensions as before
"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=test1_m,p=0,A=test1_A,E=test1_E,B=test1_B,C=np.zeros((1,test1_n)),D=np.zeros((1,test1_m)),equil=test1_equil, tol=test1_tol)

assert_equal(Af, np.zeros((0,0)))
assert_equal(Ef, np.zeros((0,0)))
assert_equal(nrank, 9)
assert_equal(niz, 0)
assert_equal(infz, [])
assert_equal(kronr, [2,2,2])
assert_equal(infe, [1,1,1])
assert_equal(kronl, [])

def test4_ag08bd():
"""test [A-lambda*E,B;C,D]"""

Af,Ef,nrank,niz,infz,kronr,infe,kronl = analysis.ag08bd(l=test1_l,n=test1_n,m=test1_m,p=test1_p,A=test1_A,E=test1_E,B=test1_B,C=test1_C,D=test1_D,equil=test1_equil, tol=test1_tol)

# Af-lambda*Ef==0. => lambda==1. => Finite Smith zero of S(lambda) == 1.
assert Af.shape == (1, 1)
assert_almost_equal(Af, Ef)
assert_equal(nrank, 11)
assert_equal(niz, 2)
assert_equal(infz, [0,1])
assert_equal(kronr, [2])
assert_equal(infe, [1,1,1,1,3])
assert_equal(kronl, [1])
4 changes: 3 additions & 1 deletion slycot/tests/test_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# repagh <rene.vanpaassen@gmail.com, May 2020

import pytest
from .test_exceptions import assert_docstring_parse

from slycot import analysis
from slycot.exceptions import SlycotArithmeticError, SlycotResultWarning

from .test_exceptions import assert_docstring_parse


@pytest.mark.parametrize(
'fun, exception_class, erange, checkvars',
Expand Down
1 change: 1 addition & 0 deletions slycot/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

from inspect import getmembers, isfunction

import pytest

from slycot import examples
Expand Down
4 changes: 2 additions & 2 deletions slycot/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

import pytest

from slycot.exceptions import raise_if_slycot_error, \
SlycotError, SlycotWarning, SlycotParameterError
from slycot import _wrapper
from slycot.exceptions import (SlycotError, SlycotParameterError,
SlycotWarning, raise_if_slycot_error)


def assert_docstring_parse(docstring, exception_class, erange, checkvars={}):
Expand Down
Loading
Loading