ges: Add test for the newly added DiscovererManager object

Making pep8 happy on the way

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3911>
This commit is contained in:
Thibault Saunier 2023-02-08 16:50:15 -03:00
parent 98e5c5e862
commit e8e5508d1d

View file

@ -27,6 +27,7 @@ gi.require_version("Gst", "1.0")
gi.require_version("GES", "1.0")
from gi.repository import Gst # noqa
from gi.repository import GstPbutils # noqa
from gi.repository import GLib # noqa
from gi.repository import GES # noqa
import unittest # noqa
@ -74,6 +75,7 @@ class TestTimeline(GESSimpleTimelineTest):
with common.created_video_asset(uri, 6, framerate="2/1") as uri:
mainloop = common.create_main_loop()
def asset_loaded_cb(_, res, mainloop):
asset2 = GES.Asset.request_finish(res)
self.assertEqual(asset2.props.duration, 3 * Gst.SECOND)
@ -102,7 +104,6 @@ class TestTimeline(GESSimpleTimelineTest):
with open(xges_path, "w") as xges_file:
xges_file.write(xges)
def loaded_cb(project, timeline):
asset = project.list_assets(GES.Extractable)[0]
self.assertEqual(asset.get_meta("foo"), "bar")
@ -112,3 +113,40 @@ class TestTimeline(GESSimpleTimelineTest):
loaded_project.connect("loaded", loaded_cb)
timeline = loaded_project.extract()
mainloop.run()
def test_asset_load_serialized_info(self):
mainloop = GLib.MainLoop()
serialized_infos = {}
n_calls = 0
n_cache_hits = 0
def load_serialized_info_cb(_manager, uri):
nonlocal n_calls, n_cache_hits, serialized_infos
n_calls += 1
res = serialized_infos.get(uri)
if res:
n_cache_hits += 1
return res
GES.DiscovererManager.get_default().connect("load-serialized-info",
load_serialized_info_cb)
self.assertEqual(n_calls, 0)
asset = GES.UriClipAsset.request_sync(Gst.filename_to_uri(os.path.join(__file__, "../../assets/audio_video.ogg")))
self.assertEqual(n_calls, 1)
self.assertEqual(n_cache_hits, 0)
serialized_infos[asset.get_id()] = asset.get_info()
# Clear the GES internal asset cache
GES.deinit()
GES.init()
# Connect to the new manager, previous one was destroyed on deinit
GES.DiscovererManager.get_default().connect("load-serialized-info",
load_serialized_info_cb)
asset = GES.UriClipAsset.request_sync(Gst.filename_to_uri(os.path.join(__file__, "../../assets/audio_video.ogg")))
self.assertEqual(n_calls, 2)
self.assertEqual(n_cache_hits, 1)