Skip to content
Closed
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
29 changes: 12 additions & 17 deletions control/tests/rlocus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
RMM, 1 Jul 2011
"""

import signal

import matplotlib.pyplot as plt
import numpy as np
from numpy.testing import assert_array_almost_equal
import pytest
import scipy as sp

import control as ct
from control.rlocus import root_locus, _RLClickDispatcher
Expand Down Expand Up @@ -76,6 +79,8 @@ def test_root_locus_zoom(self):
assert_array_almost_equal(zoom_x, zoom_x_valid)
assert_array_almost_equal(zoom_y, zoom_y_valid)

@pytest.mark.skipif(not hasattr(signal, 'SIGALRM'),
reason="SIGALRM is Unix only")
def test_rlocus_default_wn(self):
"""Check that default wn calculation works properly"""
#
Expand All @@ -87,25 +92,15 @@ def test_rlocus_default_wn(self):
# This unit test makes sure that is fixed by generating a test case
# that will take a long time to do the calculation (minutes).
#
import scipy as sp
import signal

# Define a system that exhibits this behavior
sys = ct.tf(*sp.signal.zpk2tf(
[-1e-2, 1-1e7j, 1+1e7j], [0, -1e7j, 1e7j], 1))

# Set up a timer to catch execution time
try:
def signal_handler(signum, frame):
raise Exception("rlocus took too long to complete")
signal.signal(signal.SIGALRM, signal_handler)

# Run the command and reset the alarm
signal.alarm(2) # 2 second timeout
ct.root_locus(sys)
signal.alarm(0) # reset the alarm

except AttributeError:
# If no SIGALRM (eg, on Windows), then skip this test
pass
def signal_handler(signum, frame):
raise Exception("rlocus took too long to complete")
signal.signal(signal.SIGALRM, signal_handler)

# Run the command and reset the alarm
signal.alarm(2) # 2 second timeout
ct.root_locus(sys)
signal.alarm(0) # reset the alarm