Skip to content

Commit

Permalink
Coverage and unittests - test_controller.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 26, 2013
1 parent c62fd9b commit 28a2e3b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
37 changes: 27 additions & 10 deletions python-api/gstswitch/helpers.py
Expand Up @@ -5,7 +5,13 @@

class TestSources(object):
"""A Controller of test sources feeding into the
gst-switch-srv"""
gst-switch-srv
:param width: The width of the output video
:param height: The height of the output video
:param pattern: The videotestsrc pattern of the output video
:param timeoverlay: True to enable a running time over video
:param clockoverlay: True to enable current clock time over video
"""

def __init__(self, video_port):
super(TestSources, self).__init__()
Expand All @@ -18,9 +24,15 @@ def new_test_video(self,
pattern=None,
timeoverlay=False,
clockoverlay=False):
"""Start a new test source
"""Start a new test video
:param port: The port of where the TCP stream will be sent
Should be same as video port of gst-switch-src
:param width: The width of the output video
:param height: The height of the output video
:param pattern: The videotestsrc pattern of the output video
:param timeoverlay: True to enable a running time over video
:param clockoverlay: True to enable current clock time over video
"""
print 'Adding new test video source'
testsrc = VideoSrc(
self.video_port,
width,
Expand All @@ -33,7 +45,8 @@ def new_test_video(self,
self.running_tests.append(testsrc)

def get_test_video(self):
"""Returns a list of processes acting as test inputs
"""Returns a list of processes acting as video test sources running
:returns: A list containing all video test sources running
"""
i = 0
for test in self.running_tests:
Expand All @@ -42,23 +55,26 @@ def get_test_video(self):
return self.running_tests

def terminate_index(self, index):
"""
"""Terminate video test source specified by index
:param index: The index of the video source to terminate
Use get_test_video for finding the index
"""
testsrc = self.running_tests[index]
print 'End source with pattern %s' % (str(testsrc.pattern))
testsrc.end()
self.running_tests.remove(self.running_tests[index])

def terminate(self):
"""
"""Terminate all test video sources
"""
print 'TESTS:', self.running_tests
for test in range(len(self.running_tests)):
for i in range(len(self.running_tests)):
self.terminate_index(0)


class PreviewSinks(object):
"""docstring for PreviewSinks
"""A Controller for preview sinks to preview ports of gst-switch-srv
:param preview_port: The preview port to get the preview
"""
# TODO set preview port from dbus call

Expand All @@ -77,5 +93,6 @@ def terminate(self):
try:
self.preview.end()
print 'end preview'
except:
pass
# TODO: Find which error may occur
except OSError:
raise
12 changes: 11 additions & 1 deletion python-api/gstswitch/test_controller.py
Expand Up @@ -2,6 +2,7 @@
from exception import *
import pytest
from mock import Mock, patch
from connection import Connection


class TestAddress(object):
Expand Down Expand Up @@ -74,4 +75,13 @@ def test_interface_dot(self):
def test_interface_normal(self):
default_interface = "info.duzy.gst.switch.SwitchControllerInterface"
conn = Controller(default_interface=default_interface)
assert default_interface == conn.default_interface
assert default_interface == conn.default_interface


class TestEstablishConnection(object):

def test_normal(self, monkeypatch):
monkeypatch.setattr(Connection, 'connect_dbus', Mock())
controller = Controller()
controller.establish_connection()
assert controller.connection is not None

0 comments on commit 28a2e3b

Please sign in to comment.