Skip to content

Commit 06fcb90

Browse files
committed
update unit tests + tweak formatting for consistency
1 parent ce0ad48 commit 06fcb90

File tree

10 files changed

+212
-195
lines changed

10 files changed

+212
-195
lines changed

control/frdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def _repr_eval_(self):
425425
smooth=(self._ifunc and ", smooth=True") or "")
426426

427427
out += self._dt_repr()
428-
if len(labels := self._label_repr()) > 0:
428+
if len(labels := self._label_repr(show_count=False)) > 0:
429429
out += ",\n" + labels
430430

431431
out += ")"

control/iosys.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def __str__(self):
253253
out += f"\nOutputs ({self.noutputs}): {self.output_labels}"
254254
if self.nstates is not None:
255255
out += f"\nStates ({self.nstates}): {self.state_labels}"
256-
out += self._dt_repr("\n")
256+
out += self._dt_repr(separator="\n", space=" ")
257257
return out
258258

259259
def __repr__(self):
@@ -262,7 +262,7 @@ def __repr__(self):
262262
def _repr_info_(self, html=False):
263263
out = f"<{self.__class__.__name__} {self.name}: " + \
264264
f"{list(self.input_labels)} -> {list(self.output_labels)}"
265-
out += self._dt_repr(", ") + ">"
265+
out += self._dt_repr(separator=", ", space="") + ">"
266266

267267
if html:
268268
# Replace symbols that might be interpreted by HTML processing
@@ -353,10 +353,11 @@ def _label_repr(self, show_count=True):
353353

354354
return out
355355

356-
def _dt_repr(self, separator="\n"):
356+
def _dt_repr(self, separator="\n", space=""):
357357
if config.defaults['control.default_dt'] != self.dt:
358-
return "{separator}dt={dt}".format(
359-
separator=separator, dt='None' if self.dt is None else self.dt)
358+
return "{separator}dt{space}={space}{dt}".format(
359+
separator=separator, space=space,
360+
dt='None' if self.dt is None else self.dt)
360361
else:
361362
return ""
362363

control/statesp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def _repr_eval_(self):
393393
A=self.A.__repr__(), B=self.B.__repr__(),
394394
C=self.C.__repr__(), D=self.D.__repr__())
395395

396-
out += super()._dt_repr(",\n")
396+
out += super()._dt_repr(separator=",\n", space="")
397397
if len(labels := super()._label_repr(show_count=False)) > 0:
398398
out += ",\n" + labels
399399

@@ -421,9 +421,11 @@ def _repr_html_(self):
421421
if syssize > config.defaults['statesp.latex_maxsize']:
422422
return None
423423
elif config.defaults['statesp.latex_repr_type'] == 'partitioned':
424-
return super()._repr_info_(html=True) + self._latex_partitioned()
424+
return super()._repr_info_(html=True) + \
425+
"\n" + self._latex_partitioned()
425426
elif config.defaults['statesp.latex_repr_type'] == 'separate':
426-
return super()._repr_info_(html=True) + self._latex_separate()
427+
return super()._repr_info_(html=True) + \
428+
"\n" + self._latex_separate()
427429
else:
428430
raise ValueError(
429431
"Unknown statesp.latex_repr_type '{cfg}'".format(

control/tests/docstrings_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
control.lqe: '567bf657538935173f2e50700ba87168',
3636
control.lqr: 'a3e0a85f781fc9c0f69a4b7da4f0bd22',
3737
control.margin: 'f02b3034f5f1d44ce26f916cc3e51600',
38-
control.parallel: '025c5195a34c57392223374b6244a8c4',
38+
control.parallel: 'bfc470aef75dbb923f9c6fb8bf3c9b43',
3939
control.series: '9aede1459667738f05cf4fc46603a4f6',
4040
control.ss2tf: '48ff25d22d28e7b396e686dd5eb58831',
4141
control.tf2ss: '086a3692659b7321c2af126f79f4bc11',

control/tests/frd_test.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -468,9 +468,8 @@ def test_repr_str(self):
468468
ref_common = "FrequencyResponseData(\n" \
469469
"array([[[1. +0.j , 0.9 +0.1j, 0.1 +2.j , 0.05+3.j ]]]),\n" \
470470
"array([ 0.1, 1. , 10. , 100. ]),"
471-
ref0 = ref_common + "\nname='sys0', outputs=1, inputs=1)"
472-
ref1 = ref_common + " smooth=True," + \
473-
"\nname='sys1', outputs=1, inputs=1)"
471+
ref0 = ref_common + "\nname='sys0')"
472+
ref1 = ref_common + " smooth=True," + "\nname='sys1')"
474473
sysm = ct.frd(
475474
np.matmul(array([[1], [2]]), sys0.fresp), sys0.omega, name='sysm')
476475

@@ -505,19 +504,22 @@ def test_repr_str(self):
505504
Outputs (1): ['y[0]']
506505
507506
Input 1 to output 1:
508-
Freq [rad/s] Response
509-
------------ ---------------------
510-
0.100 1 +0j
511-
1.000 0.9 +0.1j
512-
10.000 0.1 +2j
513-
100.000 0.05 +3j
507+
508+
Freq [rad/s] Response
509+
------------ ---------------------
510+
0.100 1 +0j
511+
1.000 0.9 +0.1j
512+
10.000 0.1 +2j
513+
100.000 0.05 +3j
514+
514515
Input 2 to output 1:
515-
Freq [rad/s] Response
516-
------------ ---------------------
517-
0.100 2 +0j
518-
1.000 1.8 +0.2j
519-
10.000 0.2 +4j
520-
100.000 0.1 +6j"""
516+
517+
Freq [rad/s] Response
518+
------------ ---------------------
519+
0.100 2 +0j
520+
1.000 1.8 +0.2j
521+
10.000 0.2 +4j
522+
100.000 0.1 +6j"""
521523
assert str(sysm) == refm
522524

523525
def test_unrecognized_keyword(self):

control/tests/iosys_test.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,32 +2290,32 @@ def test_signal_indexing():
22902290

22912291
@slycotonly
22922292
@pytest.mark.parametrize("fcn, spec, expected, missing", [
2293-
(ct.ss, {}, "\nstates=4, outputs=3, inputs=2", r"dt|name"),
2294-
(ct.tf, {}, "\noutputs=3, inputs=2", r"dt|name|states"),
2295-
(ct.frd, {}, "\noutputs=3, inputs=2", r"dt|states|name"),
2296-
(ct.ss, {'dt': 0.1}, ".*\ndt=0.1,\nstates=4, outputs=3, inputs=2", r"name"),
2297-
(ct.tf, {'dt': 0.1}, ".*\ndt=0.1,\noutputs=3, inputs=2", r"name|states"),
2293+
(ct.ss, {}, "", r"states|inputs|outputs|dt|name"),
2294+
(ct.tf, {}, "", r"states|inputs|outputs|dt|name"),
2295+
(ct.frd, {}, "", r"states|inputs|outputs|dt|name"),
2296+
(ct.ss, {'dt': 0.1}, ".*\ndt=0.1", r"states|inputs|outputs|name"),
2297+
(ct.tf, {'dt': 0.1}, ".*\ndt=0.1", r"states|inputs|outputs|name"),
22982298
(ct.frd, {'dt': 0.1},
2299-
".*\ndt=0.1,\noutputs=3, inputs=2", r"name|states"),
2300-
(ct.ss, {'dt': True}, "\ndt=True,\nstates=4, outputs=3, inputs=2", r"name"),
2301-
(ct.ss, {'dt': None}, "\ndt=None,\nstates=4, outputs=3, inputs=2", r"name"),
2302-
(ct.ss, {'dt': 0}, "\nstates=4, outputs=3, inputs=2", r"dt|name"),
2303-
(ct.ss, {'name': 'mysys'}, "\nname='mysys',", r"dt"),
2304-
(ct.tf, {'name': 'mysys'}, "\nname='mysys',", r"dt|states"),
2305-
(ct.frd, {'name': 'mysys'}, "\nname='mysys',", r"dt|states"),
2299+
".*\ndt=0.1", r"states|inputs|outputs|name"),
2300+
(ct.ss, {'dt': True}, "\ndt=True", r"states|inputs|outputs|name"),
2301+
(ct.ss, {'dt': None}, "\ndt=None", r"states|inputs|outputs|name"),
2302+
(ct.ss, {'dt': 0}, "", r"states|inputs|outputs|dt|name"),
2303+
(ct.ss, {'name': 'mysys'}, "\nname='mysys'", r"dt"),
2304+
(ct.tf, {'name': 'mysys'}, "\nname='mysys'", r"dt|states"),
2305+
(ct.frd, {'name': 'mysys'}, "\nname='mysys'", r"dt|states"),
23062306
(ct.ss, {'inputs': ['u1']},
2307-
r"[\n]states=4, outputs=3, inputs=\['u1'\]", r"dt|name"),
2307+
r"[\n]inputs=\['u1'\]", r"states|outputs|dt|name"),
23082308
(ct.tf, {'inputs': ['u1']},
2309-
r"[\n]outputs=3, inputs=\['u1'\]", r"dt|name"),
2309+
r"[\n]inputs=\['u1'\]", r"outputs|dt|name"),
23102310
(ct.frd, {'inputs': ['u1'], 'name': 'sampled'},
2311-
r"[\n]name='sampled', outputs=3, inputs=\['u1'\]", r"dt"),
2311+
r"[\n]name='sampled', inputs=\['u1'\]", r"outputs|dt"),
23122312
(ct.ss, {'outputs': ['y1']},
2313-
r"[\n]states=4, outputs=\['y1'\], inputs=2", r"dt|name"),
2313+
r"[\n]outputs=\['y1'\]", r"states|inputs|dt|name"),
23142314
(ct.ss, {'name': 'mysys', 'inputs': ['u1']},
2315-
r"[\n]name='mysys', states=4, outputs=3, inputs=\['u1'\]", r"dt"),
2315+
r"[\n]name='mysys', inputs=\['u1'\]", r"states|outputs|dt"),
23162316
(ct.ss, {'name': 'mysys', 'states': [
23172317
'long_state_1', 'long_state_2', 'long_state_3']},
2318-
r"[\n]name='.*', states=\[.*\],[\n]outputs=3, inputs=2\)", r"dt"),
2318+
r"[\n]name='.*', states=\[.*\]\)", r"inputs|outputs|dt"),
23192319
])
23202320
@pytest.mark.parametrize("format", ['info', 'eval'])
23212321
def test_iosys_repr(fcn, spec, expected, missing, format):
@@ -2335,7 +2335,11 @@ def test_iosys_repr(fcn, spec, expected, missing, format):
23352335

23362336
# Construct the 'info' format
23372337
info_expected = f"<{sys.__class__.__name__} {sys.name}: " \
2338-
f"{sys.input_labels} -> {sys.output_labels}>"
2338+
f"{sys.input_labels} -> {sys.output_labels}"
2339+
if sys.dt != 0:
2340+
info_expected += f", dt={sys.dt}>"
2341+
else:
2342+
info_expected += ">"
23392343

23402344
# Make sure the default format is OK
23412345
out = repr(sys)

control/tests/lti_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,5 +408,5 @@ def test_printoptions(
408408
if str_expected is not None:
409409
assert re.search(str_expected, str(sys)) is not None
410410

411-
# Test LaTeX representation
412-
assert re.search(latex_expected, sys._repr_latex_()) is not None
411+
# Test LaTeX/HTML representation
412+
assert re.search(latex_expected, sys._repr_html_()) is not None

0 commit comments

Comments
 (0)