<s> from __future__ import print_function <EOL> from nose . tools import nottest , raises , eq_ <EOL> import os <EOL> try : <EOL> os . environ . pop ( '<STR_LIT>' ) <EOL> except : <EOL> pass <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> import numpy as np <EOL> import librosa <EOL> from test_core import files , load <EOL> __EXAMPLE_FILE = '<STR_LIT>' <EOL> def test_onset_strength ( ) : <EOL> def __test ( infile ) : <EOL> DATA = load ( infile ) <EOL> onsets = librosa . onset . onset_strength ( y = None , <EOL> sr = <NUM_LIT> , <EOL> S = DATA [ '<STR_LIT:D>' ] , <EOL> lag = <NUM_LIT:1> , <EOL> max_size = <NUM_LIT:1> , <EOL> center = False , <EOL> detrend = True , <EOL> aggregate = np . mean ) <EOL> assert np . allclose ( onsets [ <NUM_LIT:1> : ] , DATA [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> pass <EOL> for infile in files ( '<STR_LIT>' ) : <EOL> yield ( __test , infile ) <EOL> def test_tempo ( ) : <EOL> def __test ( infile ) : <EOL> DATA = load ( infile ) <EOL> tempo = librosa . beat . estimate_tempo ( DATA [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> sr = <NUM_LIT> , <EOL> hop_length = <NUM_LIT:32> , <EOL> start_bpm = <NUM_LIT> ) <EOL> assert ( np . allclose ( tempo , DATA [ '<STR_LIT:t>' ] [ <NUM_LIT:0> , <NUM_LIT:0> ] ) or <EOL> np . allclose ( tempo , DATA [ '<STR_LIT:t>' ] [ <NUM_LIT:0> , <NUM_LIT:1> ] ) ) <EOL> for infile in files ( '<STR_LIT>' ) : <EOL> yield ( __test , infile ) <EOL> @ raises ( librosa . ParameterError ) <EOL> def test_beat_no_input ( ) : <EOL> librosa . beat . beat_track ( y = None , onset_envelope = None ) <EOL> def test_beat_no_onsets ( ) : <EOL> sr = <NUM_LIT> <EOL> hop_length = <NUM_LIT> <EOL> duration = <NUM_LIT:30> <EOL> onsets = np . zeros ( duration * sr // hop_length ) <EOL> tempo , beats = librosa . beat . beat_track ( onset_envelope = onsets , <EOL> sr = sr , <EOL> hop_length = hop_length ) <EOL> assert np . allclose ( tempo , <NUM_LIT:0> ) <EOL> eq_ ( len ( beats ) , <NUM_LIT:0> ) <EOL> def test_tempo_no_onsets ( ) : <EOL> sr = <NUM_LIT> <EOL> hop_length = <NUM_LIT> <EOL> duration = <NUM_LIT:30> <EOL> onsets = np . zeros ( duration * sr // hop_length ) <EOL> def __test ( start_bpm ) : <EOL> tempo = librosa . beat . estimate_tempo ( onsets , sr = sr , <EOL> hop_length = hop_length , <EOL> start_bpm = start_bpm ) <EOL> eq_ ( tempo , start_bpm ) <EOL> for start_bpm in [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] : <EOL> yield __test , start_bpm <EOL> def test_beat ( ) : <EOL> y , sr = librosa . load ( __EXAMPLE_FILE ) <EOL> hop_length = <NUM_LIT> <EOL> onset_env = librosa . onset . onset_strength ( y = y , sr = sr , hop_length = hop_length ) <EOL> def __test ( with_audio , with_tempo , start_bpm , bpm , trim , tightness ) : <EOL> if with_audio : <EOL> _y = y <EOL> _ons = None <EOL> else : <EOL> _y = None <EOL> _ons = onset_env <EOL> tempo , beats = librosa . beat . beat_track ( y = _y , <EOL> sr = sr , <EOL> onset_envelope = _ons , <EOL> hop_length = hop_length , <EOL> start_bpm = start_bpm , <EOL> tightness = tightness , <EOL> trim = trim , <EOL> bpm = bpm ) <EOL> assert tempo >= <NUM_LIT:0> <EOL> if len ( beats ) > <NUM_LIT:0> : <EOL> assert beats . min ( ) >= <NUM_LIT:0> <EOL> assert beats . max ( ) <= len ( onset_env ) <EOL> for with_audio in [ False , True ] : <EOL> for with_tempo in [ False , True ] : <EOL> for trim in [ False , True ] : <EOL> for start_bpm in [ - <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] : <EOL> for bpm in [ - <NUM_LIT:20> , <NUM_LIT:0> , None , <NUM_LIT> , <NUM_LIT> ] : <EOL> for tightness in [ <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT> ] : <EOL> if ( tightness <= <NUM_LIT:0> or <EOL> ( bpm is not None and bpm <= <NUM_LIT:0> ) or <EOL> ( start_bpm is not None and bpm is None and start_bpm <= <NUM_LIT:0> ) ) : <EOL> tf = raises ( librosa . ParameterError ) ( __test ) <EOL> else : <EOL> tf = __test <EOL> yield ( tf , with_audio , with_tempo , <EOL> start_bpm , bpm , trim , tightness ) <EOL> @ nottest <EOL> def deprecated_test_beat ( ) : <EOL> def __test ( infile ) : <EOL> DATA = load ( infile ) <EOL> ( bpm , beats ) = librosa . beat . beat_track ( y = None , <EOL> sr = <NUM_LIT> , <EOL> hop_length = <NUM_LIT:32> , <EOL> onset_envelope = DATA [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> beat_times = librosa . frames_to_time ( beats , sr = <NUM_LIT> , hop_length = <NUM_LIT:32> ) <EOL> assert np . allclose ( beat_times , DATA [ '<STR_LIT>' ] ) <EOL> for infile in files ( '<STR_LIT>' ) : <EOL> yield ( __test , infile ) </s>
