def test_read_existing_single_mp3():
    '''
    reading an existing MP3 through the read_single_wav
    should raise ValueError
    '''
    with pytest.raises(ValueError):
        wbr.read_single_wav(EXISTING_SINGLE_MP3)
def test_read_nonexisting_single_wav():
    '''
    reading a non-existing wav file through the read_single_wav
    should raise IOError
    '''
    with pytest.raises(FileNotFoundError):
        wbr.read_single_wav(NON_EXISTING_SINGLE_WAV)
def iter_list_mp3(file_paths, save_to_dir=None):
    '''
    if save_to_dir is None, the intermediates will be deleted,
        after the list has been iterated over
    '''
    delete_intermediates = False
    if save_to_dir is None:
        delete_intermediates = True
        save_to_dir = os.path.dirname(file_paths[0]) + os.sep + "wav_temp"
        # FIXME: @motjuste: if the first file in the list does not exist

    paths_to_wavs = []

    for fp in file_paths:
        paths_to_wavs.append(convert_single_mp3ToWav(fp, save_to_dir))
        yield wbr.read_single_wav(paths_to_wavs[-1], orig_file_path=fp)

    if delete_intermediates:
        for w in paths_to_wavs:
            os.remove(w)
        try:
            os.rmdir(save_to_dir)
        except OSError:
            print(save_to_dir, " was not deleted")
            print("Probably existing from previous run")
            print("Delete Manually")
def test_read_single_wav_samplingFreq():
    '''
    result of reading an existing WAV has sampling frequency
    EXISTING_SINGLE_WAV above has known sampling freq of 44100
    '''
    result = wbr.read_single_wav(EXISTING_SINGLE_WAV)

    assert result["sampling_frequency"] == 44100
def read_single_mp3(file_path, save_to_dir=None):
    '''
    Reads single mp3, converts to wav, then reads it using wavBasicRead
    if save_to_dir is None, the intermediate wav file is deleted
    '''
    delete_intermediate = False
    if save_to_dir is None:
        delete_intermediate = True
        save_to_dir = os.path.dirname(file_path) + os.sep + "wav_temp"

    path_to_wav = convert_single_mp3ToWav(file_path, save_to_dir)
    read_wav = wbr.read_single_wav(path_to_wav, orig_file_path=file_path)

    if delete_intermediate:
        os.remove(path_to_wav)
        try:
            os.rmdir(save_to_dir)
        except OSError:
            print(save_to_dir, " was not deleted")
            print("Probably existing from previous run")
            print("Delete Manually")

    return read_wav
def test_read_existing_single_wav():
    '''
    reading an existing wav file through the read_single_wav
    should not raise exception
    '''
    wbr.read_single_wav(EXISTING_SINGLE_WAV)