File: test_failures.py

package info (click to toggle)
python-librosa 0.11.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 166,732 kB
  • sloc: python: 21,731; makefile: 141; sh: 2
file content (127 lines) | stat: -rw-r--r-- 3,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# CREATED:2014-12-29 10:52:23 by Brian McFee <brian.mcfee@nyu.edu>
# unit tests for ill-formed inputs

# Disable cache
import os

try:
    os.environ.pop("LIBROSA_CACHE_DIR")
except KeyError:
    pass

import numpy as np
import librosa
import pytest


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_int():
    y = np.zeros(10, dtype=int)
    librosa.util.valid_audio(y)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_scalar():
    y = np.array(0.0)
    librosa.util.valid_audio(y)


def test_valid_stereo_or_mono():
    """valid_audio: mono=False, y.ndim==1"""
    y = np.zeros(1000)
    librosa.util.valid_audio(y)


def test_valid_stereo():
    """valid_audio: mono=False, y.ndim==2"""
    y = np.zeros((1000, 2)).T
    librosa.util.valid_audio(y)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_type():
    """valid_audio: list input"""
    y = list(np.zeros(1000))
    librosa.util.valid_audio(y)  # type: ignore


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_nan():
    """valid_audio: NaN"""
    y = np.zeros(1000)
    y[10] = np.nan
    librosa.util.valid_audio(y)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_valid_audio_inf():
    """valid_audio: Inf"""
    y = np.zeros(1000)
    y[10] = np.inf
    librosa.util.valid_audio(y)


def test_valid_audio_strided():
    """valid_audio: strided"""
    y = np.zeros(1000)[::2]
    librosa.util.valid_audio(y)


def test_valid_audio_clang():
    """valid_audio: C-contiguous"""
    y = np.zeros(1000).reshape(2, 500)
    librosa.util.valid_audio(y)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_frame_hop():
    """frame: hop_length=0"""
    y = np.zeros(128)
    librosa.util.frame(y, frame_length=10, hop_length=0)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_frame_size():
    # frame: len(y) == 128, frame_length==256, hop_length=128
    y = np.zeros(64)
    librosa.util.frame(y, frame_length=256, hop_length=128)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_frame_size_difference():
    # In response to issue #385
    # https://github.com/librosa/librosa/issues/385
    # frame: len(y) == 129, frame_length==256, hop_length=128
    y = np.zeros(129)
    librosa.util.frame(y, frame_length=256, hop_length=128)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_stft_bad_window():

    y = np.zeros(22050 * 5)

    n_fft = 2048
    window = np.ones(n_fft // 2)

    librosa.stft(y, n_fft=n_fft, window=window)


@pytest.mark.xfail(raises=librosa.ParameterError)
def test_istft_bad_window():

    D = np.zeros((1025, 10), dtype=np.complex64)

    n_fft = 2 * (D.shape[0] - 1)

    window = np.ones(n_fft // 2)

    librosa.istft(D, window=window)


@pytest.mark.xfail(raises=librosa.ParameterError)
@pytest.mark.parametrize("y", [np.empty(22050)])
@pytest.mark.parametrize("mode", ["wrap", "maximum", "minimum", "median", "mean"])
def test_stft_bad_pad(y, mode):
    librosa.stft(y, pad_mode=mode)