From 471a59c0d1f1681a01a718676a95b0478e7c4ba5 Mon Sep 17 00:00:00 2001 From: Aayush Ahuja Date: Wed, 7 Jan 2015 22:00:39 +1300 Subject: [PATCH] Better naming of composite modes --- python-api/gstswitch/controller.py | 19 ++++++++++++++----- python-api/tests/integrationtests/compare.py | 8 ++++---- .../tests/integrationtests/test_controller.py | 17 +++++++++++------ .../tests/unittests/test_controller_unit.py | 4 ++-- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/python-api/gstswitch/controller.py b/python-api/gstswitch/controller.py index 8937853..7568fe1 100644 --- a/python-api/gstswitch/controller.py +++ b/python-api/gstswitch/controller.py @@ -18,6 +18,10 @@ class Controller(object): :param: None """ + COMPOSITE_NONE = 0 + COMPOSITE_PIP = 1 + COMPOSITE_DUAL_PREVIEW = 2 + COMPOSITE_DUAL_EQUAL = 3 def __init__( self, @@ -206,18 +210,22 @@ def get_preview_ports(self): 'Should return a GVariant tuple') def set_composite_mode(self, mode): - """Set the current composite mode. Modes between 0 and 3 are allowed. + """Set the current composite mode. + Modes allowed are: + - COMPOSITE_NONE + - COMPOSITE_PIP + - COMPOSITE_DUAL_PREVIEW + - COMPOSITE_DUAL_EQUAL :param mode: new composite mode :returns: True when requested """ self.establish_connection() # only modes from 0 to 3 are supported - mode_map = {'NONE': 0, 'PIP': 1, 'DUAL_PREVIEW': 2, 'DUAL_EQUAL': 3} res = None - if mode in mode_map: + if mode in range(0, 4): try: - conn = self.connection.set_composite_mode(mode_map[mode]) + conn = self.connection.set_composite_mode(mode) print conn res = conn.unpack()[0] if res is True: @@ -295,7 +303,8 @@ def adjust_pip(self, xpos, ypos, width, height): def switch(self, channel, port): """Switch the channel to the target port - :param channel: The channel to be switched, 'A', 'B', 'a' + :param channel: The channel to be switched: + 'A', 'B', 'a' :param port: The target port number :returns: True when requested """ diff --git a/python-api/tests/integrationtests/compare.py b/python-api/tests/integrationtests/compare.py index 6cfbdab..48d80d4 100644 --- a/python-api/tests/integrationtests/compare.py +++ b/python-api/tests/integrationtests/compare.py @@ -32,10 +32,10 @@ class BaseCompareVideo(object): """Base class containing image operations""" TESTS = { - 'composite_mode_NONE': 0, - 'composite_mode_PIP': 1, - 'composite_mode_DUAL_PREVIEW': 2, - 'composite_mode_DUAL_EQUAL': 3, + 'composite_mode_0': 0, + 'composite_mode_1': 1, + 'composite_mode_2': 2, + 'composite_mode_3': 3, 'adjust_pip_4': 4 } REF_FRAME_DIR = os.getcwd() + '/tests/integrationtests/reference_frames' diff --git a/python-api/tests/integrationtests/test_controller.py b/python-api/tests/integrationtests/test_controller.py index 8087010..7d9bb6d 100644 --- a/python-api/tests/integrationtests/test_controller.py +++ b/python-api/tests/integrationtests/test_controller.py @@ -306,7 +306,8 @@ def set_composite_mode(self, mode, generate_frames=False): sources.terminate_video() serv.terminate(1) if not generate_frames: - if mode == 'DUAL_EQUAL': + controller = Controller() + if mode == controller.COMPOSITE_DUAL_EQUAL: assert res is False else: assert res is True @@ -345,19 +346,23 @@ def verify_output(self, mode, video): def test_set_composite_mode_none(self): """Test set_composite_mode""" - self.set_composite_mode('NONE') + controller = Controller() + self.set_composite_mode(controller.COMPOSITE_NONE) def test_set_composite_mode_pip(self): """Test set_composite_mode""" - self.set_composite_mode('PIP') + controller = Controller() + self.set_composite_mode(controller.COMPOSITE_PIP) def test_set_composite_mode_preview(self): """Test set_composite_mode""" - self.set_composite_mode('DUAL_PREVIEW') + controller = Controller() + self.set_composite_mode(controller.COMPOSITE_DUAL_PREVIEW) def test_set_composite_mode_equal(self): """Test set_composite_mode""" - self.set_composite_mode('DUAL_EQUAL') + controller = Controller() + self.set_composite_mode(controller.COMPOSITE_DUAL_EQUAL) class TestNewRecord(object): @@ -436,7 +441,7 @@ def adjust_pip(self, sources.new_test_video(pattern=4) sources.new_test_video(pattern=5) controller = Controller() - controller.set_composite_mode('PIP') + controller.set_composite_mode(controller.COMPOSITE_PIP) time.sleep(3) res = controller.adjust_pip(xpos, ypos, width, heigth) time.sleep(3) diff --git a/python-api/tests/unittests/test_controller_unit.py b/python-api/tests/unittests/test_controller_unit.py index 3650931..394d100 100644 --- a/python-api/tests/unittests/test_controller_unit.py +++ b/python-api/tests/unittests/test_controller_unit.py @@ -284,14 +284,14 @@ def test_unpack(self): controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(True) with pytest.raises(ConnectionReturnError): - controller.set_composite_mode('NONE') + controller.set_composite_mode(controller.COMPOSITE_NONE) def test_normal_unpack(self): """Test if valid""" controller = Controller(address='unix:abstract=abcdef') controller.establish_connection = Mock(return_value=None) controller.connection = MockConnection(False) - assert controller.set_composite_mode('NONE') is True + assert controller.set_composite_mode(controller.COMPOSITE_NONE) is True class TestSetEncodeMode(object):