From cb63c635c2c21c976bd164d427ddd35f0d2fd14b Mon Sep 17 00:00:00 2001 From: hyades Date: Sun, 11 Aug 2013 12:10:37 +0530 Subject: [PATCH] Made TestSources video specific --- python-api/gstswitch/helpers.py | 31 ++++++++++++------- python-api/test.py | 4 +++ python-api/tests/unittests/test_controller.py | 2 +- python-api/tests/unittests/test_helpers.py | 22 ++++++------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/python-api/gstswitch/helpers.py b/python-api/gstswitch/helpers.py index 38f096a..1f48517 100644 --- a/python-api/gstswitch/helpers.py +++ b/python-api/gstswitch/helpers.py @@ -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 @@ -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, @@ -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)) @@ -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): diff --git a/python-api/test.py b/python-api/test.py index 491ab76..e98621c 100755 --- a/python-api/test.py +++ b/python-api/test.py @@ -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 diff --git a/python-api/tests/unittests/test_controller.py b/python-api/tests/unittests/test_controller.py index 2eb390b..6ff0905 100644 --- a/python-api/tests/unittests/test_controller.py +++ b/python-api/tests/unittests/test_controller.py @@ -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 diff --git a/python-api/tests/unittests/test_helpers.py b/python-api/tests/unittests/test_helpers.py index 52ce0f4..57a09ec 100644 --- a/python-api/tests/unittests/test_helpers.py +++ b/python-api/tests/unittests/test_helpers.py @@ -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): @@ -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):