Skip to content

Commit f6799ab

Browse files
authored
Merge pull request #1127 from roryyorke/lint-tests
Lint tests
2 parents d11f05d + c907a4f commit f6799ab

32 files changed

+247
-350
lines changed

control/tests/bdalg_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,19 @@ def test_bdalg_udpate_names_errors():
347347
sys2 = ctrl.rss(2, 1, 1)
348348

349349
with pytest.raises(ValueError, match="number of inputs does not match"):
350-
sys = ctrl.series(sys1, sys2, inputs=2)
350+
ctrl.series(sys1, sys2, inputs=2)
351351

352352
with pytest.raises(ValueError, match="number of outputs does not match"):
353-
sys = ctrl.series(sys1, sys2, outputs=2)
353+
ctrl.series(sys1, sys2, outputs=2)
354354

355355
with pytest.raises(ValueError, match="number of states does not match"):
356-
sys = ctrl.series(sys1, sys2, states=2)
356+
ctrl.series(sys1, sys2, states=2)
357357

358358
with pytest.raises(ValueError, match="number of states does not match"):
359-
sys = ctrl.series(ctrl.tf(sys1), ctrl.tf(sys2), states=2)
359+
ctrl.series(ctrl.tf(sys1), ctrl.tf(sys2), states=2)
360360

361361
with pytest.raises(TypeError, match="unrecognized keywords"):
362-
sys = ctrl.series(sys1, sys2, dt=1)
362+
ctrl.series(sys1, sys2, dt=1)
363363

364364

365365
class TestEnsureTf:

control/tests/bspline_test.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111

1212
import numpy as np
1313
import pytest
14-
import scipy as sp
1514

1615
import control as ct
1716
import control.flatsys as fs
18-
import control.optimal as opt
1917

2018
def test_bspline_basis():
2119
Tf = 10
@@ -182,40 +180,40 @@ def test_kinematic_car_multivar():
182180
def test_bspline_errors():
183181
# Breakpoints must be a 1D array, in increasing order
184182
with pytest.raises(NotImplementedError, match="not yet supported"):
185-
basis = fs.BSplineFamily([[0, 1, 3], [0, 2, 3]], [3, 3])
183+
fs.BSplineFamily([[0, 1, 3], [0, 2, 3]], [3, 3])
186184

187185
with pytest.raises(ValueError,
188186
match="breakpoints must be convertable to a 1D array"):
189-
basis = fs.BSplineFamily([[[0, 1], [0, 1]], [[0, 1], [0, 1]]], [3, 3])
187+
fs.BSplineFamily([[[0, 1], [0, 1]], [[0, 1], [0, 1]]], [3, 3])
190188

191189
with pytest.raises(ValueError, match="must have at least 2 values"):
192-
basis = fs.BSplineFamily([10], 2)
190+
fs.BSplineFamily([10], 2)
193191

194192
with pytest.raises(ValueError, match="must be strictly increasing"):
195-
basis = fs.BSplineFamily([1, 3, 2], 2)
193+
fs.BSplineFamily([1, 3, 2], 2)
196194

197195
# Smoothness can't be more than dimension of splines
198-
basis = fs.BSplineFamily([0, 1], 4, 3) # OK
196+
fs.BSplineFamily([0, 1], 4, 3) # OK
199197
with pytest.raises(ValueError, match="degree must be greater"):
200-
basis = fs.BSplineFamily([0, 1], 4, 4) # not OK
198+
fs.BSplineFamily([0, 1], 4, 4) # not OK
201199

202200
# nvars must be an integer
203201
with pytest.raises(TypeError, match="vars must be an integer"):
204-
basis = fs.BSplineFamily([0, 1], 4, 3, vars=['x1', 'x2'])
202+
fs.BSplineFamily([0, 1], 4, 3, vars=['x1', 'x2'])
205203

206204
# degree, smoothness must match nvars
207205
with pytest.raises(ValueError, match="length of 'degree' does not match"):
208-
basis = fs.BSplineFamily([0, 1], [4, 4, 4], 3, vars=2)
206+
fs.BSplineFamily([0, 1], [4, 4, 4], 3, vars=2)
209207

210208
# degree, smoothness must be list of ints
211-
basis = fs.BSplineFamily([0, 1], [4, 4], 3, vars=2) # OK
209+
fs.BSplineFamily([0, 1], [4, 4], 3, vars=2) # OK
212210
with pytest.raises(ValueError, match="could not parse 'degree'"):
213-
basis = fs.BSplineFamily([0, 1], [4, '4'], 3, vars=2)
211+
fs.BSplineFamily([0, 1], [4, '4'], 3, vars=2)
214212

215213
# degree must be strictly positive
216214
with pytest.raises(ValueError, match="'degree'; must be at least 1"):
217-
basis = fs.BSplineFamily([0, 1], 0, 1)
215+
fs.BSplineFamily([0, 1], 0, 1)
218216

219217
# smoothness must be non-negative
220218
with pytest.raises(ValueError, match="'smoothness'; must be at least 0"):
221-
basis = fs.BSplineFamily([0, 1], 2, -1)
219+
fs.BSplineFamily([0, 1], 2, -1)

control/tests/config_test.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,8 @@ def test_system_indexing(self):
339339
{'dt': 0.1}
340340
])
341341
def test_repr_format(self, kwargs):
342-
from ..statesp import StateSpace
343-
from numpy import array
344-
345342
sys = ct.ss([[1]], [[1]], [[1]], [[0]], **kwargs)
346-
new = eval(repr(sys))
343+
new = eval(repr(sys), None, {'StateSpace':ct.StateSpace, 'array':np.array})
347344
for attr in ['A', 'B', 'C', 'D']:
348345
assert getattr(new, attr) == getattr(sys, attr)
349346
for prop in ['input_labels', 'output_labels', 'state_labels']:

control/tests/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
"""conftest.py - pytest local plugins, fixtures, marks and functions."""
22

3-
import os
4-
from contextlib import contextmanager
5-
63
import matplotlib as mpl
74
import numpy as np
85
import pytest

control/tests/ctrlplot_test.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def setup_plot_arguments(resp_fcn, plot_fcn, compute_time_response=True):
7474
case ct.gangof4_response, _:
7575
args1 = (sys1, sys1c)
7676
args2 = (sys2, sys1c)
77-
default_labels = ["P=sys[1]", "P=sys[2]"]
7877

7978
case ct.frequency_response, ct.nichols_plot:
8079
args1 = (sys1, None) # to allow *fmt in linestyle test
@@ -239,10 +238,10 @@ def test_plot_ax_processing(resp_fcn, plot_fcn):
239238
# Call the plotting function, passing the axes
240239
if resp_fcn is not None:
241240
resp = resp_fcn(*args, **kwargs, **resp_kwargs)
242-
cplt4 = resp.plot(**kwargs, **meth_kwargs, ax=ax)
241+
resp.plot(**kwargs, **meth_kwargs, ax=ax)
243242
else:
244243
# No response function available; just plot the data
245-
cplt4 = plot_fcn(*args, **kwargs, **plot_kwargs, ax=ax)
244+
plot_fcn(*args, **kwargs, **plot_kwargs, ax=ax)
246245

247246
# Check to make sure original settings did not change
248247
assert fig._suptitle.get_text() == title
@@ -331,19 +330,9 @@ def test_plot_label_processing(resp_fcn, plot_fcn):
331330
@pytest.mark.parametrize("resp_fcn, plot_fcn", resp_plot_fcns)
332331
@pytest.mark.usefixtures('mplcleanup')
333332
def test_plot_linestyle_processing(resp_fcn, plot_fcn):
334-
# Create some systems to use
335-
sys1 = ct.rss(2, 1, 1, strictly_proper=True, name="sys[1]")
336-
sys1c = ct.rss(4, 1, 1, strictly_proper=True, name="sys[1]_C")
337-
sys2 = ct.rss(4, 1, 1, strictly_proper=True, name="sys[2]")
338-
339333
# Set up arguments
340334
args1, args2, _, kwargs, meth_kwargs, plot_kwargs, resp_kwargs = \
341335
setup_plot_arguments(resp_fcn, plot_fcn)
342-
default_labels = ["sys[1]", "sys[2]"]
343-
expected_labels = ["sys1_", "sys2_"]
344-
match resp_fcn, plot_fcn:
345-
case ct.gangof4_response, _:
346-
default_labels = ["P=sys[1]", "P=sys[2]"]
347336

348337
# Set line color
349338
cplt1 = plot_fcn(*args1, **kwargs, **plot_kwargs, color='r')
@@ -491,16 +480,10 @@ def test_mimo_plot_legend_processing(resp_fcn, plot_fcn):
491480
@pytest.mark.parametrize("resp_fcn, plot_fcn", resp_plot_fcns)
492481
@pytest.mark.usefixtures('mplcleanup')
493482
def test_plot_title_processing(resp_fcn, plot_fcn):
494-
# Create some systems to use
495-
sys1 = ct.rss(2, 1, 1, strictly_proper=True, name="sys[1]")
496-
sys1c = ct.rss(4, 1, 1, strictly_proper=True, name="sys[1]_C")
497-
sys2 = ct.rss(2, 1, 1, strictly_proper=True, name="sys[2]")
498-
499483
# Set up arguments
500484
args1, args2, argsc, kwargs, meth_kwargs, plot_kwargs, resp_kwargs = \
501485
setup_plot_arguments(resp_fcn, plot_fcn)
502486
default_title = "sys[1], sys[2]"
503-
expected_title = "sys1_, sys2_"
504487
match resp_fcn, plot_fcn:
505488
case ct.gangof4_response, _:
506489
default_title = "P=sys[1], C=sys[1]_C, P=sys[2], C=sys[1]_C"
@@ -536,7 +519,7 @@ def test_plot_title_processing(resp_fcn, plot_fcn):
536519
case ct.input_output_response, _:
537520
title_prefix = "Input/output response for "
538521
case _:
539-
raise RuntimeError(f"didn't recognize {resp_fnc}, {plot_fnc}")
522+
raise RuntimeError(f"didn't recognize {resp_fcn}, {plot_fcn}")
540523

541524
# Generate the first plot, with default title
542525
cplt1 = plot_fcn(*args1, **kwargs, **plot_kwargs)
@@ -587,11 +570,9 @@ def test_plot_title_processing(resp_fcn, plot_fcn):
587570
@pytest.mark.usefixtures('mplcleanup')
588571
def test_tickmark_label_processing(plot_fcn):
589572
# Generate the response that we will use for plotting
590-
top_row, bot_row = 0, -1
591573
match plot_fcn:
592574
case ct.bode_plot:
593575
resp = ct.frequency_response(ct.rss(4, 2, 2))
594-
top_row = 1
595576
case ct.time_response_plot:
596577
resp = ct.step_response(ct.rss(4, 2, 2))
597578
case ct.gangof4_plot:
@@ -625,20 +606,9 @@ def test_tickmark_label_processing(plot_fcn):
625606
@pytest.mark.parametrize("resp_fcn, plot_fcn", resp_plot_fcns)
626607
@pytest.mark.usefixtures('mplcleanup', 'editsdefaults')
627608
def test_rcParams(resp_fcn, plot_fcn):
628-
# Create some systems to use
629-
sys1 = ct.rss(2, 1, 1, strictly_proper=True, name="sys[1]")
630-
sys1c = ct.rss(4, 1, 1, strictly_proper=True, name="sys[1]_C")
631-
sys2 = ct.rss(2, 1, 1, strictly_proper=True, name="sys[2]")
632-
633609
# Set up arguments
634610
args1, args2, argsc, kwargs, meth_kwargs, plot_kwargs, resp_kwargs = \
635611
setup_plot_arguments(resp_fcn, plot_fcn)
636-
default_title = "sys[1], sys[2]"
637-
expected_title = "sys1_, sys2_"
638-
match resp_fcn, plot_fcn:
639-
case ct.gangof4_response, _:
640-
default_title = "P=sys[1], C=sys[1]_C, P=sys[2], C=sys[1]_C"
641-
642612
# Create new set of rcParams
643613
my_rcParams = {}
644614
for key in ct.ctrlplot.rcParams:

control/tests/descfcn_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ def test_describing_function_exceptions():
205205
assert saturation(3) == 2
206206

207207
# Turn off the bias check
208-
bias = ct.describing_function(saturation, 0, zero_check=False)
208+
ct.describing_function(saturation, 0, zero_check=False)
209209

210210
# Function should evaluate to zero at zero amplitude
211211
f = lambda x: x + 0.5
212212
with pytest.raises(ValueError, match="must evaluate to zero"):
213-
bias = ct.describing_function(f, 0, zero_check=True)
213+
ct.describing_function(f, 0, zero_check=True)
214214

215215
# Evaluate at a negative amplitude
216216
with pytest.raises(ValueError, match="cannot evaluate"):
@@ -236,4 +236,4 @@ def test_describing_function_exceptions():
236236
# Describing function plot for non-describing function object
237237
resp = ct.frequency_response(H_simple)
238238
with pytest.raises(TypeError, match="data must be DescribingFunction"):
239-
cplt = ct.describing_function_plot(resp)
239+
ct.describing_function_plot(resp)

0 commit comments

Comments
 (0)