Exemple #1
0
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
"""This module provides tests for profile.py module."""

from collections import OrderedDict

import nose

from videomorph.converter.profile import ConversionProfile
from videomorph.converter.conversionlib import ConversionLib

profile = None
conv = ConversionLib()


def setup():
    """Function to setup the test."""
    global profile
    profile = ConversionProfile(prober=conv.prober_path)
    profile.update(new_quality='MP4 Fullscreen (4:3)')


def test_get_xml_profile_attr():
    """Test get_xml_profile_attr."""
    attr = profile.get_xml_profile_attr(target_quality='MP4 Fullscreen (4:3)',
                                        attr_name='preset_params')

    assert attr == '-f mp4 -r 29.97 -vcodec libx264 -s 640x480 -b:v 1000k ' \
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

"""This module provides tests for conversionlib.py module."""

import nose
from PyQt5.QtCore import QProcess

from videomorph.converter import CONV_LIB
from videomorph.converter import PROBER
from videomorph.converter import media
from videomorph.converter.conversionlib import ConversionLib
from videomorph.converter.profile import ConversionProfile

conv_lib = ConversionLib()

profile = ConversionProfile(prober=conv_lib.prober_path)
profile.update(new_quality='DVD Fullscreen (4:3)')

media_list = media.MediaList(profile)


def teardown():
    """Clean up when finished."""
    media_list.clear()
    gen = media_list.populate(('Dad.mpg',))
    next(gen)
    next(gen)
    media_list.get_file(0).delete_output('.', tagged_output=True)
Exemple #3
0
class TestConversionLib:
    conv_lib = ConversionLib()

    profile = ConversionProfile(prober=conv_lib.prober_path)
    profile.update(new_quality='FLV Fullscreen 320x240 (4:3)')

    media_list = media.MediaList(profile)

    @classmethod
    def setUpClass(cls):
        gen = cls.media_list.populate(('Dad.mpg', ))
        next(gen)
        next(gen)

    @classmethod
    def tearDownClass(cls):
        cls.media_list.get_file(0).delete_output('.', tagged_output=True)

    def get_conversion_cmd(self):
        """Return a conversion command."""
        cmd = self.media_list.get_file(position=0).build_conversion_cmd(
            output_dir='.',
            subtitle=False,
            tagged_output=True,
            target_quality='FLV Fullscreen 320x240 (4:3)')
        return cmd

    def test_get_library_path(self):
        """Test ConversionLib.library_path."""
        assert self.conv_lib.library_path in {
            '/usr/bin/ffmpeg', '/usr/local/bin/ffmpeg'
        }

    def test_prober_path(self):
        """Test the ConversionLib.prober_path."""
        assert self.conv_lib.prober_path in {
            '/usr/bin/ffprobe', '/usr/local/bin/ffprbe'
        }

    def test_start_converter(self):
        """Test ConversionLib.start_converter()."""
        self.conv_lib.start_converter(cmd=self.get_conversion_cmd())

        assert self.conv_lib.converter_state() == QProcess.Starting
        self.conv_lib.stop_converter()

    def test_read_converter_output(self):
        """Test ConversionLib.read_converter_output()."""
        self.conv_lib.start_converter(cmd=self.get_conversion_cmd())
        assert len(self.conv_lib.read_converter_output())
        self.conv_lib.stop_converter()

    def test_catch_library_error_true(self):
        """Test _OutputReader.catch_library_error() -> true."""
        self.conv_lib.reader.update_read('Some random output with '
                                         'Unknown encoder error')
        assert self.conv_lib.reader.catch_library_error() == 'Unknown encoder'

    def test_catch_library_error_false(self):
        """Test _OutputReader.catch_library_error() -> false."""
        self.conv_lib.reader.update_read('Some random output with ' 'no error')
        assert self.conv_lib.reader.catch_library_error() is None

    def test_stop_converter(self):
        """Test ConversionLib.stop_converter()."""
        self.conv_lib.stop_converter()
        assert not self.conv_lib.converter_is_running
Exemple #4
0
class TestMedia:
    """Class for testing media.py module."""

    conv_lib = ConversionLib()
    profile = ConversionProfile(prober=conv_lib.prober_path)
    profile.update(new_quality='DVD Fullscreen 352x480 (4:3)')

    def setUp(self):
        self.media_list = MediaList(profile=self.profile)
        self.gen = self.media_list.populate(('Dad.mpg',))
        next(self.gen)
        next(self.gen)

    def test_populate(self):
        """Test MediaList.populate()."""
        assert len(self.media_list) == 1 == self.media_list.length
        assert self.media_list[0].input_path == 'Dad.mpg'

    def test_delete_file(self):
        """Test MediaList.delete_file()."""
        # Be sure there is one element in the list
        assert len(self.media_list) == 1
        self.media_list.delete_file(position=0)
        assert len(self.media_list) == 0

    def test_get_file_object(self):
        """Test MediaList.get_file()."""
        assert isinstance(self.media_list.get_file(0), _MediaFile)

    def test_get_file_name(self):
        """Test MediaList.get_file_name()."""
        assert self.media_list.get_file_name(position=0) == 'Dad'

    def test_get_file_name_with_extension(self):
        """Test MediaList.get_file_name() with extension."""
        assert self.media_list.get_file_name(position=0,
                                             with_extension=True) == 'Dad.mpg'

    def test_get_file_path(self):
        """Test MediaList.get_file_path()."""
        assert self.media_list.get_file_path(position=0) == 'Dad.mpg'

    def test_get_file_status(self):
        """Test MediaList.get_file_status()."""
        assert self.media_list.get_file_status(position=0) == STATUS.todo

    def test_set_file_status(self):
        """Test MediaList.set_file_status()."""
        self.media_list.set_file_status(0, STATUS.done)
        assert self.media_list.get_file_status(position=0) == STATUS.done

    def test_get_file_info(self):
        """Test MediaList.get_file_info()."""
        assert self.media_list.get_file_info(0, 'filename') == 'Dad.mpg'

    def test_running_file_name(self):
        """Test MediaList.running_file_name()."""
        self.media_list.position = 0
        assert self.media_list.running_file_name() == 'Dad'

    def test_running_file_info(self):
        """Test MediaList.running_file_info()."""
        self.media_list.position = 0
        assert self.media_list.running_file_info('filename') == 'Dad.mpg'

    def test_running_file_status(self):
        """Test MediaList.running_file_status()."""
        assert self.media_list.running_file_status == STATUS.todo

    def test_set_running_file_status(self):
        """Test MediaList.running_file_status."""
        self.media_list.running_file_status = STATUS.done
        assert self.media_list.running_file_status == STATUS.done

    def test_running_file_output_name(self):
        """Test MediaList.running_file_output_name()."""
        assert self.media_list.running_file_output_name('.', False) == 'Dad.mpg'

    def test_is_exhausted_true(self):
        """Test MediaList.is_exhausted == True."""
        self.media_list.position = 0
        assert self.media_list.is_exhausted

    def test_is_exhausted_false(self):
        """Test MediaList.is_exhausted == False."""
        self.media_list.position = -1
        assert not self.media_list.is_exhausted

    def test_all_stopped_true(self):
        """Test MediaList.all_stopped == True."""
        self.media_list.set_file_status(0, 'Stopped')
        assert self.media_list.all_stopped

    def test_all_stopped_false(self):
        """Test MediaList.all_stopped == False."""
        self.media_list.set_file_status(0, 'Todo')
        assert not self.media_list.all_stopped

    def test_length(self):
        """Test MediaList.length."""
        assert self.media_list.length == 1

    def test_duration(self):
        """Test MediaList.duration()."""
        nose.tools.assert_almost_equal(self.media_list.duration, 120.72)

    @nose.tools.raises(StopIteration)
    def test_add_file_twice(self):
        """Testing adding the same file twice."""
        assert self.media_list.length == 1
        gen = self.media_list.populate(('Dad.mpg',))
        next(gen)

    def test_build_conversion_cmd(self):
        """Test _MediaFile.build_conversion_cmd."""
        assert self.media_list.get_file(0).build_conversion_cmd(
            output_dir='.',
            tagged_output=True,
            subtitle=True,
            target_quality='DVD Fullscreen 352x480 (4:3)') == ['-i', 'Dad.mpg',
                                                               '-f', 'dvd',
                                                               '-target',
                                                               'ntsc-dvd',
                                                               '-vcodec',
                                                               'mpeg2video', '-r',
                                                               '29.97', '-s',
                                                               '352x480',
                                                               '-aspect', '4:3',
                                                               '-b:v',
                                                               '4000k', '-mbd',
                                                               'rd',
                                                               '-cmp', '2',
                                                               '-subcmp',
                                                               '2', '-acodec',
                                                               'mp2',
                                                               '-b:a', '192k',
                                                               '-ar',
                                                               '48000', '-ac', '2',
                                                               '-threads', '3',
                                                               '-y',
                                                               './[DVDF]-Dad.mpg']

    def test_running_file_conversion_cmd(self):
        """Test MediaList.running_file_conversion_cmd()."""
        assert self.media_list.running_file_conversion_cmd(
            output_dir='.',
            tagged_output=True,
            subtitle=True,
            target_quality='DVD Fullscreen 352x480 (4:3)') == ['-i', 'Dad.mpg',
                                                               '-f', 'dvd',
                                                               '-target',
                                                               'ntsc-dvd',
                                                               '-vcodec',
                                                               'mpeg2video', '-r',
                                                               '29.97', '-s',
                                                               '352x480',
                                                               '-aspect', '4:3',
                                                               '-b:v',
                                                               '4000k', '-mbd',
                                                               'rd',
                                                               '-cmp', '2',
                                                               '-subcmp',
                                                               '2', '-acodec',
                                                               'mp2',
                                                               '-b:a', '192k',
                                                               '-ar',
                                                               '48000', '-ac', '2',
                                                               '-threads', '3',
                                                               '-y',
                                                               './[DVDF]-Dad.mpg']

    @nose.tools.raises(PermissionError)
    def test_running_file_conversion_cmd_permission_error(self):
        """Test MediaList.running_file_conversion_cmd() -> PermissionError."""
        self.media_list.running_file_conversion_cmd(
            output_dir='/',
            tagged_output=True,
            subtitle=True,
            target_quality='DVD Fullscreen 352x480 (4:3)')

    def test_clear(self):
        """Test MediaList.clear()."""
        self.media_list.clear()
        assert not self.media_list

    def test_populate_files_count(self):
        """Test MediaList.populate() yield amount of video files."""
        media_list = MediaList(profile=self.profile)
        gen = media_list.populate(('Dad.mpg',))
        assert next(gen) == 1

    def test_populate_first_file_name(self):
        """Test MediaList.populate() yield first video file name."""
        media_list = MediaList(profile=self.profile)
        gen = media_list.populate(('Dad.mpg',))
        next(gen)
        assert next(gen) == 'Dad.mpg'