[pitivi] tests: Remove duplicated logic for creating an xges
- From: Alexandru Băluț <alexbalut src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] tests: Remove duplicated logic for creating an xges
- Date: Sat, 30 Apr 2016 16:05:02 +0000 (UTC)
commit 91c81afcfe0f27a543e9fa33b187dba58d332896
Author: Alexandru Băluț <alexandru balut gmail com>
Date: Tue Apr 26 22:59:23 2016 +0200
tests: Remove duplicated logic for creating an xges
Differential Revision: https://phabricator.freedesktop.org/D968
tests/common.py | 36 ++++++++++++++++++------------------
tests/test_mainwindow.py | 6 +-----
tests/test_media_library.py | 8 ++------
tests/test_project.py | 24 ++----------------------
4 files changed, 23 insertions(+), 51 deletions(-)
---
diff --git a/tests/common.py b/tests/common.py
index 9ec03b0..48ad095 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -19,6 +19,7 @@
"""
A collection of objects to use for testing
"""
+import contextlib
import gc
import os
import tempfile
@@ -194,37 +195,36 @@ class TestCase(unittest.TestCase, Loggable):
expect_selected)
self.assertEqual(ges_clip.selected.selected, expect_selected)
- def createTempProject(self):
- """
- Created a temporary project
-
- Always generate projects with missing assets for now
-
- Returns:
- str: The path of the new project
- str: The URI of the new project
- """
- unused_fd, xges_path = tempfile.mkstemp()
- with open(xges_path, "w") as xges:
- xges.write("""
+ contextlib contextmanager
+def created_project_file(asset_uri="file:///icantpossiblyexist.png"):
+ """
+ Create a project file.
+
+ Yields:
+ str: The URI of the new project
+ """
+ unused_fd, xges_path = tempfile.mkstemp()
+ with open(xges_path, "w") as xges:
+ xges.write("""
<ges version='0.1'>
<project>
<ressources>
- <asset id='file:///icantpossiblyexist.png'
- extractable-type-name='GESUriClip' />
+ <asset id='%(asset_uri)s' extractable-type-name='GESUriClip' />
</ressources>
<timeline>
<track caps='video/x-raw' track-type='4' track-id='0' />
<layer priority='0'>
- <clip id='0' asset-id='file:///icantpossiblyexist.png'
+ <clip id='0' asset-id='%(asset_uri)s'
type-name='GESUriClip' layer-priority='0' track-types='4'
start='0' duration='2590000000' inpoint='0' rate='0' />
</layer>
</timeline>
</project>
-</ges>""")
+</ges>""" % {'asset_uri': asset_uri})
+
+ yield Gst.filename_to_uri(xges_path)
- return xges_path, Gst.filename_to_uri(xges_path)
+ os.remove(xges_path)
def get_sample_uri(sample):
diff --git a/tests/test_mainwindow.py b/tests/test_mainwindow.py
index 8f728cf..e2e8b6e 100644
--- a/tests/test_mainwindow.py
+++ b/tests/test_mainwindow.py
@@ -19,7 +19,6 @@
"""
Test for pitivi/mainwindow.py
"""
-import os
from unittest import mock
from gi.repository import GES
@@ -113,11 +112,8 @@ class TestMainWindow(common.TestCase):
app.project_manager.connect("missing-uri",
__pm_missing_uri_cb)
- xges_path, uri = self.createTempProject()
- try:
+ with common.created_project_file() as uri:
app.project_manager.loadProject(uri)
- finally:
- os.remove(xges_path)
mainloop.run()
diff --git a/tests/test_media_library.py b/tests/test_media_library.py
index 24d2be0..fcdd3c6 100644
--- a/tests/test_media_library.py
+++ b/tests/test_media_library.py
@@ -187,10 +187,6 @@ class TestMediaLibrary(common.TestCase):
self.assertEqual(asset.get_proxy(), proxy)
def testMissingUriDisplayed(self):
- xges_path, uri = self.createTempProject()
-
- try:
+ with common.created_project_file() as uri:
self._customSetUp(project_uri=uri)
- self.assertTrue(self.medialibrary._import_warning_infobar.props.visible)
- finally:
- os.remove(xges_path)
+ self.assertTrue(self.medialibrary._import_warning_infobar.props.visible)
diff --git a/tests/test_project.py b/tests/test_project.py
index 1a130bf..724f632 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -144,30 +144,10 @@ class TestProjectManager(TestCase):
self.manager.connect(
"missing-uri", missingUriCb, result)
- # Load a project with a missing asset.
- unused, xges_path = tempfile.mkstemp()
- with open(xges_path, "w") as xges:
- xges.write("""<ges version='0.1'>
- <project>
- <ressources>
- <asset id='file:///icantpossiblyexist.png' extractable-type-name='GESUriClip' />
- </ressources>
- <timeline>
- <track caps='video/x-raw' track-type='4' track-id='0' />
- <layer priority='0'>
- <clip id='0' asset-id='file:///icantpossiblyexist.png' type-name='GESUriClip' layer-priority='0'
track-types='4' start='0' duration='2590000000' inpoint='0' rate='0' />
- </layer>
- </timeline>
-</project>
-</ges>""")
- uri = "file://%s" % xges_path
- try:
+ with common.created_project_file() as uri:
self.assertTrue(self.manager.loadProject(uri))
-
mainloop.run()
- self.assertTrue(result[0], "missing not missing")
- finally:
- os.remove(xges_path)
+ self.assertTrue(result[0], "missing-uri has not been emitted")
def testCloseRunningProjectNoProject(self):
self.assertTrue(self.manager.closeRunningProject())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]