diff options
Diffstat (limited to 'tests/check')
-rw-r--r-- | tests/check/python/common.py | 69 | ||||
-rw-r--r-- | tests/check/python/test_group.py | 32 | ||||
-rw-r--r-- | tests/check/python/test_timeline.py | 62 |
3 files changed, 163 insertions, 0 deletions
diff --git a/tests/check/python/common.py b/tests/check/python/common.py new file mode 100644 index 0000000000..e0e9d70205 --- /dev/null +++ b/tests/check/python/common.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016 Alexandru Băluț <alexandru.balut@gmail.com> +# +# 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 gi.repository import GES +from gi.repository import GLib +import tempfile + + +def create_main_loop(): + """Creates a MainLoop with a timeout.""" + mainloop = GLib.MainLoop() + timed_out = False + + def quit_cb(unused): + nonlocal timed_out + timed_out = True + mainloop.quit() + + def run(timeout_seconds=5): + source = GLib.timeout_source_new_seconds(timeout_seconds) + source.set_callback(quit_cb) + source.attach() + GLib.MainLoop.run(mainloop) + source.destroy() + if timed_out: + raise Exception("Timed out after %s seconds" % timeout_seconds) + + mainloop.run = run + return mainloop + +def create_project(with_group=False, saved=False): + """Creates a project with two clips in a group.""" + project = GES.Project() + timeline = project.extract() + layer = timeline.append_layer() + + if with_group: + clip1 = GES.TitleClip() + clip1.set_start(0) + clip1.set_duration(10) + layer.add_clip(clip1) + clip2 = GES.TitleClip() + clip2.set_start(100) + clip2.set_duration(10) + layer.add_clip(clip2) + group = GES.Container.group([clip1, clip2]) + + if saved: + uri = "file://%s" % tempfile.NamedTemporaryFile(suffix=".xges").name + project.save(timeline, uri, None, overwrite=True) + + return timeline + diff --git a/tests/check/python/test_group.py b/tests/check/python/test_group.py index ad27444dfb..87c097c717 100644 --- a/tests/check/python/test_group.py +++ b/tests/check/python/test_group.py @@ -27,6 +27,8 @@ from gi.repository import GES # noqa import unittest # noqa from unittest import mock +import common + Gst.init(None) GES.init() @@ -167,3 +169,33 @@ class TestGroup(unittest.TestCase): child_removed_cb.reset_mock() group.ungroup(recursive=False) child_removed_cb.assert_called_once_with(group, clip1) + + def test_loaded_project_has_groups(self): + mainloop = common.create_main_loop() + timeline = common.create_project(with_group=True, saved=True) + layer, = timeline.get_layers() + group, = timeline.get_groups() + self.assertEqual(len(layer.get_clips()), 2) + for clip in layer.get_clips(): + self.assertEqual(clip.get_parent(), group) + + # Reload the project, check the group. + project = GES.Project.new(uri=timeline.get_asset().props.uri) + + loaded_called = False + def loaded(unused_project, unused_timeline): + nonlocal loaded_called + loaded_called = True + mainloop.quit() + project.connect("loaded", loaded) + + timeline = project.extract() + + mainloop.run() + self.assertTrue(loaded_called) + + layer, = timeline.get_layers() + group, = timeline.get_groups() + self.assertEqual(len(layer.get_clips()), 2) + for clip in layer.get_clips(): + self.assertEqual(clip.get_parent(), group) diff --git a/tests/check/python/test_timeline.py b/tests/check/python/test_timeline.py new file mode 100644 index 0000000000..9aad8d608b --- /dev/null +++ b/tests/check/python/test_timeline.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# +# Copyright (c) 2016 Alexandru Băluț <alexandru.balut@gmail.com> +# +# 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. + +import gi + +gi.require_version("Gst", "1.0") +gi.require_version("GES", "1.0") + +from gi.repository import Gst # noqa +from gi.repository import GES # noqa +import unittest # noqa +from unittest import mock + +import common + +Gst.init(None) +GES.init() + + +class TestTimeline(unittest.TestCase): + + def test_signals_not_emitted_when_loading(self): + mainloop = common.create_main_loop() + timeline = common.create_project(with_group=True, saved=True) + + # Reload the project, check the group. + project = GES.Project.new(uri=timeline.get_asset().props.uri) + + loaded_called = False + def loaded(unused_project, unused_timeline): + nonlocal loaded_called + loaded_called = True + mainloop.quit() + project.connect("loaded", loaded) + + timeline = project.extract() + + signals = ["layer-added", "group-added", "track-added"] + called = [] + handle = mock.Mock() + for signal in signals: + timeline.connect(signal, handle) + + mainloop.run() + self.assertTrue(loaded_called) + handle.assert_not_called() |