From 2d923cac58695dd958ffb3199c7cce7e8bdba5c8 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Tue, 14 Sep 2021 19:39:15 -0600 Subject: [PATCH] Migrate pygstc to asyncio based sockets. Signed-off-by: James Hilliard --- .github/workflows/main.yml | 8 +- libgstc/python/pygstc/gstc.py | 135 +++++++++--------- libgstc/python/pygstc/tcp.py | 96 ++++--------- libgstc/python/setup.py | 8 +- tests/libgstc/Makefile.am | 2 +- tests/libgstc/python/Makefile.am | 4 +- .../python/test_libgstc_python_bus_filter.py | 18 +-- .../python/test_libgstc_python_bus_timeout.py | 34 ++--- .../python/test_libgstc_python_create.py | 16 +-- .../python/test_libgstc_python_debug_color.py | 10 +- .../test_libgstc_python_debug_enable.py | 10 +- .../python/test_libgstc_python_debug_reset.py | 10 +- .../test_libgstc_python_debug_threshold.py | 42 +++--- .../python/test_libgstc_python_delete.py | 14 +- .../python/test_libgstc_python_element_get.py | 15 +- .../python/test_libgstc_python_element_set.py | 16 +-- .../python/test_libgstc_python_event_eos.py | 18 +-- .../test_libgstc_python_event_flush_start.py | 16 +-- .../python/test_libgstc_python_event_seek.py | 14 +- .../test_libgstc_python_list_elements.py | 12 +- .../test_libgstc_python_list_pipelines.py | 12 +- .../test_libgstc_python_list_properties.py | 12 +- .../test_libgstc_python_list_signals.py | 12 +- .../test_libgstc_python_pipeline_create.py | 10 +- .../test_libgstc_python_pipeline_delete.py | 12 +- .../test_libgstc_python_pipeline_pause.py | 16 +-- .../test_libgstc_python_pipeline_play.py | 20 +-- .../test_libgstc_python_pipeline_stop.py | 16 +-- .../python/test_libgstc_python_read.py | 12 +- .../test_libgstc_python_signal_connect.py | 14 +- .../test_libgstc_python_signal_disconnect.py | 28 ++-- .../test_libgstc_python_signal_timeout.py | 15 +- .../python/test_libgstc_python_update.py | 14 +- 33 files changed, 326 insertions(+), 365 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a3cce7b2..d4e37f5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,7 +11,7 @@ on: jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 @@ -20,7 +20,7 @@ jobs: sudo apt update sudo apt install automake libtool pkg-config libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev sudo apt install libglib2.0-dev libjson-glib-dev gtk-doc-tools libreadline-dev libncursesw5-dev - sudo apt install libdaemon-dev libjansson-dev python3-pip python3-setuptools libsoup2.4 + sudo apt install libdaemon-dev libjansson-dev python3-pip python3-setuptools libsoup2.4-dev - name: Generate run: ./autogen.sh @@ -28,10 +28,10 @@ jobs: run: ./configure CFLAGS=-Werror - name: Compile run: make - - name: Checks - run: make check - name: Install run: sudo make install + - name: Checks + run: make check - name: List Pipelines Verification run: | gstd -e diff --git a/libgstc/python/pygstc/gstc.py b/libgstc/python/pygstc/gstc.py index 59eb1a3b..bf01d7bc 100644 --- a/libgstc/python/pygstc/gstc.py +++ b/libgstc/python/pygstc/gstc.py @@ -28,6 +28,7 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. +import asyncio import inspect import json import traceback @@ -162,7 +163,7 @@ def __init__( % (self._ip, self._port)) self._ipc = Ipc(self._logger, self._ip, self._port) self._timeout = timeout - self.ping_gstd() + asyncio.ensure_future(self.ping_gstd()) def _check_parameters(self, parameter_list, type_list): """ @@ -200,7 +201,7 @@ def _check_parameters(self, parameter_list, type_list): parameter_string_list += [str(parameter)] return parameter_string_list - def _send_cmd_line(self, cmd_line): + async def _send_cmd_line(self, cmd_line): """ Send a command using an abstract IPC and wait for the response. @@ -223,7 +224,7 @@ def _send_cmd_line(self, cmd_line): """ try: cmd = cmd_line[0] - jresult = self._ipc.send(cmd_line, timeout=self._timeout) + jresult = await self._ipc.send(cmd_line, timeout=self._timeout) result = json.loads(jresult) if result['code'] != GstcErrorCode.GSTC_OK.value: self._logger.error('%s error: %s' % (cmd, @@ -246,7 +247,7 @@ def _send_cmd_line(self, cmd_line): raise GstcError('GstClient time out ocurred', GstcErrorCode.GSTC_TIMEOUT) from e - def ping_gstd(self): + async def ping_gstd(self): """ Test if Gstd responds in the configured address and port @@ -260,7 +261,7 @@ def ping_gstd(self): """ self._logger.info('Sending ping to Gstd') try: - jresult = self._ipc.send(['list_pipelines'], timeout=1) + jresult = await self._ipc.send(['list_pipelines'], timeout=1) # Verify correct data format result = json.loads(jresult) if ('description' in result and @@ -286,7 +287,7 @@ def ping_gstd(self): raise GstcError('GstClient time out ocurred', GstcErrorCode.GSTC_TIMEOUT) from e - def bus_filter(self, pipe_name, filter): + async def bus_filter(self, pipe_name, filter): """ Select the types of message to be read from the bus. Separate with a '+', i.e.: eos+warning+error. @@ -309,9 +310,9 @@ def bus_filter(self, pipe_name, filter): self._logger.info('Setting bus read filter of pipeline %s to %s' % (pipe_name, filter)) parameters = self._check_parameters([pipe_name, filter], [str, str]) - self._send_cmd_line(['bus_filter'] + parameters) + await self._send_cmd_line(['bus_filter'] + parameters) - def bus_read(self, pipe_name): + async def bus_read(self, pipe_name): """ Read the bus and wait. @@ -335,10 +336,10 @@ def bus_read(self, pipe_name): self._logger.info('Reading bus of pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - result = self._send_cmd_line(['bus_read'] + parameters) + result = await self._send_cmd_line(['bus_read'] + parameters) return result['response'] - def bus_timeout(self, pipe_name, timeout): + async def bus_timeout(self, pipe_name, timeout): """ Apply a timeout for the bus polling. Parameters @@ -360,9 +361,9 @@ def bus_timeout(self, pipe_name, timeout): self._logger.info('Setting bus read timeout of pipeline %s to %s' % (pipe_name, timeout)) parameters = self._check_parameters([pipe_name, timeout], [str, int]) - self._send_cmd_line(['bus_timeout'] + parameters) + await self._send_cmd_line(['bus_timeout'] + parameters) - def create( + async def create( self, uri, property, @@ -392,9 +393,9 @@ def create( % (property, uri, value)) parameters = self._check_parameters( [uri, property, value], [str, str, str]) - self._send_cmd_line(['create'] + parameters) + await self._send_cmd_line(['create'] + parameters) - def debug_color(self, colors): + async def debug_color(self, colors): """ Enable/Disable colors in the debug logging. @@ -413,9 +414,9 @@ def debug_color(self, colors): self._logger.info('Enabling/Disabling GStreamer debug colors') parameters = self._check_parameters([colors], [bool]) - self._send_cmd_line(['debug_color'] + parameters) + await self._send_cmd_line(['debug_color'] + parameters) - def debug_enable(self, enable): + async def debug_enable(self, enable): """ Enable/Disable GStreamer debug. @@ -434,9 +435,9 @@ def debug_enable(self, enable): self._logger.info('Enabling/Disabling GStreamer debug') parameters = self._check_parameters([enable], [bool]) - self._send_cmd_line(['debug_enable'] + parameters) + await self._send_cmd_line(['debug_enable'] + parameters) - def debug_reset(self, reset): + async def debug_reset(self, reset): """ Enable/Disable debug threshold reset. @@ -455,9 +456,9 @@ def debug_reset(self, reset): self._logger.info('Enabling/Disabling GStreamer debug threshold reset') parameters = self._check_parameters([reset], [bool]) - self._send_cmd_line(['debug_reset'] + parameters) + await self._send_cmd_line(['debug_reset'] + parameters) - def debug_threshold(self, threshold): + async def debug_threshold(self, threshold): """ The debug filter to apply (as you would use with gst-launch). @@ -486,9 +487,9 @@ def debug_threshold(self, threshold): self._logger.info('Setting GStreamer debug threshold to %s' % threshold) parameters = self._check_parameters([threshold], [str]) - self._send_cmd_line(['debug_threshold'] + parameters) + await self._send_cmd_line(['debug_threshold'] + parameters) - def delete(self, uri, name): + async def delete(self, uri, name): """ Delete the resource held at the given URI with the given name. @@ -509,9 +510,9 @@ def delete(self, uri, name): self._logger.info('Deleting name %s at uri "%s"' % (name, uri)) parameters = self._check_parameters([uri, name], [str, str]) - self._send_cmd_line(['delete'] + parameters) + await self._send_cmd_line(['delete'] + parameters) - def element_get( + async def element_get( self, pipe_name, element, @@ -547,10 +548,10 @@ def element_get( (element, prop, pipe_name)) parameters = self._check_parameters( [pipe_name, element, prop], [str, str, str]) - result = self._send_cmd_line(['element_get'] + parameters) + result = await self._send_cmd_line(['element_get'] + parameters) return result['response']['value'] - def element_set( + async def element_set( self, pipe_name, element, @@ -583,9 +584,9 @@ def element_set( % (element, prop, pipe_name, value)) parameters = self._check_parameters( [pipe_name, element, prop, value], [str, str, str, str]) - self._send_cmd_line(['element_set'] + parameters) + await self._send_cmd_line(['element_set'] + parameters) - def event_eos(self, pipe_name): + async def event_eos(self, pipe_name): """ Send an end-of-stream event. @@ -605,9 +606,9 @@ def event_eos(self, pipe_name): self._logger.info('Sending end-of-stream event to pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['event_eos'] + parameters) + await self._send_cmd_line(['event_eos'] + parameters) - def event_flush_start(self, pipe_name): + async def event_flush_start(self, pipe_name): """ Put the pipeline in flushing mode. @@ -627,9 +628,9 @@ def event_flush_start(self, pipe_name): self._logger.info('Putting pipeline %s in flushing mode' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['event_flush_start'] + parameters) + await self._send_cmd_line(['event_flush_start'] + parameters) - def event_flush_stop(self, pipe_name, reset=True): + async def event_flush_stop(self, pipe_name, reset=True): """ Take the pipeline out from flushing mode. @@ -651,9 +652,9 @@ def event_flush_stop(self, pipe_name, reset=True): self._logger.info('Taking pipeline %s out of flushing mode' % pipe_name) parameters = self._check_parameters([pipe_name, reset], [str, bool]) - self._send_cmd_line(['event_flush_stop'] + parameters) + await self._send_cmd_line(['event_flush_stop'] + parameters) - def event_seek( + async def event_seek( self, pipe_name, rate=1.0, @@ -702,9 +703,9 @@ def event_seek( end], [ str, float, int, int, int, int, int, int]) - self._send_cmd_line(['event_seek'] + parameters) + await self._send_cmd_line(['event_seek'] + parameters) - def list_elements(self, pipe_name): + async def list_elements(self, pipe_name): """ List the elements in a given pipeline. @@ -728,10 +729,10 @@ def list_elements(self, pipe_name): self._logger.info('Listing elements of pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - result = self._send_cmd_line(['list_elements'] + parameters) + result = await self._send_cmd_line(['list_elements'] + parameters) return result['response']['nodes'] - def list_pipelines(self): + async def list_pipelines(self): """ List the existing pipelines @@ -749,10 +750,10 @@ def list_pipelines(self): """ self._logger.info('Listing pipelines') - result = self._send_cmd_line(['list_pipelines']) + result = await self._send_cmd_line(['list_pipelines']) return result['response']['nodes'] - def list_properties(self, pipe_name, element): + async def list_properties(self, pipe_name, element): """ List the properties of an element in a given pipeline. @@ -779,10 +780,10 @@ def list_properties(self, pipe_name, element): self._logger.info('Listing properties of element %s from pipeline %s' % (element, pipe_name)) parameters = self._check_parameters([pipe_name, element], [str, str]) - result = self._send_cmd_line(['list_properties'] + parameters) + result = await self._send_cmd_line(['list_properties'] + parameters) return result['response']['nodes'] - def list_signals(self, pipe_name, element): + async def list_signals(self, pipe_name, element): """ List the signals of an element in a given pipeline. @@ -809,10 +810,10 @@ def list_signals(self, pipe_name, element): self._logger.info('Listing signals of element %s from pipeline %s' % (element, pipe_name)) parameters = self._check_parameters([pipe_name, element], [str, str]) - result = self._send_cmd_line(['list_signals'] + parameters) + result = await self._send_cmd_line(['list_signals'] + parameters) return result['response']['nodes'] - def pipeline_create(self, pipe_name, pipe_desc): + async def pipeline_create(self, pipe_name, pipe_desc): """ Create a new pipeline based on the name and description. @@ -827,9 +828,9 @@ def pipeline_create(self, pipe_name, pipe_desc): self._logger.info('Creating pipeline %s with description "%s"' % (pipe_name, pipe_desc)) parameters = self._check_parameters([pipe_name, pipe_desc], [str, str]) - self._send_cmd_line(['pipeline_create'] + parameters) + await self._send_cmd_line(['pipeline_create'] + parameters) - def pipeline_delete(self, pipe_name): + async def pipeline_delete(self, pipe_name): """ Delete the pipeline with the given name. @@ -848,9 +849,9 @@ def pipeline_delete(self, pipe_name): self._logger.info('Deleting pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_delete'] + parameters) + await self._send_cmd_line(['pipeline_delete'] + parameters) - def pipeline_pause(self, pipe_name): + async def pipeline_pause(self, pipe_name): """ Set the pipeline to paused. @@ -869,9 +870,9 @@ def pipeline_pause(self, pipe_name): self._logger.info('Pausing pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_pause'] + parameters) + await self._send_cmd_line(['pipeline_pause'] + parameters) - def pipeline_play(self, pipe_name): + async def pipeline_play(self, pipe_name): """ Set the pipeline to playing. @@ -890,9 +891,9 @@ def pipeline_play(self, pipe_name): self._logger.info('Playing pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_play'] + parameters) + await self._send_cmd_line(['pipeline_play'] + parameters) - def pipeline_stop(self, pipe_name): + async def pipeline_stop(self, pipe_name): """ Set the pipeline to null. @@ -911,9 +912,9 @@ def pipeline_stop(self, pipe_name): self._logger.info('Stoping pipeline %s' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_stop'] + parameters) + await self._send_cmd_line(['pipeline_stop'] + parameters) - def pipeline_get_graph(self, pipe_name): + async def pipeline_get_graph(self, pipe_name): """ Get the pipeline graph. @@ -937,10 +938,10 @@ def pipeline_get_graph(self, pipe_name): self._logger.info('Getting the pipeline %s graph' % pipe_name) parameters = self._check_parameters([pipe_name], [str]) - result = self._send_cmd_line(['pipeline_get_graph'] + parameters) + result = await self._send_cmd_line(['pipeline_get_graph'] + parameters) return result - def pipeline_verbose(self, pipe_name, value): + async def pipeline_verbose(self, pipe_name, value): """ Set the pipeline verbose mode. Only supported on GST Version >= 1.10 @@ -963,9 +964,9 @@ def pipeline_verbose(self, pipe_name, value): self._logger.info('Setting the pipeline %s verbose mode to %s' % (pipe_name, value)) parameters = self._check_parameters([pipe_name, value], [str, bool]) - self._send_cmd_line(['pipeline_verbose'] + parameters) + await self._send_cmd_line(['pipeline_verbose'] + parameters) - def read(self, uri): + async def read(self, uri): """ Read the resource held at the given URI with the given name. @@ -989,10 +990,10 @@ def read(self, uri): self._logger.info('Reading uri %s' % uri) parameters = self._check_parameters([uri], [str]) - result = self._send_cmd_line(['read'] + parameters) + result = await self._send_cmd_line(['read'] + parameters) return result['response'] - def signal_connect( + async def signal_connect( self, pipe_name, element, @@ -1028,10 +1029,10 @@ def signal_connect( (signal, element, pipe_name)) parameters = self._check_parameters( [pipe_name, element, signal], [str, str, str]) - result = self._send_cmd_line(['signal_connect'] + parameters) + result = await self._send_cmd_line(['signal_connect'] + parameters) return result['response'] - def signal_disconnect( + async def signal_disconnect( self, pipe_name, element, @@ -1062,9 +1063,9 @@ def signal_disconnect( (signal, element, pipe_name)) parameters = self._check_parameters( [pipe_name, element, signal], [str, str, str]) - self._send_cmd_line(['signal_disconnect'] + parameters) + await self._send_cmd_line(['signal_disconnect'] + parameters) - def signal_timeout( + async def signal_timeout( self, pipe_name, element, @@ -1099,9 +1100,9 @@ def signal_timeout( timeout %s' % (signal, element, pipe_name, timeout)) parameters = self._check_parameters( [pipe_name, element, signal, timeout], [str, str, str, int]) - self._send_cmd_line(['signal_timeout'] + parameters) + await self._send_cmd_line(['signal_timeout'] + parameters) - def update(self, uri, value): + async def update(self, uri, value): """ Update the resource at the given URI. @@ -1123,4 +1124,4 @@ def update(self, uri, value): self._logger.info('Updating uri %s with value "%s"' % (uri, value)) parameters = self._check_parameters([uri, value], [str, str]) - self._send_cmd_line(['update'] + parameters) + await self._send_cmd_line(['update'] + parameters) diff --git a/libgstc/python/pygstc/tcp.py b/libgstc/python/pygstc/tcp.py index 3973fae0..9c2dbd4f 100644 --- a/libgstc/python/pygstc/tcp.py +++ b/libgstc/python/pygstc/tcp.py @@ -28,9 +28,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. -import json -import select +import asyncio import socket +from contextlib import asynccontextmanager """ GstClient - Ipc Class @@ -54,7 +54,7 @@ def __init__( ip, port, maxsize=None, - terminator='\x00'.encode('utf-8'), + terminator=b'\x00', ): """ Initialize new Ipc @@ -81,7 +81,23 @@ def __init__( self._maxsize = maxsize self._terminator = terminator - def send(self, line, timeout=None): + @asynccontextmanager + async def gstd_conn(self): + kwargs = { + 'host': self._ip, + 'port': self._port + } + if self._maxsize is not None: + kwargs['limit'] = self._maxsize + reader, writer = await asyncio.open_connection(**kwargs) + try: + yield reader, writer + finally: + if not writer.is_closing(): + writer.close() + await writer.wait_closed() + + async def send(self, line, timeout=None): """ Create a socket and sends a message through it @@ -103,82 +119,30 @@ def send(self, line, timeout=None): data : string Decoded JSON string with the response """ - data = None self._logger.debug('GSTD socket sending line: %s' % line) - try: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - - s.connect((self._ip, self._port)) - s.sendall(' '.join(line).encode('utf-8')) - data = self._recvall(s, timeout) - if not data: - raise socket.error("Socket read error happened") - data = data.decode('utf-8') - s.close() - return data + try: + async with self.gstd_conn() as (reader, writer): + writer.write(' '.join(line).encode('utf-8')) + await writer.drain() + fut = reader.readuntil(separator=self._terminator) + data = await asyncio.wait_for(fut, timeout=timeout) + if not data: + raise socket.error("Socket read error happened") + data = data[:-1].decode('utf-8') + return data except BufferError as e: - s.close() error_msg = 'Server response too long' self._logger.error(error_msg) raise BufferError(error_msg)\ from e except TimeoutError as e: - s.close() error_msg = 'Server took too long to respond' self._logger.error(error_msg) raise TimeoutError(error_msg)\ from e except socket.error as e: - s.close() error_msg = 'Server did not respond. Is it up?' self._logger.error(error_msg) raise ConnectionRefusedError(error_msg)\ from e - - def _recvall(self, sock, timeout): - """ - Wait for a response message from the socket - - Parameters - ---------- - sock : string - The socket to poll - timeout : float - Timeout in seconds to wait for a response. 0: non-blocking, None: blocking - - Raises - ------ - socket.error - Error is triggered when Gstd IPC fails - BufferError - When the incoming buffer is too big. - - Returns - ------- - buf : string - Raw socket response - """ - buf = b'' - newbuf = '' - try: - sock.settimeout(timeout) - except socket.error as e: - raise TimeoutError from e - - while True: - if (self._maxsize and self._maxsize > len(newbuf)): - raise BufferError - - try: - newbuf = sock.recv(self._socket_read_size) - # Raise an exception timeout - except socket.error as e: - raise TimeoutError from e - - if self._terminator in newbuf: - buf += newbuf[:newbuf.find(self._terminator)] - break - else: - buf += newbuf - return buf diff --git a/libgstc/python/setup.py b/libgstc/python/setup.py index f2c164fb..aa89fdc7 100755 --- a/libgstc/python/setup.py +++ b/libgstc/python/setup.py @@ -44,10 +44,10 @@ 'tests']), scripts=[], classifiers=['Development Status :: 3 - Alpha', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7'], - python_requires='>=3.5', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9'], + python_requires='>=3.7', install_requires=[], command_options={}, extras_require={}, diff --git a/tests/libgstc/Makefile.am b/tests/libgstc/Makefile.am index 389acd78..933cfcfe 100644 --- a/tests/libgstc/Makefile.am +++ b/tests/libgstc/Makefile.am @@ -1,5 +1,5 @@ SUBDIRS=c # FIXME Disable pygstc checks -#SUBDIRS = python +SUBDIRS = python diff --git a/tests/libgstc/python/Makefile.am b/tests/libgstc/python/Makefile.am index 44f0ddac..e89cd999 100644 --- a/tests/libgstc/python/Makefile.am +++ b/tests/libgstc/python/Makefile.am @@ -29,4 +29,6 @@ TESTS = \ test_libgstc_python_update.py \ test_libgstc_python_stop_gstd.py -export PYTHONPATH = $PYTHONPATH:$(top_srcdir)/libgstc +check_SCRIPTS = $(TESTS) + +export PYTHONPATH = $PYTHONPATH:$(top_srcdir)/libgstc/python diff --git a/tests/libgstc/python/test_libgstc_python_bus_filter.py b/tests/libgstc/python/test_libgstc_python_bus_filter.py index e86ed131..b6b65c65 100755 --- a/tests/libgstc/python/test_libgstc_python_bus_filter.py +++ b/tests/libgstc/python/test_libgstc_python_bus_filter.py @@ -35,20 +35,20 @@ from pygstc.logger import * -class TestGstcBusFilterMethods(unittest.TestCase): +class TestGstcBusFilterMethods(unittest.IsolatedAsyncioTestCase): - def test_bus_filter_eos(self): + async def test_bus_filter_eos(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.event_eos('p0') - self.gstd_client.bus_filter('p0', 'eos') - ret = self.gstd_client.bus_read('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.event_eos('p0') + await self.gstd_client.bus_filter('p0', 'eos') + ret = await self.gstd_client.bus_read('p0') self.assertEqual(ret['type'], 'eos') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_bus_timeout.py b/tests/libgstc/python/test_libgstc_python_bus_timeout.py index 8c72644d..c01088fc 100755 --- a/tests/libgstc/python/test_libgstc_python_bus_timeout.py +++ b/tests/libgstc/python/test_libgstc_python_bus_timeout.py @@ -35,33 +35,33 @@ from pygstc.logger import * -class TestGstcBusTimeoutMethods(unittest.TestCase): +class TestGstcBusTimeoutMethods(unittest.IsolatedAsyncioTestCase): - def test_bus_timeout_eos(self): + async def test_bus_timeout_eos(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.event_eos('p0') - self.gstd_client.bus_filter('p0', 'eos') - self.gstd_client.bus_timeout('p0', 1000) - ret = self.gstd_client.bus_read('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.event_eos('p0') + await self.gstd_client.bus_filter('p0', 'eos') + await self.gstd_client.bus_timeout('p0', 1000) + ret = await self.gstd_client.bus_read('p0') self.assertEqual(ret['type'], 'eos') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') - def test_bus_timeout_no_response(self): + async def test_bus_timeout_no_response(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.bus_timeout('p0', 1000) - ret = self.gstd_client.bus_read('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.bus_timeout('p0', 1000) + ret = await self.gstd_client.bus_read('p0') self.assertEqual(ret, None) - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_create.py b/tests/libgstc/python/test_libgstc_python_create.py index c35a0437..fd6c5d5d 100755 --- a/tests/libgstc/python/test_libgstc_python_create.py +++ b/tests/libgstc/python/test_libgstc_python_create.py @@ -35,26 +35,26 @@ from pygstc.logger import * -class TestGstcCreateMethods(unittest.TestCase): +class TestGstcCreateMethods(unittest.IsolatedAsyncioTestCase): - def test_create_pipeline(self): + async def test_create_pipeline(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - ret = self.gstd_client.read('pipelines') + ret = await self.gstd_client.read('pipelines') initial_n_pipes = len(ret['nodes']) - self.gstd_client.create('pipelines', 'p0', pipeline) - ret = self.gstd_client.read('pipelines') + await self.gstd_client.create('pipelines', 'p0', pipeline) + ret = await self.gstd_client.read('pipelines') final_n_pipes = len(ret['nodes']) self.assertEqual(final_n_pipes, initial_n_pipes + 1) - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_delete('p0') - def test_create_bad_pipeline(self): + async def test_create_bad_pipeline(self): pipeline = 'source sink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) with self.assertRaises(GstdError): - self.gstd_client.create('pipelines', 'p0', pipeline) + await self.gstd_client.create('pipelines', 'p0', pipeline) if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_debug_color.py b/tests/libgstc/python/test_libgstc_python_debug_color.py index 46f33319..03e75208 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_color.py +++ b/tests/libgstc/python/test_libgstc_python_debug_color.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcDebugColorMethods(unittest.TestCase): +class TestGstcDebugColorMethods(unittest.IsolatedAsyncioTestCase): - def test_debug_color_true(self): + async def test_debug_color_true(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_color(True) + await self.gstd_client.debug_color(True) - def test_debug_color_false(self): + async def test_debug_color_false(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_color(False) + await self.gstd_client.debug_color(False) if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_debug_enable.py b/tests/libgstc/python/test_libgstc_python_debug_enable.py index cee836ad..41cb53b2 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_enable.py +++ b/tests/libgstc/python/test_libgstc_python_debug_enable.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcDebugEnableMethods(unittest.TestCase): +class TestGstcDebugEnableMethods(unittest.IsolatedAsyncioTestCase): - def test_debug_enable_true(self): + async def test_debug_enable_true(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_enable(True) + await self.gstd_client.debug_enable(True) - def test_debug_enable_false(self): + async def test_debug_enable_false(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_enable(False) + await self.gstd_client.debug_enable(False) if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_debug_reset.py b/tests/libgstc/python/test_libgstc_python_debug_reset.py index 6fd315f7..05ee9fae 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_reset.py +++ b/tests/libgstc/python/test_libgstc_python_debug_reset.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcDebugResetMethods(unittest.TestCase): +class TestGstcDebugResetMethods(unittest.IsolatedAsyncioTestCase): - def test_debug_reset_true(self): + async def test_debug_reset_true(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_reset(True) + await self.gstd_client.debug_reset(True) - def test_debug_reset_false(self): + async def test_debug_reset_false(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_reset(False) + await self.gstd_client.debug_reset(False) if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_debug_threshold.py b/tests/libgstc/python/test_libgstc_python_debug_threshold.py index b2b9dda2..ff958dea 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_threshold.py +++ b/tests/libgstc/python/test_libgstc_python_debug_threshold.py @@ -34,57 +34,57 @@ from pygstc.logger import * -class TestGstcDebugThresholdMethods(unittest.TestCase): +class TestGstcDebugThresholdMethods(unittest.IsolatedAsyncioTestCase): - def test_debug_threshold_none(self): + async def test_debug_threshold_none(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('0') + await self.gstd_client.debug_threshold('0') - def test_debug_threshold_error(self): + async def test_debug_threshold_error(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('1') + await self.gstd_client.debug_threshold('1') - def test_debug_threshold_warning(self): + async def test_debug_threshold_warning(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('2') + await self.gstd_client.debug_threshold('2') - def test_debug_threshold_fixme(self): + async def test_debug_threshold_fixme(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('3') + await self.gstd_client.debug_threshold('3') - def test_debug_threshold_info(self): + async def test_debug_threshold_info(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('4') + await self.gstd_client.debug_threshold('4') - def test_debug_threshold_debug(self): + async def test_debug_threshold_debug(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('5') + await self.gstd_client.debug_threshold('5') - def test_debug_threshold_log(self): + async def test_debug_threshold_log(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('6') + await self.gstd_client.debug_threshold('6') - def test_debug_threshold_trace(self): + async def test_debug_threshold_trace(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('7') + await self.gstd_client.debug_threshold('7') - def test_debug_threshold_memdump(self): + async def test_debug_threshold_memdump(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('8') + await self.gstd_client.debug_threshold('8') - def test_debug_threshold_invalid(self): + async def test_debug_threshold_invalid(self): self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.debug_threshold('9') + await self.gstd_client.debug_threshold('9') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_delete.py b/tests/libgstc/python/test_libgstc_python_delete.py index 8193f707..a47a50b8 100755 --- a/tests/libgstc/python/test_libgstc_python_delete.py +++ b/tests/libgstc/python/test_libgstc_python_delete.py @@ -35,20 +35,20 @@ from pygstc.logger import * -class TestGstcDeleteMethods(unittest.TestCase): +class TestGstcDeleteMethods(unittest.IsolatedAsyncioTestCase): - def test_delete_pipeline(self): + async def test_delete_pipeline(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - ret = self.gstd_client.read('pipelines') + ret = await self.gstd_client.read('pipelines') initial_n_pipes = len(ret['nodes']) - self.gstd_client.create('pipelines', 'p0', pipeline) - ret = self.gstd_client.read('pipelines') + await self.gstd_client.create('pipelines', 'p0', pipeline) + ret = await self.gstd_client.read('pipelines') final_n_pipes = len(ret['nodes']) self.assertEqual(initial_n_pipes + 1, final_n_pipes) - self.gstd_client.delete('pipelines', 'p0') - ret = self.gstd_client.read('pipelines') + await self.gstd_client.delete('pipelines', 'p0') + ret = await self.gstd_client.read('pipelines') final_n_pipes = len(ret['nodes']) self.assertEqual(initial_n_pipes, final_n_pipes) diff --git a/tests/libgstc/python/test_libgstc_python_element_get.py b/tests/libgstc/python/test_libgstc_python_element_get.py index 54f33c82..96582b45 100755 --- a/tests/libgstc/python/test_libgstc_python_element_get.py +++ b/tests/libgstc/python/test_libgstc_python_element_get.py @@ -35,20 +35,19 @@ from pygstc.logger import * -class TestGstcElementGetMethods(unittest.TestCase): +class TestGstcElementGetMethods(unittest.IsolatedAsyncioTestCase): - def test_element_get_property_value(self): + async def test_element_get_property_value(self): pipeline = 'videotestsrc name=v0 pattern=ball ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.assertEqual( - self.gstd_client.element_get( + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.element_get( 'p0', 'v0', - 'pattern'), - 'Moving ball') - self.gstd_client.pipeline_delete('p0') + 'pattern') + self.assertEqual(ret, 'Moving ball') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_element_set.py b/tests/libgstc/python/test_libgstc_python_element_set.py index 959350f0..d61fd43c 100755 --- a/tests/libgstc/python/test_libgstc_python_element_set.py +++ b/tests/libgstc/python/test_libgstc_python_element_set.py @@ -35,23 +35,23 @@ from pygstc.logger import * -class TestGstcElementSetMethods(unittest.TestCase): +class TestGstcElementSetMethods(unittest.IsolatedAsyncioTestCase): - def test_element_set_property_value(self): + async def test_element_set_property_value(self): pipeline = 'videotestsrc name=v0 pattern=ball ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_create('p0', pipeline) self.assertEqual( - self.gstd_client.element_get( + await self.gstd_client.element_get( 'p0', 'v0', 'pattern'), 'Moving ball') - self.gstd_client.element_set('p0', 'v0', 'pattern', 'bar') - self.assertEqual(self.gstd_client.element_get('p0', 'v0', - 'pattern'), 'Bar') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.element_set('p0', 'v0', 'pattern', 'bar') + ret = await self.gstd_client.element_get('p0', 'v0', 'pattern') + self.assertEqual(ret, 'Bar') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_event_eos.py b/tests/libgstc/python/test_libgstc_python_event_eos.py index 7666f702..6c5ae638 100755 --- a/tests/libgstc/python/test_libgstc_python_event_eos.py +++ b/tests/libgstc/python/test_libgstc_python_event_eos.py @@ -35,20 +35,20 @@ from pygstc.logger import * -class TestGstcEventEosMethods(unittest.TestCase): +class TestGstcEventEosMethods(unittest.IsolatedAsyncioTestCase): - def test_event_eos(self): + async def test_event_eos(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.event_eos('p0') - self.gstd_client.bus_filter('p0', 'eos') - ret = self.gstd_client.bus_read('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.event_eos('p0') + await self.gstd_client.bus_filter('p0', 'eos') + ret = await self.gstd_client.bus_read('p0') self.assertEqual(ret['type'], 'eos') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_event_flush_start.py b/tests/libgstc/python/test_libgstc_python_event_flush_start.py index e4128313..3b737de1 100755 --- a/tests/libgstc/python/test_libgstc_python_event_flush_start.py +++ b/tests/libgstc/python/test_libgstc_python_event_flush_start.py @@ -35,18 +35,18 @@ from pygstc.logger import * -class TestGstcEventFlushStartMethods(unittest.TestCase): +class TestGstcEventFlushStartMethods(unittest.IsolatedAsyncioTestCase): - def test_event_flush_start(self): + async def test_event_flush_start(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.event_flush_start('p0') - self.gstd_client.event_flush_stop('p0') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.event_flush_start('p0') + await self.gstd_client.event_flush_stop('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_event_seek.py b/tests/libgstc/python/test_libgstc_python_event_seek.py index 0b4e656d..2866aa1c 100755 --- a/tests/libgstc/python/test_libgstc_python_event_seek.py +++ b/tests/libgstc/python/test_libgstc_python_event_seek.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcEventSeekMethods(unittest.TestCase): +class TestGstcEventSeekMethods(unittest.IsolatedAsyncioTestCase): - def test_event_seek(self): + async def test_event_seek(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.event_seek('p0') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.event_seek('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_list_elements.py b/tests/libgstc/python/test_libgstc_python_list_elements.py index 95b2a49b..4b039cbd 100755 --- a/tests/libgstc/python/test_libgstc_python_list_elements.py +++ b/tests/libgstc/python/test_libgstc_python_list_elements.py @@ -35,16 +35,16 @@ from pygstc.logger import * -class TestGstcListElementsMethods(unittest.TestCase): +class TestGstcListElementsMethods(unittest.IsolatedAsyncioTestCase): - def test_list_elements(self): + async def test_list_elements(self): pipeline = 'videotestsrc name=v0 ! fakesink name=x0' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.assertEqual(self.gstd_client.list_elements('p0'), - [{'name': 'x0'}, {'name': 'v0'}]) - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.list_elements('p0') + self.assertEqual(ret, [{'name': 'x0'}, {'name': 'v0'}]) + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_list_pipelines.py b/tests/libgstc/python/test_libgstc_python_list_pipelines.py index 564c14d8..89d6e70f 100755 --- a/tests/libgstc/python/test_libgstc_python_list_pipelines.py +++ b/tests/libgstc/python/test_libgstc_python_list_pipelines.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcListPipelinesMethods(unittest.TestCase): +class TestGstcListPipelinesMethods(unittest.IsolatedAsyncioTestCase): - def test_list_pipelines(self): + async def test_list_pipelines(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - initial_n_pipes = len(self.gstd_client.list_pipelines()) - self.gstd_client.create('pipelines', 'p0', pipeline) - final_n_pipes = len(self.gstd_client.list_pipelines()) + initial_n_pipes = len(await self.gstd_client.list_pipelines()) + await self.gstd_client.create('pipelines', 'p0', pipeline) + final_n_pipes = len(await self.gstd_client.list_pipelines()) self.assertEqual(final_n_pipes, initial_n_pipes + 1) - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_list_properties.py b/tests/libgstc/python/test_libgstc_python_list_properties.py index fdee9375..27c9b467 100755 --- a/tests/libgstc/python/test_libgstc_python_list_properties.py +++ b/tests/libgstc/python/test_libgstc_python_list_properties.py @@ -35,9 +35,9 @@ from pygstc.logger import * -class TestGstcListPropertiesMethods(unittest.TestCase): +class TestGstcListPropertiesMethods(unittest.IsolatedAsyncioTestCase): - def test_list_properties(self): + async def test_list_properties(self): pipeline = \ 'videotestsrc name=v0 ! identity name=i0 ! fakesink name=x0' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') @@ -62,10 +62,10 @@ def test_list_properties(self): {'name': 'signal-handoffs'}, {'name': 'drop-allocation'}, ] - self.gstd_client.pipeline_create('p0', pipeline) - self.assertEqual(self.gstd_client.list_properties('p0', 'i0')[0], - identity_properties[0]) - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.list_properties('p0', 'i0') + self.assertEqual(ret[0], identity_properties[0]) + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_list_signals.py b/tests/libgstc/python/test_libgstc_python_list_signals.py index 5d202345..74f31d30 100755 --- a/tests/libgstc/python/test_libgstc_python_list_signals.py +++ b/tests/libgstc/python/test_libgstc_python_list_signals.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcListSignalsMethods(unittest.TestCase): +class TestGstcListSignalsMethods(unittest.IsolatedAsyncioTestCase): - def test_list_signals(self): + async def test_list_signals(self): pipeline = \ 'videotestsrc name=v0 ! identity name=i0 ! fakesink name=x0' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.assertEqual(self.gstd_client.list_signals('p0', 'i0'), - [{'name': 'handoff'}]) - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.list_signals('p0', 'i0') + self.assertEqual(ret, [{'name': 'handoff'}]) + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_pipeline_create.py b/tests/libgstc/python/test_libgstc_python_pipeline_create.py index c7949de1..15e1ad70 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_create.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_create.py @@ -35,16 +35,16 @@ from pygstc.logger import * -class TestGstcPipelineCreateMethods(unittest.TestCase): +class TestGstcPipelineCreateMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_pipeline_create(self): + async def test_libgstc_python_pipeline_create(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - ret = self.gstd_client.read('pipelines') + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.read('pipelines') self.assertEqual(ret['nodes'][0]['name'], 'p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_pipeline_delete.py b/tests/libgstc/python/test_libgstc_python_pipeline_delete.py index 4c447c9a..5e666965 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_delete.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_delete.py @@ -35,17 +35,17 @@ from pygstc.logger import * -class TestGstcPipelineDeleteMethods(unittest.TestCase): +class TestGstcPipelineDeleteMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_pipeline_delete(self): + async def test_libgstc_python_pipeline_delete(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - ret_prev = self.gstd_client.read('pipelines') + await self.gstd_client.pipeline_create('p0', pipeline) + ret_prev = await self.gstd_client.read('pipelines') len_prev = len(ret_prev['nodes']) - self.gstd_client.pipeline_delete('p0') - ret_post = self.gstd_client.read('pipelines') + await self.gstd_client.pipeline_delete('p0') + ret_post = await self.gstd_client.read('pipelines') len_post = len(ret_post['nodes']) self.assertTrue(len_prev > len_post) diff --git a/tests/libgstc/python/test_libgstc_python_pipeline_pause.py b/tests/libgstc/python/test_libgstc_python_pipeline_pause.py index d0c6e406..88958a1f 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_pause.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_pause.py @@ -35,18 +35,18 @@ from pygstc.logger import * -class TestGstcPipelinePauseMethods(unittest.TestCase): +class TestGstcPipelinePauseMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_pipeline_pause(self): + async def test_libgstc_python_pipeline_pause(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.pipeline_pause('p0') - self.assertEqual(self.gstd_client.read( - 'pipelines/p0/state')['value'], 'PAUSED') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.pipeline_pause('p0') + ret = await self.gstd_client.read('pipelines/p0/state') + self.assertEqual(ret['value'], 'PAUSED') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_pipeline_play.py b/tests/libgstc/python/test_libgstc_python_pipeline_play.py index 86a5eafd..55df98a4 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_play.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_play.py @@ -29,26 +29,26 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. -import time +import asyncio import unittest from pygstc.gstc import * from pygstc.logger import * -class TestGstcPipelinePlayMethods(unittest.TestCase): +class TestGstcPipelinePlayMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_pipeline_play(self): + async def test_libgstc_python_pipeline_play(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - time.sleep(0.1) - self.assertIn(self.gstd_client.read('pipelines/p0/state') - ['value'], ['PLAYING']) - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await asyncio.sleep(0.1) + ret = await self.gstd_client.read('pipelines/p0/state') + self.assertIn(ret['value'], ['PLAYING']) + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_pipeline_stop.py b/tests/libgstc/python/test_libgstc_python_pipeline_stop.py index 274863d8..72eb9545 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_stop.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_stop.py @@ -35,18 +35,18 @@ from pygstc.logger import * -class TestGstcPipelineStopMethods(unittest.TestCase): +class TestGstcPipelineStopMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_pipeline_stop(self): + async def test_libgstc_python_pipeline_stop(self): pipeline = 'videotestsrc name=v0 ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.pipeline_stop('p0') - self.assertEqual(self.gstd_client.read( - 'pipelines/p0/state')['value'], 'NULL') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.pipeline_stop('p0') + ret = await self.gstd_client.read('pipelines/p0/state') + self.assertEqual(ret['value'], 'NULL') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_read.py b/tests/libgstc/python/test_libgstc_python_read.py index de8e40ae..5e4389df 100755 --- a/tests/libgstc/python/test_libgstc_python_read.py +++ b/tests/libgstc/python/test_libgstc_python_read.py @@ -35,18 +35,18 @@ from pygstc.logger import * -class TestGstcReadMethods(unittest.TestCase): +class TestGstcReadMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_read(self): + async def test_libgstc_python_read(self): pipeline = 'videotestsrc name=v0 pattern=ball ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - ret = self.gstd_client.read( + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.read( 'pipelines/p0/elements/v0/properties/pattern') self.assertEqual(ret['value'], 'Moving ball') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_signal_connect.py b/tests/libgstc/python/test_libgstc_python_signal_connect.py index 1d29058f..7825fa93 100755 --- a/tests/libgstc/python/test_libgstc_python_signal_connect.py +++ b/tests/libgstc/python/test_libgstc_python_signal_connect.py @@ -35,20 +35,20 @@ from pygstc.logger import * -class TestGstcSignalConnectMethods(unittest.TestCase): +class TestGstcSignalConnectMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_signal_connect(self): + async def test_libgstc_python_signal_connect(self): pipeline = \ 'videotestsrc ! identity signal-handoffs=true name=identity ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - ret = self.gstd_client.signal_connect('p0', 'identity', + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + ret = await self.gstd_client.signal_connect('p0', 'identity', 'handoff') self.assertEqual(ret['name'], 'handoff') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_signal_disconnect.py b/tests/libgstc/python/test_libgstc_python_signal_disconnect.py index d017846e..8c99dffc 100755 --- a/tests/libgstc/python/test_libgstc_python_signal_disconnect.py +++ b/tests/libgstc/python/test_libgstc_python_signal_disconnect.py @@ -28,41 +28,37 @@ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. - +import asyncio import unittest -import threading from pygstc.gstc import * from pygstc.logger import * -import time -import os ret_val = '' -def signal_connect_test(): +async def signal_connect_test(): global ret_val gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') gstd_client = GstdClient(logger=gstd_logger) - ret_val = gstd_client.signal_connect('p0', 'identity', 'handoff') + ret_val = await gstd_client.signal_connect('p0', 'identity', 'handoff') -class TestGstcSignalDisconnectMethods(unittest.TestCase): +class TestGstcSignalDisconnectMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_signal_disconnect(self): + async def test_libgstc_python_signal_disconnect(self): global ret_val pipeline = 'videotestsrc ! identity name=identity ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - ret_thr = threading.Thread(target=signal_connect_test) - ret_thr.start() - time.sleep(0.1) - self.gstd_client.signal_disconnect('p0', 'identity', 'handoff') - time.sleep(0.1) + await self.gstd_client.pipeline_create('p0', pipeline) + asyncio.ensure_future(signal_connect_test()) + await asyncio.sleep(0.1) + await self.gstd_client.signal_disconnect('p0', 'identity', 'handoff') + await asyncio.sleep(0.1) self.assertEqual(ret_val, None) - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_signal_timeout.py b/tests/libgstc/python/test_libgstc_python_signal_timeout.py index 17c7c157..02eb4a0a 100755 --- a/tests/libgstc/python/test_libgstc_python_signal_timeout.py +++ b/tests/libgstc/python/test_libgstc_python_signal_timeout.py @@ -30,25 +30,24 @@ # OF THE POSSIBILITY OF SUCH DAMAGE. import unittest -import threading from pygstc.gstc import * from pygstc.logger import * -class TestGstcSignalTimeoutMethods(unittest.TestCase): +class TestGstcSignalTimeoutMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_signal_timeout(self): + async def test_libgstc_python_signal_timeout(self): pipeline = 'videotestsrc ! identity name=identity ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.signal_timeout('p0', 'identity', 'handoff', 1) - ret_con = self.gstd_client.signal_connect('p0', 'identity', + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.signal_timeout('p0', 'identity', 'handoff', 1) + ret_con = await self.gstd_client.signal_connect('p0', 'identity', 'handoff') self.assertEqual(ret_con, None) - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_update.py b/tests/libgstc/python/test_libgstc_python_update.py index b6e18c9e..37a01c28 100755 --- a/tests/libgstc/python/test_libgstc_python_update.py +++ b/tests/libgstc/python/test_libgstc_python_update.py @@ -35,20 +35,20 @@ from pygstc.logger import * -class TestGstcUpdateMethods(unittest.TestCase): +class TestGstcUpdateMethods(unittest.IsolatedAsyncioTestCase): - def test_libgstc_python_update(self): + async def test_libgstc_python_update(self): pipeline = 'videotestsrc name=v0 pattern=snow ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.update( + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.update( 'pipelines/p0/elements/v0/properties/pattern', 'ball') - ret = self.gstd_client.read( + ret = await self.gstd_client.read( 'pipelines/p0/elements/v0/properties/pattern') self.assertEqual(ret['value'], 'Moving ball') - self.gstd_client.pipeline_stop('p0') - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_stop('p0') + await self.gstd_client.pipeline_delete('p0') if __name__ == '__main__':