コード例 #1
0
ファイル: test_loading_tree.py プロジェクト: hile/oodi
    def test_loading_tree_with_configuration(self):
        from oodi.configuration import Configuration
        from oodi.library.tree import Tree

        tree = Tree(TEST_TREE_PATH, Configuration())
        self.assertIsInstance(tree.configuration, Configuration)

        tree = Tree(TEST_TREE_PATH, configuration=Configuration())
        self.assertIsInstance(tree.configuration, Configuration)
コード例 #2
0
ファイル: test_loading_libraries.py プロジェクト: hile/oodi
    def test_loading_libraries_with_configuration(self):
        from oodi.configuration import Configuration
        from oodi.library.base import Libraries

        libraries = Libraries(Configuration())
        self.assertIsInstance(libraries.configuration, Configuration)

        libraries = Libraries(configuration=Configuration())
        self.assertIsInstance(libraries.configuration, Configuration)
コード例 #3
0
 def test_configuration_invalid_file_path(self):
     """
     Test loading invalid path as yaml configuration
     """
     from oodi.configuration import Configuration, ConfigurationError
     with self.assertRaises(ConfigurationError):
         Configuration(os.path.join('/{}'.format(uuid4())))
コード例 #4
0
 def test_configuration_load_directory_path(self):
     """
     Test loading directory path as yaml configuration
     """
     from oodi.configuration import Configuration, ConfigurationError
     with self.assertRaises(ConfigurationError):
         Configuration(path='/')
コード例 #5
0
 def test_configuration_load_empty_configuration(self):
     """
     Test loading empty yaml configuration
     """
     from oodi.configuration import Configuration
     config = Configuration(os.path.join(TEST_FILES_PATH, 'empty.yaml'))
     self.check_configuration_objects(config)
コード例 #6
0
 def test_configuration_no_path(self):
     """
     Test configuration can be loaded by passing None as path
     """
     from oodi.configuration import Configuration
     config = Configuration(path=None)
     self.check_configuration_objects(config)
コード例 #7
0
 def test_configuration_default_configuration(self):
     """
     Test loading configuration with no options
     """
     from oodi.configuration import Configuration
     config = Configuration()
     self.check_configuration_objects(config)
コード例 #8
0
    def test_configuration_load_invalid_configuration(self):
        """
        Test loading invalid yaml configuration.

        The test file is actually .ini file
        """
        from oodi.configuration import Configuration, ConfigurationError
        with self.assertRaises(ConfigurationError):
            Configuration(os.path.join(TEST_FILES_PATH, 'invalid.yaml'))
コード例 #9
0
    def test_codec_decoders_explicit_output_file(self):
        """
        Call all decoders by specifying a named output file path
        """
        from oodi.configuration import Configuration
        from oodi.library.track import Track

        configuration = Configuration()
        output_file = configuration.get_temporary_file_path('test.wav')
        for name in TEST_FILES:
            if os.path.isfile(output_file):
                os.unlink(output_file)
            testfile = os.path.join(TEST_FILES_PATH, name)
            track = Track(testfile, configuration)
            track.decode(output_file)
            self.assertTrue(
                os.path.isfile(output_file),
                'Error decoding {}: missing output file {}'.format(
                    testfile, output_file))
コード例 #10
0
    def test_configuration_load_custom_codec_configuration(self):
        """
        Test loading custom settings to codecs configuration

        Overrides some attributes, check here these are loaded to configuration
        """
        from oodi.configuration import Configuration

        config = Configuration(os.path.join(TEST_FILES_PATH, 'codecs.yaml'))
        self.check_configuration_objects(config)

        self.assertEqual(config.codecs.get('aac').get('bitrate'), 123456)
        self.assertEqual(config.codecs.get('encoders').get('wav'), [])
コード例 #11
0
    def test_codec_decoders_tempfile_output(self):
        """
        Call all decoders without explicit path, decoding to temporary file
        """
        from oodi.configuration import Configuration
        from oodi.library.track import Track

        configuration = Configuration()
        for name in TEST_FILES:
            testfile = os.path.join(TEST_FILES_PATH, name)
            track = Track(testfile, configuration=configuration)
            output_file = track.decode()
            self.assertTrue(
                os.path.isfile(output_file),
                'Error decoding {}: missing output file {}'.format(
                    testfile, output_file))
            if track.supports_tags:
                self.assertIsInstance(track.tags.items(), dict)
コード例 #12
0
ファイル: test_loading_codecs.py プロジェクト: hile/oodi
    def test_loaders_codecs(self):
        """
        Test loading codec objects (oodi.codecs.Codecs)
        """
        from oodi.configuration import Configuration
        from oodi.codecs.base import Codecs, CodecError, GenericAudioFile, BaseDecoder, BaseEncoder, BaseTagParser

        codecs = Codecs(Configuration())

        # Test accessing common codec objects by name
        for name in TEST_CODEC_NAMES:
            codec = getattr(codecs, name)
            self.assertIsInstance(codec, GenericAudioFile)

            self.assertIsInstance(codec.encoder, BaseEncoder)
            self.assertEqual(
                codec.format, codec.encoder.format,
                'Codec encoder format mismatch: {}'.format(
                    codec.format,
                    codec.encoder.format,
                ))

            self.assertIsInstance(codec.decoder, BaseDecoder)
            self.assertEqual(
                codec.format, codec.decoder.format,
                'Codec decoder format mismatch: {}'.format(
                    codec.format,
                    codec.decoder.format,
                ))

            if name in TEST_NO_TAGPARSER:
                with self.assertRaises(CodecError):
                    codec.tagparser
            else:
                self.assertIsInstance(codec.tagparser, BaseTagParser)
                self.assertEqual(
                    codec.format, codec.tagparser.format,
                    'Codec tag parser format mismatch: {}'.format(
                        codec.format,
                        codec.tagparser.format,
                    ))
コード例 #13
0
 def __process_args__(self, args):
     try:
         self.configuration = Configuration(args.config)
     except ConfigurationError as e:
         self.exit(1, e)
     return super().__process_args__(args)
コード例 #14
0
ファイル: test_codec_encoders.py プロジェクト: hile/oodi
 def setUp(self):
     from oodi.configuration import Configuration
     self.configuration = Configuration()
     self.input_file = os.path.join(os.path.dirname(__file__), 'files/test.wav')
コード例 #15
0
ファイル: test_codec_encoders.py プロジェクト: hile/oodi
class CodecEncoders(unittest.TestCase):
    """
    Tests codec encoders
    """
    def setUp(self):
        from oodi.configuration import Configuration
        self.configuration = Configuration()
        self.input_file = os.path.join(os.path.dirname(__file__), 'files/test.wav')

    def test_encoder_aac(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.exceptions import LibraryError
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.m4a')

        # Raises LibraryError because .m4a matches multiple codecs
        with self.assertRaises(LibraryError):
            track = Track(filename, configuration=self.configuration)
            output_file = track.encode(self.input_file, remove_input_file=False)

        # Specifying explicit format allows encoding
        track = Track(filename, configuration=self.configuration, format='aac')
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'aac')

    def test_encoder_aif(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.aif')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'aif')

    def test_encoder_alac(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.exceptions import LibraryError
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.m4a')

        # Raises LibraryError because .alac matches multiple codecs
        with self.assertRaises(LibraryError):
            track = Track(filename, self.configuration)
            output_file = track.encode(self.input_file, remove_input_file=False)

        # Specifying explicit format allows encoding
        track = Track(filename, configuration=self.configuration, format='alac')
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'alac')

    def test_encoder_caf(self):
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.caf')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))

    def test_encoder_flac(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.flac')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'flac')

    def test_encoder_mp3(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.mp3')

        track = Track(filename, self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'mp3')

    def test_encoder_opus(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.opus')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'opus')

    def test_encoder_vorbis(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.ogg')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'vorbis')

    def test_encoder_wavpack(self):
        from oodi.codecs.utils import detect_file_codec
        from oodi.library.track import Track

        filename = self.configuration.get_temporary_file_path('test.wv')

        track = Track(filename, configuration=self.configuration)
        output_file = track.encode(self.input_file, remove_input_file=False)
        self.assertEqual(output_file, track.path)
        self.assertTrue(os.path.isfile(output_file))
        self.assertEqual(detect_file_codec(filename), 'wavpack')