From e582a54e90b55a356878d1965d31c20eb0e192a6 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 | 1 - libgstc/python/pygstc/gstc.py | 154 +++++++++--------- libgstc/python/pygstc/tcp.py | 100 ++++-------- libgstc/python/setup.py | 8 +- tests/libgstc/python/gstd_runner.py | 38 +++-- .../python/test_libgstc_python_bus_filter.py | 16 +- .../python/test_libgstc_python_bus_timeout.py | 32 ++-- .../python/test_libgstc_python_create.py | 14 +- .../python/test_libgstc_python_debug_color.py | 8 +- .../test_libgstc_python_debug_enable.py | 8 +- .../python/test_libgstc_python_debug_reset.py | 8 +- .../test_libgstc_python_debug_threshold.py | 40 ++--- .../python/test_libgstc_python_delete.py | 12 +- .../python/test_libgstc_python_element_get.py | 13 +- .../python/test_libgstc_python_element_set.py | 14 +- .../python/test_libgstc_python_event_eos.py | 16 +- .../test_libgstc_python_event_flush_start.py | 14 +- .../python/test_libgstc_python_event_seek.py | 12 +- .../test_libgstc_python_list_elements.py | 10 +- .../test_libgstc_python_list_pipelines.py | 10 +- .../test_libgstc_python_list_properties.py | 10 +- .../test_libgstc_python_list_signals.py | 10 +- .../test_libgstc_python_pipeline_create.py | 8 +- .../test_libgstc_python_pipeline_delete.py | 10 +- .../test_libgstc_python_pipeline_pause.py | 24 +-- .../test_libgstc_python_pipeline_play.py | 18 +- .../test_libgstc_python_pipeline_stop.py | 14 +- .../python/test_libgstc_python_read.py | 10 +- .../test_libgstc_python_signal_connect.py | 12 +- .../test_libgstc_python_signal_disconnect.py | 29 ++-- .../test_libgstc_python_signal_timeout.py | 13 +- .../python/test_libgstc_python_stop_gstd.py | 7 +- .../python/test_libgstc_python_update.py | 12 +- 33 files changed, 330 insertions(+), 375 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4b0f4dcf..f6a02c4f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,6 @@ jobs: fail-fast: false matrix: os: - - ubuntu-18.04 - ubuntu-20.04 include: - os: ubuntu-22.04 diff --git a/libgstc/python/pygstc/gstc.py b/libgstc/python/pygstc/gstc.py index d7df0774..b5cce7c5 100644 --- a/libgstc/python/pygstc/gstc.py +++ b/libgstc/python/pygstc/gstc.py @@ -30,6 +30,7 @@ # (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 inspect import json import traceback @@ -167,7 +168,6 @@ def __init__( self._ip, self._port)) self._ipc = Ipc(self._logger, self._ip, self._port) self._timeout = timeout - self.ping_gstd() def _check_parameters(self, parameter_list, type_list): """ @@ -208,7 +208,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. @@ -231,7 +231,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( @@ -255,7 +255,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 @@ -269,7 +269,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 @@ -295,7 +295,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. @@ -319,9 +319,9 @@ def bus_filter(self, pipe_name, filter): 'Setting bus read filter of pipeline {} to {}'.format( 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. @@ -345,10 +345,10 @@ def bus_read(self, pipe_name): self._logger.info('Reading bus of pipeline {}'.format(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 @@ -371,9 +371,9 @@ def bus_timeout(self, pipe_name, timeout): 'Setting bus read timeout of pipeline {} to {}'.format( 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, @@ -404,9 +404,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. @@ -425,9 +425,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. @@ -446,9 +446,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. @@ -467,9 +467,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). @@ -498,9 +498,9 @@ def debug_threshold(self, threshold): self._logger.info( 'Setting GStreamer debug threshold to {}'.format(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. @@ -521,9 +521,9 @@ def delete(self, uri, name): self._logger.info('Deleting name {} at uri "{}"'.format(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, @@ -559,10 +559,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, @@ -596,9 +596,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. @@ -618,9 +618,9 @@ def event_eos(self, pipe_name): self._logger.info( 'Sending end-of-stream event to pipeline {}'.format(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. @@ -640,9 +640,9 @@ def event_flush_start(self, pipe_name): self._logger.info( 'Putting pipeline {} in flushing mode'.format(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. @@ -664,9 +664,9 @@ def event_flush_stop(self, pipe_name, reset=True): self._logger.info( 'Taking pipeline {} out of flushing mode'.format(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, @@ -715,9 +715,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. @@ -741,10 +741,10 @@ def list_elements(self, pipe_name): self._logger.info('Listing elements of pipeline {}'.format(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 @@ -762,10 +762,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. @@ -793,10 +793,10 @@ def list_properties(self, pipe_name, element): 'Listing properties of element {} from pipeline {}'.format( 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. @@ -824,10 +824,10 @@ def list_signals(self, pipe_name, element): 'Listing signals of element {} from pipeline {}'.format( 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. @@ -843,9 +843,9 @@ def pipeline_create(self, pipe_name, pipe_desc): 'Creating pipeline {} with description "{}"'.format( 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_create_ref(self, pipe_name, pipe_desc): + async def pipeline_create_ref(self, pipe_name, pipe_desc): """ Create a new pipeline based on the name and description using refcount. The refcount works similarly to GObject references. If the command @@ -864,9 +864,9 @@ def pipeline_create_ref(self, pipe_name, pipe_desc): 'Creating pipeline by reference {} with description "{}"'.format( pipe_name, pipe_desc)) parameters = self._check_parameters([pipe_name, pipe_desc], [str, str]) - self._send_cmd_line(['pipeline_create_ref'] + parameters) + await self._send_cmd_line(['pipeline_create_ref'] + parameters) - def pipeline_delete(self, pipe_name): + async def pipeline_delete(self, pipe_name): """ Delete the pipeline with the given name. @@ -885,9 +885,9 @@ def pipeline_delete(self, pipe_name): self._logger.info('Deleting pipeline {}'.format(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_delete_ref(self, pipe_name): + async def pipeline_delete_ref(self, pipe_name): """ Delete the pipeline with the given name using refcount. The refcount works similarly to GObject references. If the command @@ -910,9 +910,9 @@ def pipeline_delete_ref(self, pipe_name): self._logger.info( 'Deleting pipeline by reference {}'.format(pipe_name)) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_delete_ref'] + parameters) + await self._send_cmd_line(['pipeline_delete_ref'] + parameters) - def pipeline_pause(self, pipe_name): + async def pipeline_pause(self, pipe_name): """ Set the pipeline to paused. @@ -931,9 +931,9 @@ def pipeline_pause(self, pipe_name): self._logger.info('Pausing pipeline {}'.format(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. @@ -952,9 +952,9 @@ def pipeline_play(self, pipe_name): self._logger.info('Playing pipeline {}'.format(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_play_ref(self, pipe_name): + async def pipeline_play_ref(self, pipe_name): """ Set the pipeline to playing using refcount. The refcount works similarly to GObject references. If the command @@ -976,9 +976,9 @@ def pipeline_play_ref(self, pipe_name): self._logger.info('Playing pipeline by reference {}'.format(pipe_name)) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_play_ref'] + parameters) + await self._send_cmd_line(['pipeline_play_ref'] + parameters) - def pipeline_stop(self, pipe_name): + async def pipeline_stop(self, pipe_name): """ Set the pipeline to null. @@ -997,9 +997,9 @@ def pipeline_stop(self, pipe_name): self._logger.info('Stoping pipeline {}'.format(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_stop_ref(self, pipe_name): + async def pipeline_stop_ref(self, pipe_name): """ Set the pipeline to null using refcount. The refcount works similarly to GObject references. If the command @@ -1021,9 +1021,9 @@ def pipeline_stop_ref(self, pipe_name): self._logger.info('Stoping pipeline by reference {}'.format(pipe_name)) parameters = self._check_parameters([pipe_name], [str]) - self._send_cmd_line(['pipeline_stop_ref'] + parameters) + await self._send_cmd_line(['pipeline_stop_ref'] + parameters) - def pipeline_get_graph(self, pipe_name): + async def pipeline_get_graph(self, pipe_name): """ Get the pipeline graph. @@ -1047,10 +1047,10 @@ def pipeline_get_graph(self, pipe_name): self._logger.info('Getting the pipeline {} graph'.format(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 @@ -1074,9 +1074,9 @@ def pipeline_verbose(self, pipe_name, value): 'Setting the pipeline {} verbose mode to {}'.format( 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. @@ -1100,10 +1100,10 @@ def read(self, uri): self._logger.info('Reading uri {}'.format(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, @@ -1139,10 +1139,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, @@ -1173,9 +1173,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, @@ -1210,9 +1210,9 @@ def signal_timeout( timeout {}'.format(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 action_emit(self, pipe_name, element, action): + async def action_emit(self, pipe_name, element, action): """ Emits an action with no-parameters @@ -1238,9 +1238,9 @@ def action_emit(self, pipe_name, element, action): action, element, pipe_name)) parameters = self._check_parameters( [pipe_name, element, action], [str, str, str]) - self._send_cmd_line(['action_emit'] + parameters) + await self._send_cmd_line(['action_emit'] + parameters) - def update(self, uri, value): + async def update(self, uri, value): """ Update the resource at the given URI. @@ -1261,4 +1261,4 @@ def update(self, uri, value): self._logger.info('Updating uri {} with value "{}"'.format(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 7f79996b..9ca96f7f 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,87 +119,29 @@ def send(self, line, timeout=None): data : string Decoded JSON string with the response """ - data = None self._logger.debug('GSTD socket sending line: {}'.format(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 - + 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 - - # When a connection dies, the socket does not close properly and it - # returns immediately with an empty string. So, check that first. - if len(newbuf) == 0: - break - - 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 aee71c0f..737be6d5 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/python/gstd_runner.py b/tests/libgstc/python/gstd_runner.py index 87183303..229df448 100644 --- a/tests/libgstc/python/gstd_runner.py +++ b/tests/libgstc/python/gstd_runner.py @@ -29,15 +29,15 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED # OF THE POSSIBILITY OF SUCH DAMAGE. +import asyncio import pathlib import socket -import subprocess import unittest DEFAULT_TEAR_DOWN_TIMEOUT = 1 -class GstdTestRunner(unittest.TestCase): +class GstdTestRunner(unittest.IsolatedAsyncioTestCase): def get_open_port(self): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -48,24 +48,30 @@ def get_open_port(self): s.close() return port - def setUp(self): + async def asyncSetUp(self): self.port = self.get_open_port() self.gstd_path = (pathlib.Path(__file__).parent.parent.parent.parent .joinpath('gstd').joinpath('gstd').resolve()) - self.gstd = subprocess.Popen([self.gstd_path, '-p', str(self.port)]) - connected = -1 - while connected != 0: - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - connected = sock.connect_ex(("", self.port)) - sock.close() + self.gstd = await asyncio.create_subprocess_exec(self.gstd_path, '-p', str(self.port)) + asyncio.get_event_loop().call_later(5, self.gstd.kill) + connected = False + while not connected: + try: + reader, writer = await asyncio.open_connection(port=self.port) + writer.close() + await writer.wait_closed() + connected = True + except OSError: + pass - def tearDown(self): - self.gstd.terminate() - try: - self.gstd.wait(DEFAULT_TEAR_DOWN_TIMEOUT) - except subprocess.TimeoutExpired: - self.gstd.kill() - self.gstd.wait() + async def asyncTearDown(self): + if self.gstd.returncode is None: + self.gstd.terminate() + try: + await asyncio.wait_for(self.gstd.wait(), timeout=DEFAULT_TEAR_DOWN_TIMEOUT) + except asyncio.TimeoutError: + self.gstd.kill() + await self.gstd.wait() if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_bus_filter.py b/tests/libgstc/python/test_libgstc_python_bus_filter.py index 68dbdfba..acabe852 100755 --- a/tests/libgstc/python/test_libgstc_python_bus_filter.py +++ b/tests/libgstc/python/test_libgstc_python_bus_filter.py @@ -38,18 +38,18 @@ class TestGstcBusFilterMethods(GstdTestRunner): - 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(port=self.port, 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 2ee9f4a6..8c6dd696 100755 --- a/tests/libgstc/python/test_libgstc_python_bus_timeout.py +++ b/tests/libgstc/python/test_libgstc_python_bus_timeout.py @@ -38,32 +38,32 @@ class TestGstcBusTimeoutMethods(GstdTestRunner): - 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(port=self.port, 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') if ret: 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(port=self.port, 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 36c87b83..26af2057 100755 --- a/tests/libgstc/python/test_libgstc_python_create.py +++ b/tests/libgstc/python/test_libgstc_python_create.py @@ -38,24 +38,24 @@ class TestGstcCreateMethods(GstdTestRunner): - 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(port=self.port, 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(port=self.port, 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 f0c17803..2fa6ad47 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_color.py +++ b/tests/libgstc/python/test_libgstc_python_debug_color.py @@ -38,15 +38,15 @@ class TestGstcDebugColorMethods(GstdTestRunner): - 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(port=self.port, 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(port=self.port, 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 92f4725c..5be01ddf 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_enable.py +++ b/tests/libgstc/python/test_libgstc_python_debug_enable.py @@ -38,15 +38,15 @@ class TestGstcDebugEnableMethods(GstdTestRunner): - 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(port=self.port, 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(port=self.port, 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 db1abf64..14016c88 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_reset.py +++ b/tests/libgstc/python/test_libgstc_python_debug_reset.py @@ -38,15 +38,15 @@ class TestGstcDebugResetMethods(GstdTestRunner): - 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(port=self.port, 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(port=self.port, 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 e0a2c4bc..9dafa573 100755 --- a/tests/libgstc/python/test_libgstc_python_debug_threshold.py +++ b/tests/libgstc/python/test_libgstc_python_debug_threshold.py @@ -37,55 +37,55 @@ class TestGstcDebugThresholdMethods(GstdTestRunner): - 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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(port=self.port, 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 67ba4879..9a321e60 100755 --- a/tests/libgstc/python/test_libgstc_python_delete.py +++ b/tests/libgstc/python/test_libgstc_python_delete.py @@ -38,18 +38,18 @@ class TestGstcDeleteMethods(GstdTestRunner): - 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(port=self.port, 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 7457057f..54b5d8a8 100755 --- a/tests/libgstc/python/test_libgstc_python_element_get.py +++ b/tests/libgstc/python/test_libgstc_python_element_get.py @@ -38,18 +38,17 @@ class TestGstcElementGetMethods(GstdTestRunner): - 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(port=self.port, logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.assertIn( - 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', 'ball']) - self.gstd_client.pipeline_delete('p0') + 'pattern') + self.assertIn(ret, ['Moving ball', '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 4fb99ca1..2603ffef 100755 --- a/tests/libgstc/python/test_libgstc_python_element_set.py +++ b/tests/libgstc/python/test_libgstc_python_element_set.py @@ -38,21 +38,21 @@ class TestGstcElementSetMethods(GstdTestRunner): - 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(port=self.port, logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_create('p0', pipeline) self.assertIn( - self.gstd_client.element_get( + await self.gstd_client.element_get( 'p0', 'v0', 'pattern'), ['Moving ball', 'ball']) - self.gstd_client.element_set('p0', 'v0', 'pattern', 'bar') - self.assertIn(self.gstd_client.element_get('p0', 'v0', - 'pattern'), ['Bar', '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.assertIn(ret, ['Bar', '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 2fe79393..bda3624c 100755 --- a/tests/libgstc/python/test_libgstc_python_event_eos.py +++ b/tests/libgstc/python/test_libgstc_python_event_eos.py @@ -38,18 +38,18 @@ class TestGstcEventEosMethods(GstdTestRunner): - 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(port=self.port, 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 8e9e66a6..a459e412 100755 --- a/tests/libgstc/python/test_libgstc_python_event_flush_start.py +++ b/tests/libgstc/python/test_libgstc_python_event_flush_start.py @@ -38,16 +38,16 @@ class TestGstcEventFlushStartMethods(GstdTestRunner): - 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(port=self.port, 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 89505e64..e0db1e8b 100755 --- a/tests/libgstc/python/test_libgstc_python_event_seek.py +++ b/tests/libgstc/python/test_libgstc_python_event_seek.py @@ -38,15 +38,15 @@ class TestGstcEventSeekMethods(GstdTestRunner): - 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(port=self.port, 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 edd9613b..42859163 100755 --- a/tests/libgstc/python/test_libgstc_python_list_elements.py +++ b/tests/libgstc/python/test_libgstc_python_list_elements.py @@ -38,14 +38,14 @@ class TestGstcListElementsMethods(GstdTestRunner): - 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(port=self.port, 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 47cd7c12..df9ddd0e 100755 --- a/tests/libgstc/python/test_libgstc_python_list_pipelines.py +++ b/tests/libgstc/python/test_libgstc_python_list_pipelines.py @@ -38,15 +38,15 @@ class TestGstcListPipelinesMethods(GstdTestRunner): - 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(port=self.port, 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 52888044..de2cb772 100755 --- a/tests/libgstc/python/test_libgstc_python_list_properties.py +++ b/tests/libgstc/python/test_libgstc_python_list_properties.py @@ -38,7 +38,7 @@ class TestGstcListPropertiesMethods(GstdTestRunner): - 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') @@ -63,10 +63,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 1676920c..9d341a43 100755 --- a/tests/libgstc/python/test_libgstc_python_list_signals.py +++ b/tests/libgstc/python/test_libgstc_python_list_signals.py @@ -38,15 +38,15 @@ class TestGstcListSignalsMethods(GstdTestRunner): - 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(port=self.port, logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.assertTrue({'name': 'handoff'} in - self.gstd_client.list_signals('p0', 'i0')) - self.gstd_client.pipeline_delete('p0') + await self.gstd_client.pipeline_create('p0', pipeline) + ret = await self.gstd_client.list_signals('p0', 'i0') + self.assertTrue({'name': 'handoff'} in ret) + 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 76ece076..e90d482a 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_create.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_create.py @@ -38,14 +38,14 @@ class TestGstcPipelineCreateMethods(GstdTestRunner): - 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(port=self.port, 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 c65c10d0..d553f041 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_delete.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_delete.py @@ -38,15 +38,15 @@ class TestGstcPipelineDeleteMethods(GstdTestRunner): - 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(port=self.port, 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 a1cb16e3..610b8315 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_pause.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_pause.py @@ -29,7 +29,7 @@ # 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 gstd_runner import GstdTestRunner @@ -42,22 +42,22 @@ class TestGstcPipelinePauseMethods(GstdTestRunner): - 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(port=self.port, logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.pipeline_pause('p0') - state = self.gstd_client.read('pipelines/p0/state')['value'] + await self.gstd_client.pipeline_create('p0', pipeline) + await self.gstd_client.pipeline_play('p0') + await self.gstd_client.pipeline_pause('p0') + state = await self.gstd_client.read('pipelines/p0/state') retry = DEFAULT_STATE_READ_RETRIES - while (retry and state in RUN_STATES): - time.sleep(DEFAULT_TIME_BETWEEN_RETRIES) - state = self.gstd_client.read('pipelines/p0/state')['value'] + while (retry and state['value'] in RUN_STATES): + asyncio.sleep(DEFAULT_TIME_BETWEEN_RETRIES) + state = await self.gstd_client.read('pipelines/p0/state') retry -= 1 - self.assertIn(self.gstd_client.read( - 'pipelines/p0/state')['value'], ['PAUSED', 'paused']) - self.gstd_client.pipeline_delete('p0') + state = await self.gstd_client.read('pipelines/p0/state') + self.assertIn(state['value'], ['PAUSED', '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 1e245d83..8e091e6a 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_play.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_play.py @@ -29,7 +29,7 @@ # 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 gstd_runner import GstdTestRunner @@ -39,17 +39,17 @@ class TestGstcPipelinePlayMethods(GstdTestRunner): - 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(port=self.port, 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', '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', '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 fb6733e5..a56a533a 100755 --- a/tests/libgstc/python/test_libgstc_python_pipeline_stop.py +++ b/tests/libgstc/python/test_libgstc_python_pipeline_stop.py @@ -38,16 +38,16 @@ class TestGstcPipelineStopMethods(GstdTestRunner): - 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(port=self.port, logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - self.gstd_client.pipeline_play('p0') - self.gstd_client.pipeline_stop('p0') - self.assertIn(self.gstd_client.read( - 'pipelines/p0/state')['value'], ['NULL', '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.assertIn(ret['value'], ['NULL', '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 5ae22b9a..2057d201 100755 --- a/tests/libgstc/python/test_libgstc_python_read.py +++ b/tests/libgstc/python/test_libgstc_python_read.py @@ -38,16 +38,16 @@ class TestGstcReadMethods(GstdTestRunner): - 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(port=self.port, 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.assertIn(ret['value'], ['Moving ball', '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 276156c3..75cb82a4 100755 --- a/tests/libgstc/python/test_libgstc_python_signal_connect.py +++ b/tests/libgstc/python/test_libgstc_python_signal_connect.py @@ -38,18 +38,18 @@ class TestGstcSignalConnectMethods(GstdTestRunner): - 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(port=self.port, 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 7abc41a3..05a627cf 100755 --- a/tests/libgstc/python/test_libgstc_python_signal_disconnect.py +++ b/tests/libgstc/python/test_libgstc_python_signal_disconnect.py @@ -29,41 +29,34 @@ # 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 gstd_runner import GstdTestRunner from pygstc.gstc import * from pygstc.logger import * -import time -import os -ret_val = '' - -def signal_connect_test(port): - global ret_val +async def signal_connect_test(port): gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') gstd_client = GstdClient(port=port, logger=gstd_logger) - ret_val = gstd_client.signal_connect('p0', 'identity', 'handoff') + return await gstd_client.signal_connect('p0', 'identity', 'handoff') class TestGstcSignalDisconnectMethods(GstdTestRunner): - def test_libgstc_python_signal_disconnect(self): - global ret_val + async def test_libgstc_python_signal_disconnect(self): pipeline = 'videotestsrc ! identity name=identity ! fakesink' self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG') self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger) - self.gstd_client.pipeline_create('p0', pipeline) - ret_thr = threading.Thread(target=signal_connect_test, args=(self.port,)) - 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) + connect_task = asyncio.create_task(signal_connect_test(self.port)) + await asyncio.sleep(0.1) + await self.gstd_client.signal_disconnect('p0', 'identity', 'handoff') + ret_val = await connect_task 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 297ee336..824e20ac 100755 --- a/tests/libgstc/python/test_libgstc_python_signal_timeout.py +++ b/tests/libgstc/python/test_libgstc_python_signal_timeout.py @@ -30,7 +30,6 @@ # OF THE POSSIBILITY OF SUCH DAMAGE. import unittest -import threading from gstd_runner import GstdTestRunner from pygstc.gstc import * @@ -39,17 +38,17 @@ class TestGstcSignalTimeoutMethods(GstdTestRunner): - 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(port=self.port, 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_stop_gstd.py b/tests/libgstc/python/test_libgstc_python_stop_gstd.py index b3cfc06f..e8e7bd10 100755 --- a/tests/libgstc/python/test_libgstc_python_stop_gstd.py +++ b/tests/libgstc/python/test_libgstc_python_stop_gstd.py @@ -29,16 +29,17 @@ # 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 subprocess from gstd_runner import GstdTestRunner class TestGstcStopGstdMethods(GstdTestRunner): - def test_libgstc_python_stop_gstd(self): - subprocess.Popen([self.gstd_path, '-k']) + async def test_libgstc_python_stop_gstd(self): + gstd_k = await asyncio.create_subprocess_exec(self.gstd_path, '-k') + await gstd_k.wait() if __name__ == '__main__': diff --git a/tests/libgstc/python/test_libgstc_python_update.py b/tests/libgstc/python/test_libgstc_python_update.py index 7d0821ad..c7980caf 100755 --- a/tests/libgstc/python/test_libgstc_python_update.py +++ b/tests/libgstc/python/test_libgstc_python_update.py @@ -38,18 +38,18 @@ class TestGstcUpdateMethods(GstdTestRunner): - 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(port=self.port, 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.assertIn(ret['value'], ['Moving ball', '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__':