Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7893b7b

Browse files
committed
Added test to check if specgram() warning is raised if len(x)<=NFFT.
1 parent 62ad55b commit 7893b7b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/matplotlib/tests/test_mlab.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import six
55

66
import tempfile
7+
import warnings
78

89
from numpy.testing import (assert_allclose, assert_almost_equal,
910
assert_array_equal)
@@ -2103,6 +2104,14 @@ def test_specgram_phase(self):
21032104
assert spec.shape[0] == freqs.shape[0]
21042105
assert spec.shape[1] == self.t_specgram.shape[0]
21052106

2107+
def test_specgram_warn_only1seg(self):
2108+
"""Warning should be raised if len(x) <= len(NFFT). """
2109+
with warnings.catch_warnings(record=True) as w:
2110+
mlab.specgram(x=self.y, NFFT=len(self.y), Fs=self.Fs)
2111+
assert len(w) == 1
2112+
assert issubclass(w[0].category, UserWarning)
2113+
assert str(w[0].message).startswith("Only one segment is calculated")
2114+
21062115
def test_psd_csd_equal(self):
21072116
freqs = self.freqs_density
21082117
Pxx, freqsxx = mlab.psd(x=self.y,

0 commit comments

Comments
 (0)