Skip to content

Commit

Permalink
move test_mc to pytest
Browse files Browse the repository at this point in the history
This fixes a failure with -Werror not taking into account that the warning is expected
  • Loading branch information
bnavigator committed May 24, 2020
1 parent 36ceb47 commit 443577d
Showing 1 changed file with 39 additions and 48 deletions.
87 changes: 39 additions & 48 deletions slycot/tests/test_mc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,44 @@
# test_mc.py - test suite for polynomial and rational function manipulation
# bnavigator <[email protected]>, Aug 2019

import unittest
import warnings
import pytest
import re

from slycot import mc01td


class test_mc(unittest.TestCase):

def test_mc01td(self):
""" test_mc01td: doc example
data from http://slicot.org/objects/software/shared/doc/MC01TD.html
"""
(dp, stable, nz) = mc01td('C', 4, [2, 0, 1, -1, 1])
self.assertEqual(dp, 4)
self.assertEqual(stable, 0)
self.assertEqual(nz, 2)

def test_mc01td_D(self):
""" test_mc01td_D: test discrete option """
(dp, stable, nz) = mc01td('D', 3, [1, 2, 3, 4])
self.assertEqual(dp, 3)
self.assertEqual(stable, 1)
self.assertEqual(nz, 0)
(dp, stable, nz) = mc01td('D', 3, [4, 3, 2, 1])
self.assertEqual(dp, 3)
self.assertEqual(stable, 0)
self.assertEqual(nz, 3)

def test_mc01td_warnings(self):
""" test_mc01td_warnings: Test warnings """
T = [([0, 0], "\n"
"Entry ``P(x)`` is the zero polynomial."),
([0, 1], "\n"
"The polynomial ``P(x)`` is most probably unstable,\n"
"although it may be stable with one or more zeros\n"
"very close to the imaginary axis.\n"
"The number of unstable zeros (NZ) is not determined."),
([1, 0], "\n"
"The degree of the polynomial ``P(x)`` has been\n"
"reduced to ``(DB - 1)`` because\n"
"``P(DB+1-j) = 0.0`` on entry\n"
"for ``j = 0, 1,..., k-1`` and ``P(DB+1-k) <> 0.0``.")]
for P, m in T:
with warnings.catch_warnings(record=True) as w:
(dp, stable, nz) = mc01td('C', len(P)-1, P)
self.assertEqual(str(w[0].message), m)


if __name__ == "__main__":
unittest.main()
from slycot.exceptions import SlycotResultWarning


def test_mc01td():
""" test_mc01td: doc example
data from http://slicot.org/objects/software/shared/doc/MC01TD.html
"""
(dp, stable, nz) = mc01td('C', 4, [2, 0, 1, -1, 1])
assert dp == 4
assert stable == 0
assert nz == 2

def test_mc01td_D():
""" test_mc01td_D: test discrete option """
(dp, stable, nz) = mc01td('D', 3, [1, 2, 3, 4])
assert dp == 3
assert stable == 1
assert nz == 0
(dp, stable, nz) = mc01td('D', 3, [4, 3, 2, 1])
assert dp == 3
assert stable == 0
assert nz == 3

def test_mc01td_warnings():
""" test_mc01td_warnings: Test warnings """
T = [([0, 0], "Entry ``P(x)`` is the zero polynomial."),
([0, 1], "The polynomial ``P(x)`` is most probably unstable,\n"
"although it may be stable with one or more zeros\n"
"very close to the imaginary axis.\n"
"The number of unstable zeros (NZ) is not determined."),
([1, 0], "The degree of the polynomial ``P(x)`` has been\n"
"reduced to ``(DB - 1)`` because\n"
"``P(DB+1-j) = 0.0`` on entry\n"
"for ``j = 0, 1,..., k-1`` and ``P(DB+1-k) <> 0.0``.")]
for P, m in T:
with pytest.warns(SlycotResultWarning, match=re.escape(m)):
(dp, stable, nz) = mc01td('C', len(P)-1, P)

0 comments on commit 443577d

Please sign in to comment.