<commit_before>#!/usr/bin/env python

from __future__ import print_function

import librosa
import numpy as np
import jams

import re
import six

import muda
from copy import deepcopy

from nose.tools import eq_, raises

def ap_(a, b, msg=None, rtol=1e-5, atol=1e-5):
    """Shorthand for 'assert np.allclose(a, b, rtol, atol), "%r != %r" % (a, b)
    """
    if not np.allclose(a, b, rtol=rtol, atol=atol):
        raise AssertionError(msg or "{} != {}".format(a, b))


jam_fixture = muda.load_jam_audio('data/fixture.jams', 'data/fixture.wav')

def __test_time(jam_orig, jam_new, rate):

    # Test the track length
    ap_(librosa.get_duration(**jam_orig.sandbox.muda['_audio']),
        rate * librosa.get_duration(**jam_new.sandbox.muda['_audio']))

    # Test the metadata
    ap_(jam_orig.file_metadata.duration,
        rate * jam_new.file_metadata.duration)

    # Test each annotation
    for ann_orig, ann_new in zip(jam_orig.annotations, jam_new.annotations):
        # FIXME: time deformer should modify this
        #eq_(ann_orig.time, rate * ann_new.time)
        #eq_(ann_orig.duration, rate * ann_new.duration)

        ap_(ann_orig.data.time.values.astype(float),
            rate * ann_new.data.time.values.astype(float))
        ap_(ann_orig.data.duration.values.astype(float),<commit_msg>Added test for missing mudabox in transform<commit_after>#!/usr/bin/env python

from __future__ import print_function

import librosa
import numpy as np
import jams

import re
import six

import muda
from copy import deepcopy

from nose.tools import eq_, raises

def ap_(a, b, msg=None, rtol=1e-5, atol=1e-5):
    """Shorthand for 'assert np.allclose(a, b, rtol, atol), "%r != %r" % (a, b)
    """
    if not np.allclose(a, b, rtol=rtol, atol=atol):
        raise AssertionError(msg or "{} != {}".format(a, b))


jam_fixture = muda.load_jam_audio('data/fixture.jams', 'data/fixture.wav')


@raises(RuntimeError)
def test_raw():

    jam_raw = jams.load('data/fixture.jams')
    D = muda.deformers.TimeStretch(rate=2.0)

    six.next(D.transform(jam_raw))


def __test_time(jam_orig, jam_new, rate):

    # Test the track length
    ap_(librosa.get_duration(**jam_orig.sandbox.muda['_audio']),
        rate * librosa.get_duration(**jam_new.sandbox.muda['_audio']))

    # Test the metadata
    ap_(jam_orig.file_metadata.duration,
        rate * jam_new.file_metadata.duration)

    # Test each annotation
    for ann_orig, ann_new in zip(jam_orig.annotations, jam_new.annotations):
        # FIXME: time deformer should modify this
        #eq_(ann_orig.time, rate * ann_new.time)
        #eq_(ann_orig.duration, rate * ann_new.duration)

        ap_(ann_orig.data.time.values.astype(float),
            rate * ann_new.data.time.values.astype(float))
        ap_(ann_orig.data.duration.values.astype(float),
{'fraction_non_alphanumeric': 0.13103693181818182, 'fraction_numerical': 0.0035511363636363635, 'mean_word_length': 3.633223684210526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '321575', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1005, 'n_words': 217}