Skip to content

Commit

Permalink
Made TestSources video specific
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Aug 11, 2013
1 parent f3b8765 commit cb63c63
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
31 changes: 19 additions & 12 deletions python-api/gstswitch/helpers.py
Expand Up @@ -16,7 +16,7 @@ class TestSources(object):

def __init__(self, video_port):
super(TestSources, self).__init__()
self.running_tests = []
self._running_tests_video = []
self.video_port = video_port

@property
Expand All @@ -40,7 +40,14 @@ def video_port(self, video_port):
"not, '{0}'".format(type(video_port)))
except ValueError:
raise TypeError("Port must be a valid number")


@property
def running_tests_video(self):
return self._running_tests_video

@running_tests_video.setter
def running_tests_video(self, tests):
self._running_tests_video = tests

def new_test_video(self,
width=300,
Expand All @@ -65,25 +72,25 @@ def new_test_video(self,
timeoverlay,
clockoverlay)
testsrc.run()
self.running_tests.append(testsrc)
self._running_tests_video.append(testsrc)

def get_test_video(self):
"""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:
for test in self._running_tests_video:
print i, "pattern:", test.pattern
i += 1
return self.running_tests
return self._running_tests_video

def terminate_index(self, index):
def terminate_index_video(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
"""
try:
testsrc = self.running_tests[int(index)]
testsrc = self._running_tests_video[int(index)]
except IndexError:
raise InvalidIndexError("No pattern with index:{0}, use get_test_video() to determine index"
.format(index))
Expand All @@ -94,14 +101,14 @@ def terminate_index(self, index):

print 'End source with pattern %s' % (str(testsrc.pattern))
testsrc.end()
self.running_tests.remove(self.running_tests[index])
self._running_tests_video.remove(self._running_tests_video[index])

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


class PreviewSinks(object):
Expand Down
4 changes: 4 additions & 0 deletions python-api/test.py
Expand Up @@ -4,6 +4,10 @@
# THIS FILE IS ONLY FOR MY PERSONAL TESTING PURPOSES.
# IT IS NOT MADE TO AND SHOULD NOT BE TESTING THE ENTIRE API

import sys
import os
sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../../")))

from gstswitch.server import Server
from gstswitch.helpers import *
from gstswitch.controller import Controller
Expand Down
2 changes: 1 addition & 1 deletion python-api/tests/unittests/test_controller.py
Expand Up @@ -5,7 +5,7 @@
from gstswitch.controller import Controller
from gstswitch.exception import ConnectionReturnError
import pytest
from mock import Mock, patch
from mock import Mock
from gstswitch.connection import Connection
from gi.repository import GLib

Expand Down
22 changes: 11 additions & 11 deletions python-api/tests/unittests/test_helpers.py
Expand Up @@ -56,8 +56,8 @@ def test_new_test_video(self, monkeypatch):
test = TestSources(video_port=3000)
monkeypatch.setattr(gstswitch.testsource, 'VideoSrc', self.MockVideoSrc)
test.new_test_video()
assert test.running_tests[0] is not None
assert len(test.running_tests) != 0
assert test.running_tests_video[0] is not None
assert len(test.running_tests_video) != 0

class MockTest(object):

Expand All @@ -70,32 +70,32 @@ def end(self):
def test_get_test_video(self):

test = TestSources(video_port=3000)
test.running_tests = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.get_test_video()

def test_terminate_index_error(self):
testsrc = TestSources(video_port=3000)
testsrc.running_tests = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
testsrc.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
tests = [-100, 20, 1e10, "hi", [1, 2, 3]]
for test in tests:
with pytest.raises(InvalidIndexError):
testsrc.terminate_index(test)
testsrc.terminate_index_video(test)

def test_terminate_index_normal(self):
test = TestSources(video_port=3000)
test.running_tests = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.terminate_index(0)
test.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.terminate_index_video(0)


def test_terminate1(self):
test = TestSources(video_port=3000)
test.running_tests = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.terminate()
test.running_tests_video = [self.MockTest(1), self.MockTest(2), self.MockTest(3), self.MockTest(19)]
test.terminate_video()

def test_terminate2(self):
test = TestSources(video_port=3000)
test.running_tests = []
test.terminate()
test.running_tests_video = []
test.terminate_video()


class TestPreviewSinksPreviewPort(object):
Expand Down

0 comments on commit cb63c63

Please sign in to comment.