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

# author: <NAME> <<EMAIL>>

from __future__ import division

from unit_timeside import unittest, TestRunner
from timeside.plugins.decoder.utils import get_uri, get_media_uri_info, path2uri
from timeside.core.tools.test_samples import samples
import os.path


class TestGetUri(unittest.TestCase):
    "Test get_uri function"

    def testFileName(self):
        "Retrieve the uri from a filename"
        self.source = samples["sweep.wav"]

        self.uri = path2uri(os.path.abspath(self.source))

    def testUri(self):
        "Retrieve the uri from an uri"
        self.uri = 'file://already/an/uri/file.wav'
        self.source = self.uri

    def tearDown(self):
        self.assertEqual(self.uri, get_uri(self.source))


class TestGetUriWrongUri(unittest.TestCase):

    def testMissingFile(self):
        "Missing file raise IOerror"
        self.source = os.path.join(os.path.dirname(__file__),
                                   "a_missing_file.wav")

    def testNotValidUri(self):
        "Not valid uri raise IOerror"
        self.source = "://not/a/valid/uri/parisson.com"

    def testNotSupportedUriProtocol(self):
        "Not supported uri protocol raise IOerror"
        self.source = "mailto://<EMAIL>"

    def tearDown(self):
        self.assertRaises(IOError, get_uri, self.source)


class TestGetMediaInfo(unittest.TestCase):
    "Test get_media_uri_info function on an uri"

    def setUp(self):
        self.test_exact_duration = True
        self.source_duration = 8
        self.test_exact_duration = True
        self.expected_channels = 2
        self.expected_samplerate = 44100
        self.expected_depth = 0  # ?

    def testUriFromHTTP(self):
        "Test URI decoding from HTTP"
        self.source = "https://raw.githubusercontent.com/yomguy/timeside-samples/master/samples/sweep.mp3"
        self.test_exact_duration = False
        self.expected_depth = 32

    def testWav(self):
        "Test wav decoding"
        self.source = samples["sweep.wav"]

    def testWavMono(self):
        "Test mono wav decoding"
        self.source = samples["sweep_mono.wav"]

        self.expected_channels = 1

    def testWav32k(self):
        "Test 32kHz wav decoding"
        self.source = samples["sweep_32000.wav"]
        self.expected_samplerate = 32000

    def testFlac(self):
        "Test flac decoding"
        self.source = samples["sweep.flac"]
        self.expected_depth = 24

    def testOgg(self):
        "Test ogg decoding"
        self.source = samples["sweep.ogg"]
        self.test_exact_duration = False
        self.expected_depth = 0  # ?

    def testMp3(self):
        "Test mp3 decoding"
        self.source = samples["sweep.mp3"]
        self.expected_depth = 32
        self.test_exact_duration = False

    def tearDown(self):
        uri = get_uri(self.source)
        uri_info = get_media_uri_info(uri)
        if self.test_exact_duration:
            self.assertEqual(self.source_duration, uri_info['duration'])
        else:
            self.assertAlmostEqual(self.source_duration,
                                   uri_info['duration'],
                                   places=1)
        self.assertEqual(self.expected_channels,
                         uri_info['streams'][0]['channels'])
        self.assertEqual(self.expected_samplerate,
                         uri_info['streams'][0]['samplerate'])
        self.assertEqual(self.expected_depth, uri_info['streams'][0]['depth'])


if __name__ == '__main__':
    unittest.main(testRunner=TestRunner())
<commit_msg>Skip decoding HTTPS URI test for now<commit_after>#! /usr/bin/env python

# author: <NAME> <<EMAIL>>

from __future__ import division

from unit_timeside import unittest, TestRunner
from timeside.plugins.decoder.utils import get_uri, get_media_uri_info, path2uri
from timeside.core.tools.test_samples import samples
import os.path


class TestGetUri(unittest.TestCase):
    "Test get_uri function"

    def testFileName(self):
        "Retrieve the uri from a filename"
        self.source = samples["sweep.wav"]

        self.uri = path2uri(os.path.abspath(self.source))

    def testUri(self):
        "Retrieve the uri from an uri"
        self.uri = 'file://already/an/uri/file.wav'
        self.source = self.uri

    def tearDown(self):
        self.assertEqual(self.uri, get_uri(self.source))


class TestGetUriWrongUri(unittest.TestCase):

    def testMissingFile(self):
        "Missing file raise IOerror"
        self.source = os.path.join(os.path.dirname(__file__),
                                   "a_missing_file.wav")

    def testNotValidUri(self):
        "Not valid uri raise IOerror"
        self.source = "://not/a/valid/uri/parisson.com"

    def testNotSupportedUriProtocol(self):
        "Not supported uri protocol raise IOerror"
        self.source = "mailto://<EMAIL>"

    def tearDown(self):
        self.assertRaises(IOError, get_uri, self.source)


class TestGetMediaInfo(unittest.TestCase):
    "Test get_media_uri_info function on an uri"

    def setUp(self):
        self.test_exact_duration = True
        self.source_duration = 8
        self.test_exact_duration = True
        self.expected_channels = 2
        self.expected_samplerate = 44100
        self.expected_depth = 0  # ?

    @unittest.skip("HTTPS is not supported by GStreamer 0.10")
    def testUriFromHTTPS(self):
        "Test URI decoding from HTTPS"
        self.source = "https://raw.githubusercontent.com/yomguy/timeside-samples/master/samples/sweep.mp3"
        self.test_exact_duration = False
        self.expected_depth = 32

    def testWav(self):
        "Test wav decoding"
        self.source = samples["sweep.wav"]

    def testWavMono(self):
        "Test mono wav decoding"
        self.source = samples["sweep_mono.wav"]

        self.expected_channels = 1

    def testWav32k(self):
        "Test 32kHz wav decoding"
        self.source = samples["sweep_32000.wav"]
        self.expected_samplerate = 32000

    def testFlac(self):
        "Test flac decoding"
        self.source = samples["sweep.flac"]
        self.expected_depth = 24

    def testOgg(self):
        "Test ogg decoding"
        self.source = samples["sweep.ogg"]
        self.test_exact_duration = False
        self.expected_depth = 0  # ?

    def testMp3(self):
        "Test mp3 decoding"
        self.source = samples["sweep.mp3"]
        self.expected_depth = 32
        self.test_exact_duration = False

    def tearDown(self):
        uri = get_uri(self.source)
        uri_info = get_media_uri_info(uri)
        if self.test_exact_duration:
            self.assertEqual(self.source_duration, uri_info['duration'])
        else:
            self.assertAlmostEqual(self.source_duration,
                                   uri_info['duration'],
                                   places=1)
        self.assertEqual(self.expected_channels,
                         uri_info['streams'][0]['channels'])
        self.assertEqual(self.expected_samplerate,
                         uri_info['streams'][0]['samplerate'])
        self.assertEqual(self.expected_depth, uri_info['streams'][0]['depth'])


if __name__ == '__main__':
    unittest.main(testRunner=TestRunner())

{'fraction_non_alphanumeric': 0.103510226644555, 'fraction_numerical': 0.011470425649530127, 'mean_word_length': 2.456064947468959, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3367996', 'n_tokens_mistral': 2324, 'n_tokens_neox': 2170, 'n_words': 437}