Commit 4c96850f authored by yatinmaan's avatar yatinmaan

WIP: Add more tests

parent aab89dc1
Pipeline #80171 passed with stage
in 30 minutes and 58 seconds
......@@ -197,6 +197,65 @@ 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()
pm = self.app.proxy_manager
def check(asset_res, max_res, expected_res):
asset = mock.Mock()
asset.get_info.return_value = asset
asset.get_video_streams.return_value = [asset]
asset.get_width = mock.Mock(return_value=asset_res[0])
asset.get_height = mock.Mock(return_value=asset_res[1])
result = pm._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((100, 100), (200, 200), (100, 100))
def test_getTargetUri(self):
self._customSetUp()
pm = self.app.proxy_manager
def check(proxy_uri, expected_uri):
asset = mock.Mock(spec=GES.Asset)
asset.props.id = proxy_uri
result = pm.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()
pm = 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("pitivi.utils.proxy.ProxyManager._scale_asset_resolution") as mock_s_res:
mock_s_res.return_value = scaled_res
with mock.patch("pitivi.utils.proxy.Gio.File") as mock_gio:
mock_gio.new_for_uri.return_value = mock_gio
mock_gio.query_info.return_value = mock_gio
mock_gio.get_size.return_value = size
result = pm.getProxyUri(asset, scaled=scaled)
self.assertEqual(result, expected_uri)
check("file:///home/file.name.mp4", "file:///home/file.name.mp4.1927006.proxy.mkv", size=1927006)
check("file:///home/file.name.mp4", "file:///home/file.name.mp4.1927006.1280x720.scaledproxy.mkv", scaled=True, size=1927006)
def stop_using_proxies(self, delete_proxies=False):
sample_name = "30fps_numeroted_frames_red.mkv"
self.check_import([sample_name])
......@@ -391,6 +450,9 @@ class TestMediaLibrary(BaseTestMediaLibrary):
with mock.patch.object(self.app.proxy_manager,
"isAssetFormatWellSupported",
return_value=False):
# Recalculate AssetThumbnail.state, now with no WHITELIST_FORMATS
self.medialibrary.storemodel[0][medialibrary.COL_THUMB_DECORATOR].decorate()
# Create scaled proxy
proxy = self.check_add_proxy(asset, scaled=True, w=80, h=34)
proxy_uri = self.app.proxy_manager.getProxyUri(asset, scaled=True)
......
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