Commit 4938c56c authored by yatinmaan's avatar yatinmaan

WIP: Move tests from test_media_library to proxy

parent 41eb4bab
Pipeline #81641 passed with stage
in 15 minutes and 32 seconds
......@@ -197,66 +197,6 @@ class TestMediaLibrary(BaseTestMediaLibrary):
mock_filter.uri = "file:///home/user/Videos/video.mp4.2360382.300x300.scaledproxy.mkv"
self.assertFalse(mlib._filter_unsupported(mock_filter))
def test_scale_asset_resolution(self):
self._customSetUp()
manager = self.app.proxy_manager
def check(asset_res, max_res, expected_res):
stream = mock.Mock()
stream.get_width.return_value = asset_res[0]
stream.get_height.return_value = asset_res[1]
asset = mock.Mock()
asset.get_info().get_video_streams.return_value = [stream]
result = manager._scale_asset_resolution(asset, max_res[0], max_res[1])
self.assertEqual(result, expected_res)
# Test different aspect ratios
check((1920, 1080), (100, 100), (96, 54))
check((1080, 1920), (100, 100), (54, 96))
check((1000, 1000), (100, 100), (100, 100))
# Test unscalable resolutions
check((1000, 10), (100, 100), (1000, 10))
check((10, 1000), (100, 100), (10, 1000))
check((100, 100), (200, 200), (100, 100))
def test_getTargetUri(self):
self._customSetUp()
manager = self.app.proxy_manager
def check(proxy_uri, expected_uri):
asset = mock.Mock(spec=GES.Asset)
asset.props.id = proxy_uri
result = manager.getTargetUri(asset)
self.assertEqual(result, expected_uri)
check("file:///home/filename.ext.size.scaled_res.scaledproxy.mkv", "file:///home/filename.ext")
check("file:///home/filename.ext.size.proxy.mkv", "file:///home/filename.ext")
check("file:///home/file.name.mp4.1927006.1280x720.scaledproxy.mkv", "file:///home/file.name.mp4")
check("file:///home/file.name.mp4.1927006.proxy.mkv", "file:///home/file.name.mp4")
def test_getProxyUri(self):
self._customSetUp()
manager = self.app.proxy_manager
def check(asset_uri, expected_uri, size=100, scaled=False, scaled_res=(1280, 720)):
asset = mock.Mock()
asset.get_id.return_value = asset_uri
with mock.patch.object(manager, "_scale_asset_resolution") as s_res:
s_res.return_value = scaled_res
with mock.patch("pitivi.utils.proxy.Gio.File") as gio:
gio.new_for_uri.return_value = gio
gio.query_info().get_size.return_value = size
result = manager.getProxyUri(asset, scaled=scaled)
self.assertEqual(result, expected_uri)
check("file:///home/file.name.mp4", "file:///home/file.name.mp4.100.proxy.mkv")
check("file:///home/file.name.mp4", "file:///home/file.name.mp4.100.1280x720.scaledproxy.mkv", scaled=True)
def stop_using_proxies(self, delete_proxies=False):
sample_name = "30fps_numeroted_frames_red.mkv"
self.check_import([sample_name])
......
# -*- coding: utf-8 -*-
# Pitivi video editor
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
from unittest import mock
from gi.repository import GES
from tests import common
class TestScaleAssetResolution(common.TestCase):
"""Tests _scale_asset_resolution method"""
def _check(self, asset_res, max_res, expected_res):
app = common.create_pitivi_mock()
manager = app.proxy_manager
stream = mock.Mock()
stream.get_width.return_value = asset_res[0]
stream.get_height.return_value = asset_res[1]
asset = mock.Mock()
asset.get_info().get_video_streams.return_value = [stream]
result = manager._scale_asset_resolution(asset, max_res[0], max_res[1])
self.assertEqual(result, expected_res)
def test_aspect_ratios(self):
self._check((1920, 1080), (100, 100), (96, 54))
self._check((1080, 1920), (100, 100), (54, 96))
self._check((1000, 1000), (100, 100), (100, 100))
def test_unscalable_resolutions(self):
self._check((1000, 10), (100, 100), (1000, 10))
self._check((10, 1000), (100, 100), (10, 1000))
self._check((100, 100), (200, 200), (100, 100))
class TestGetTargetUri(common.TestCase):
"""Tests getTargetUri method"""
def _check(self, proxy_uri, expected_uri):
app = common.create_pitivi_mock()
manager = app.proxy_manager
asset = mock.Mock(spec=GES.Asset)
asset.props.id = proxy_uri
result = manager.getTargetUri(asset)
self.assertEqual(result, expected_uri)
def test_target_uri(self):
self._check("file:///home/filename.ext.size.scaled_res.scaledproxy.mkv", "file:///home/filename.ext")
self._check("file:///home/filename.ext.size.proxy.mkv", "file:///home/filename.ext")
self._check("file:///home/file.name.mp4.1927006.1280x720.scaledproxy.mkv", "file:///home/file.name.mp4")
self._check("file:///home/file.name.mp4.1927006.proxy.mkv", "file:///home/file.name.mp4")
class TestGetProxyUri(common.TestCase):
"""Tests getProxyUri method"""
def _check(self, asset_uri, expected_uri, size=10, scaled=False, scaled_res=(1280, 720)):
app = common.create_pitivi_mock()
manager = app.proxy_manager
asset = mock.Mock()
asset.get_id.return_value = asset_uri
with mock.patch.object(manager, "_scale_asset_resolution") as s_res:
s_res.return_value = scaled_res
with mock.patch("pitivi.utils.proxy.Gio.File") as gio:
gio.new_for_uri.return_value = gio
gio.query_info().get_size.return_value = size
result = manager.getProxyUri(asset, scaled=scaled)
self.assertEqual(result, expected_uri)
def test_proxy_uri(self):
self._check("file:///home/file.name.mp4", "file:///home/file.name.mp4.10.proxy.mkv")
self._check("file:///home/file.name.mp4", "file:///home/file.name.mp4.10.1280x720.scaledproxy.mkv", scaled=True)
  • yatinmaan
    @yatinmaan started a thread
    • @aleb Updated.

      PS: I had some linting errors in test_proxy.py that I thought weren't worth fixing, tell me if I need to do something about them.

    Please register or sign in to reply
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment