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

import unittest
from unit_timeside import TestRunner
from timeside.core.tools.test_samples import samples
from timeside.core import get_processor


FileDecoder = get_processor('file_decoder')
try:
    AubioSpecdesc = get_processor('aubio_specdesc')
except:
    AubioSpecdesc = None


@unittest.skipIf(not AubioSpecdesc, 'Aubio library is not available')
class TestAubioSpecdesc(unittest.TestCase):

    def setUp(self):
        self.analyzer = AubioSpecdesc()

    def testOnSweep(self):
        "runs on sweep"
        self.source = samples["sweep.wav"]

    def testOnC4Scale(self):
        "runs on C4 scale"
        self.source = samples["C4_scale.wav"]

    def tearDown(self):
        decoder = FileDecoder(self.source)
        (decoder | self.analyzer).run()
        results = self.analyzer.results
        #results.to_yaml()
        #results.to_json()
        #results.to_xml()

if __name__ == '__main__':
    unittest.main(testRunner=TestRunner())<commit_msg>[test] make sure aubio_specdesc results have the expected duration<commit_after>#! /usr/bin/env python

import unittest
from unit_timeside import TestRunner
from timeside.core.tools.test_samples import samples
from timeside.core import get_processor


FileDecoder = get_processor('file_decoder')
try:
    AubioSpecdesc = get_processor('aubio_specdesc')
except:
    AubioSpecdesc = None


@unittest.skipIf(not AubioSpecdesc, 'Aubio library is not available')
class TestAubioSpecdesc(unittest.TestCase):

    def setUp(self):
        self.analyzer = AubioSpecdesc()

    def testOnSweep(self):
        "runs on sweep"
        self.source = samples["sweep.wav"]

    def testOnC4Scale(self):
        "runs on C4 scale"
        self.source = samples["C4_scale.wav"]

    def tearDown(self):
        decoder = FileDecoder(self.source)
        (decoder | self.analyzer).run()
        results = self.analyzer.results
        #results.to_yaml()
        #results.to_json()
        #results.to_xml()

        for proc_id in results.list_id():
            result = results.get_result_by_id (proc_id)
            # check we have a result with coherent length (±100ms)
            duration = result.audio_metadata.duration
            data_duration = result.data_object.time[-1]
            self.assertAlmostEqual (duration, data_duration, 1)

if __name__ == '__main__':
    unittest.main(testRunner=TestRunner())
{'fraction_non_alphanumeric': 0.10054009140008309, 'fraction_numerical': 0.004570004154549232, 'mean_word_length': 3.254416961130742, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3924041', 'n_tokens_mistral': 774, 'n_tokens_neox': 749, 'n_words': 167}