Skip to content

Switch to pytest and add optional Python 3.8 test #380

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

Merged
merged 12 commits into from
Mar 25, 2020
Merged
18 changes: 15 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ env:
- SCIPY=scipy SLYCOT= # default, w/out slycot
- SCIPY="scipy==0.19.1" SLYCOT= # legacy support, w/out slycot

# Add optional builds that test against latest version of slycot
# Add optional builds that test against latest version of slycot, python
jobs:
include:
- name: "linux, Python 2.7, slycot=source"
Expand All @@ -43,8 +43,13 @@ jobs:
services: xvfb
python: "3.7"
env: SCIPY=scipy SLYCOT=source
- name: "linux, Python 3.8, slycot=source"
os: linux
dist: xenial
services: xvfb
python: "3.8"
env: SCIPY=scipy SLYCOT=source

matrix:
# Exclude combinations that are very unlikely (and don't work)
exclude:
- python: "3.7" # python3.7 should use latest scipy
Expand All @@ -63,6 +68,12 @@ matrix:
services: xvfb
python: "3.7"
env: SCIPY=scipy SLYCOT=source
- name: "linux, Python 3.8, slycot=source"
os: linux
dist: xenial
services: xvfb
python: "3.8"
env: SCIPY=scipy SLYCOT=source

# install required system libraries
before_install:
Expand Down Expand Up @@ -97,6 +108,7 @@ before_install:
fi
# Make sure to look in the right place for python libraries (for slycot)
- export LIBRARY_PATH="$HOME/miniconda/envs/test-environment/lib"
- conda install pytest
# coveralls not in conda repos => install via pip instead
- pip install coveralls

Expand All @@ -118,7 +130,7 @@ install:
# command to run tests
script:
- 'if [ $SLYCOT != "" ]; then python -c "import slycot"; fi'
- coverage run setup.py test
- coverage run -m pytest --disable-warnings control/tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is --disable-warnings needed? I would rather have them printed and give every contributor the opportunity to fix problems early before e.g. DeprecationWarnings turn into errors after a Python or some library update.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 18,209 warning messages and unfortunately pytest prints error messages first => I found it hard to locate the errors. Most of the warnings seem to be around the use of numpy.matrix, which I figure we will get rid of starting in v0.9.0.


# only run examples if Slycot is install
# set PYTHONPATH for examples
Expand Down
6 changes: 0 additions & 6 deletions control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,5 @@
except ImportError:
__version__ = "dev"

# The following is to use Numpy's testing framework
# Tests go under directory tests/, benchmarks under directory benchmarks/
from numpy.testing import Tester
test = Tester().test
bench = Tester().bench

# Initialize default parameter values
reset_defaults()
6 changes: 1 addition & 5 deletions control/tests/bdalg_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# bdalg_test.py - test suit for block diagram algebra
# bdalg_test.py - test suite for block diagram algebra
# RMM, 30 Mar 2011 (based on TestBDAlg from v0.4a)

import unittest
Expand Down Expand Up @@ -271,9 +271,5 @@ def test_feedback_args(self):
self.assertTrue(isinstance(sys, ctrl.FRD))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestFeedback)


if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/canonical_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ def test_similarity(self):
np.testing.assert_array_almost_equal(mimo_new.C, mimo_ini.C)
np.testing.assert_array_almost_equal(mimo_new.D, mimo_ini.D)

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestFeedback)


if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,6 @@ def tearDown(self):
# Reset the configuration defaults
ct.config.reset_defaults()

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestTimeresp)


if __name__ == '__main__':
unittest.main()
2 changes: 0 additions & 2 deletions control/tests/convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ def test_tf2ss_robustness(self):
np.testing.assert_array_almost_equal(np.sort(sys2tf.pole()),
np.sort(sys2ss.pole()))

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestConvert)

if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/ctrlutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,5 @@ def test_mag2db_array(self):
np.testing.assert_array_almost_equal(db_array, self.db)


def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TestUtils)

if __name__ == "__main__":
unittest.main()
7 changes: 3 additions & 4 deletions control/tests/discrete_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import unittest
import numpy as np
from control import *
from control import StateSpace, TransferFunction, feedback, step_response, \
isdtime, timebase, isctime, sample_system, bode, impulse_response, \
timebaseEqual, forced_response
from control import matlab

class TestDiscrete(unittest.TestCase):
Expand Down Expand Up @@ -382,9 +384,6 @@ def test_discrete_bode(self):
np.testing.assert_array_almost_equal(mag_out, np.absolute(H_z))
np.testing.assert_array_almost_equal(phase_out, np.angle(H_z))

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestDiscrete)


if __name__ == "__main__":
unittest.main()
4 changes: 0 additions & 4 deletions control/tests/flatsys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,5 @@ def tearDown(self):
ct.reset_defaults()


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestFlatSys)


if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/frd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,5 @@ def test_evalfr_deprecated(self):
self.assertRaises(PendingDeprecationWarning, frd_tf.evalfr, 1.)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestFRD)

if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/freqresp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,5 @@ def test_options(self):
ctrl.config.reset_defaults()


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestTimeresp)

if __name__ == '__main__':
unittest.main()
4 changes: 0 additions & 4 deletions control/tests/iosys_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,10 +911,6 @@ def test_duplicates(self):
self.assertEqual(len(warnval), 0)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestTimeresp)


# Predator prey dynamics
def predprey(t, x, u, params={}):
r = params.get('r', 2)
Expand Down
2 changes: 0 additions & 2 deletions control/tests/lti_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ def test_dcgain(self):
np.testing.assert_equal(sys.dcgain(), 42)
np.testing.assert_equal(dcgain(sys), 42)

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestUtils)

if __name__ == "__main__":
unittest.main()
4 changes: 1 addition & 3 deletions control/tests/margin_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# margin_test.py - test suit for stability margin commands
# margin_test.py - test suite for stability margin commands
# RMM, 15 Jul 2011

from __future__ import print_function
Expand Down Expand Up @@ -310,8 +310,6 @@ def test_zmore_margin(self):
assert_array_almost_equal(
res, test['result'], test['digits'])

def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TestMargin)

if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/mateqn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,5 @@ def test_raise(self):
assert_raises(ControlArgument, cdare, A, B, Q, R, S)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestMatrixEquations)

if __name__ == "__main__":
unittest.main()
2 changes: 0 additions & 2 deletions control/tests/matlab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,6 @@ def test_tf_string_args(self):
# for i in range(len(tfdata)):
# np.testing.assert_array_almost_equal(tfdata_1[i], tfdata_2[i])

def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TestMatlab)

if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/minreal_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def testMinrealtf(self):
np.testing.assert_array_almost_equal(hm.num[0][0], hr.num[0][0])
np.testing.assert_array_almost_equal(hm.den[0][0], hr.den[0][0])

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestMinreal)


if __name__ == "__main__":
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/modelsimp_array_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ def tearDown(self):
# Reset configuration variables to their original settings
control.config.reset_defaults()

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestModelsimp)


if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/modelsimp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ def testBalredMatchDC(self):
np.testing.assert_array_almost_equal(rsys.C, Crtrue,decimal=4)
np.testing.assert_array_almost_equal(rsys.D, Drtrue,decimal=4)

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestModelsimp)


if __name__ == '__main__':
unittest.main()
3 changes: 0 additions & 3 deletions control/tests/nichols_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def testNgrid(self):
nichols(self.sys, grid=False)
ngrid()

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestStateSpace)


if __name__ == "__main__":
unittest.main()
2 changes: 0 additions & 2 deletions control/tests/phaseplot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def invpend_ode(self, x, t, m=1., l=1., b=0, g=9.8):
def oscillator_ode(self, x, t, m=1., b=1, k=1, extra=None):
return (x[1], -k/m*x[0] - b/m*x[1])

def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestPhasePlot)

if __name__ == '__main__':
unittest.main()
2 changes: 0 additions & 2 deletions control/tests/rlocus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def test_root_locus_zoom(self):
assert_array_almost_equal(zoom_x,zoom_x_valid)
assert_array_almost_equal(zoom_y,zoom_y_valid)

def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TestRootLocus)

if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions control/tests/robust_array_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,5 +388,6 @@ def testSiso(self):
def tearDown(self):
control.config.reset_defaults()


if __name__ == "__main__":
unittest.main()
71 changes: 0 additions & 71 deletions control/tests/run_all.py

This file was deleted.

2 changes: 0 additions & 2 deletions control/tests/sisotool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def test_sisotool(self):
step_response_moved = np.array([[ 0., 0.02458187, 0.16529784 , 0.46602716 , 0.91012035 , 1.43364313, 1.93996334 , 2.3190105 , 2.47041552 , 2.32724853] ])
assert_array_almost_equal(ax_step.lines[0].get_data()[1][:10],step_response_moved)

def test_suite():
return unittest.TestLoader().loadTestsFromTestCase(TestSisotool)

if __name__ == "__main__":
unittest.main()
4 changes: 0 additions & 4 deletions control/tests/slycot_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ def testFreqResp(self):
decimal=2)


# These are here for once the above is made into a unittest.
def suite():
return unittest.TestLoader().loadTestsFromTestCase(TestSlycot)

if __name__ == '__main__':
unittest.main()

6 changes: 0 additions & 6 deletions control/tests/statefbk_array_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,5 @@ def tearDown(self):
reset_defaults()


def test_suite():

status1 = unittest.TestLoader().loadTestsFromTestCase(TestStatefbk)
status2 = unittest.TestLoader().loadTestsFromTestCase(TestStatefbk)
return status1 and status2

if __name__ == '__main__':
unittest.main()
Loading