Commit 1a475da3 authored by Thibault Saunier's avatar Thibault Saunier

tests_: Cleanup tests and enhance common.py

Reviewed-by: Alexandru Băluț's avatarAlex Băluț <alexandru.balut@gmail.com>
Differential Revision: https://phabricator.freedesktop.org/D622
parent a940d195
#!/usr/bin/env python3
from . import runtests
runtests.setup()
if not runtests.setup():
raise ImportError("Could not setup testsuite")
......@@ -2,19 +2,49 @@
A collection of objects to use for testing
"""
from gi.repository import Gst
import os
import gc
import unittest
import tempfile
from gi.repository import Gst
from unittest import mock
from pitivi import check
from pitivi.application import Pitivi
from pitivi.utils.timeline import Selected
from pitivi.utils.loggable import Loggable
detect_leaks = os.environ.get("PITIVI_TEST_DETECT_LEAKS", "0") not in ("0", "")
os.environ["PITIVI_USER_CACHE_DIR"] = tempfile.mkdtemp("pitiviTestsuite")
def cleanPitiviMock(ptv):
ptv.settings = None
detect_leaks = os.environ.get("PITIVI_TEST_DETECT_LEAKS", "1") not in ("0", "")
def getPitiviMock(settings=None):
ptv = mock.MagicMock()
class TestCase(unittest.TestCase):
ptv.write_action = mock.MagicMock(spec=Pitivi.write_action)
check.check_requirements()
if not settings:
settings = mock.MagicMock()
ptv.settings = settings
return ptv
class TestCase(unittest.TestCase, Loggable):
_tracked_types = (Gst.MiniObject, Gst.Element, Gst.Pad, Gst.Caps)
def __init__(self, *args):
Loggable.__init__(self)
unittest.TestCase.__init__(self, *args)
def gctrack(self):
self.gccollect()
self._tracked = []
......@@ -77,10 +107,10 @@ class TestCase(unittest.TestCase):
self._result = result
unittest.TestCase.run(self, result)
@staticmethod
def getSampleUri(sample):
dir = os.path.dirname(os.path.abspath(__file__))
return "file://%s/samples/%s" % (dir, sample)
def getSampleUri(sample):
assets_dir = os.path.dirname(os.path.abspath(__file__))
return "file://%s/samples/%s" % (assets_dir, sample)
class SignalMonitor(object):
......
......@@ -46,6 +46,7 @@ def get_build_dir():
def setup():
res = True
# Make available to configure.py the top level dir.
pitivi_dir = get_pitivi_dir()
os.environ.setdefault('PITIVI_TOP_LEVEL_DIR', pitivi_dir)
......@@ -58,11 +59,13 @@ def setup():
# Make sure the modules are initialized correctly.
from pitivi import check
check.initialize_modules()
assert(check.check_requirements())
res = check.check_requirements()
from pitivi.utils import loggable as log
log.init('PITIVI_DEBUG')
return res
if __name__ == "__main__":
setup()
......
......@@ -22,21 +22,20 @@ import os
import tempfile
import time
from unittest import TestCase
from unittest import TestCase, mock
from gi.repository import GES
from gi.repository import GLib
from gi.repository import Gst
from tests import common
from pitivi.application import Pitivi
from pitivi.project import ProjectManager, Project
from pitivi.utils.misc import uri_is_reachable
from tests import common
def _createRealProject(name=None):
app = Pitivi()
app = common.getPitiviMock()
project_manager = ProjectManager(app)
project_manager.newBlankProject()
project = project_manager.current_project
......@@ -88,7 +87,8 @@ class ProjectManagerListener(object):
class TestProjectManager(TestCase):
def setUp(self):
self.manager = ProjectManager(None)
app = mock.MagicMock()
self.manager = ProjectManager(app)
self.listener = ProjectManagerListener(self.manager)
self.signals = self.listener.signals
......@@ -380,7 +380,7 @@ class TestProjectLoading(common.TestCase):
# Create a blank project and add an asset.
project = _createRealProject()
result = [False, False, False]
uris = [self.getSampleUri("tears_of_steel.webm")]
uris = [common.getSampleUri("tears_of_steel.webm")]
project.connect("loaded", loaded, self.mainloop, result, uris)
project.connect("done-importing", added, self.mainloop, result, uris)
......@@ -435,9 +435,9 @@ class TestProjectSettings(common.TestCase):
self.assertTrue(project._has_default_video_settings)
self.assertTrue(project._has_default_audio_settings)
uris = [self.getSampleUri("flat_colour1_640x480.png"),
self.getSampleUri("tears_of_steel.webm"),
self.getSampleUri("1sec_simpsons_trailer.mp4")]
uris = [common.getSampleUri("flat_colour1_640x480.png"),
common.getSampleUri("tears_of_steel.webm"),
common.getSampleUri("1sec_simpsons_trailer.mp4")]
project.connect("loaded", loaded, self.mainloop, uris)
project.connect("done-importing", added, self.mainloop)
......@@ -462,7 +462,8 @@ class TestProjectSettings(common.TestCase):
self.assertEqual(Gst.Fraction(1, 1), project.videopar)
def testLoad(self):
project = Project(uri="fake.xges", app=None)
ptv = common.getPitiviMock()
project = Project(uri="fake.xges", app=ptv)
self.assertFalse(project._has_default_video_settings)
self.assertFalse(project._has_default_audio_settings)
......
......@@ -46,7 +46,7 @@ class TestLayer(common.TestCase):
def testCheckMediaTypesWhenNoUI(self):
bLayer = GES.Layer()
png = self.getSampleUri("flat_colour1_640x480.png")
png = common.getSampleUri("flat_colour1_640x480.png")
video_clip = GES.UriClipAsset.request_sync(png).extract()
self.assertTrue(bLayer.add_clip(video_clip))
self.assertEqual(1, len(bLayer.get_clips()))
......
......@@ -18,7 +18,7 @@
# Boston, MA 02110-1301, USA.
from unittest import TestCase, mock
from tests.common import getPitiviMock
from gi.repository import Gdk
from pitivi.project import Project, ProjectManager
......@@ -34,10 +34,11 @@ THICK = ui.LAYER_HEIGHT
class TestLayers(TestCase):
def createTimeline(self, layers_heights):
project_manager = ProjectManager(app=None)
app = getPitiviMock()
project_manager = ProjectManager(app)
project_manager.newBlankProject()
project = project_manager.current_project
timeline = Timeline(container=None, app=None)
timeline = Timeline(container=mock.MagicMock(), app=app)
timeline.get_parent = mock.MagicMock()
timeline.setProject(project)
y = 0
......
......@@ -315,7 +315,7 @@ class TestTimelineUndo(TestCase):
self.assertEqual(20, clip1.get_priority())
def testUngroup(self):
uri = common.TestCase.getSampleUri("tears_of_steel.webm")
uri = common.getSampleUri("tears_of_steel.webm")
asset = GES.UriClipAsset.request_sync(uri)
clip1 = asset.extract()
self.layer.add_clip(clip1)
......
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