From 642e258ecbb59612257bbe2c62f45e0acd3d48fd Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 1 Feb 2023 11:36:17 +1000 Subject: [PATCH] Format python files with black And set up a gitlab ci job to check that --- .gitlab-ci.yml | 10 +++++++++ .gitlab-ci/ci.template | 10 +++++++++ test/templates/remotedesktop.py | 36 +++++++++++++++++++-------------- test/test_oeffis.py | 1 + 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 79f1f03..3cbccfc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -130,6 +130,16 @@ check-merge-request: junit: results.xml allow_failure: true +# Format anything python with python-black +# +python-black: + image: golang:alpine + stage: prep + before_script: + - apk add python3 py-pip black + script: + - black --check --diff . + # # Build distribution-specific images used by the jobs in the build stage # diff --git a/.gitlab-ci/ci.template b/.gitlab-ci/ci.template index 1726921..2ba07ab 100644 --- a/.gitlab-ci/ci.template +++ b/.gitlab-ci/ci.template @@ -138,6 +138,16 @@ check-merge-request: junit: results.xml allow_failure: true +# Format anything python with python-black +# +python-black: + image: golang:alpine + stage: prep + before_script: + - apk add python3 py-pip black + script: + - black --check --diff . + # # Build distribution-specific images used by the jobs in the build stage # diff --git a/test/templates/remotedesktop.py b/test/templates/remotedesktop.py index 912cad5..29a6a9c 100644 --- a/test/templates/remotedesktop.py +++ b/test/templates/remotedesktop.py @@ -104,16 +104,18 @@ def SelectDevices(self, session_handle, options, sender): try: session = params.sessions[session_handle] if session.state != RDSession.State.CREATED: - raise dbus.exceptions.DBusException(f"Session in state {session.state}, expected CREATED", - name="org.freedesktop.DBus.Error.AccessDenied") + raise dbus.exceptions.DBusException( + f"Session in state {session.state}, expected CREATED", + name="org.freedesktop.DBus.Error.AccessDenied", + ) else: resp = params.response if resp == 0: session.advance_state() except KeyError: raise dbus.exceptions.DBusException( - "Invalid session", - name="org.freedesktop.DBus.Error.AccessDenied") + "Invalid session", name="org.freedesktop.DBus.Error.AccessDenied" + ) response = Response(resp, {}) request.respond(response, delay=params.delay) @@ -122,7 +124,7 @@ def SelectDevices(self, session_handle, options, sender): except Exception as e: logger.critical(e) if isinstance(e, dbus.exceptions.DBusException): - raise e + raise e @dbus.service.method( @@ -144,16 +146,18 @@ def Start(self, session_handle, parent_window, options, sender): try: session = params.sessions[session_handle] if session.state != RDSession.State.SELECTED: - raise dbus.exceptions.DBusException(f"Session in state {session.state}, expected SELECTED", - name="org.freedesktop.DBus.Error.AccessDenied") + raise dbus.exceptions.DBusException( + f"Session in state {session.state}, expected SELECTED", + name="org.freedesktop.DBus.Error.AccessDenied", + ) else: resp = params.response if resp == 0: session.advance_state() except KeyError: raise dbus.exceptions.DBusException( - "Invalid session", - name="org.freedesktop.DBus.Error.AccessDenied") + "Invalid session", name="org.freedesktop.DBus.Error.AccessDenied" + ) response = Response(resp, results) request.respond(response, delay=params.delay) @@ -162,7 +166,7 @@ def Start(self, session_handle, parent_window, options, sender): except Exception as e: logger.critical(e) if isinstance(e, dbus.exceptions.DBusException): - raise e + raise e @dbus.service.method( @@ -313,12 +317,14 @@ def ConnectToEIS(self, session_handle, options): session = params.sessions[session_handle] if session.state != RDSession.State.STARTED: logger.error(f"Session in state {session.state}, expected STARTED") - raise dbus.exceptions.DBusException("Session must be started before ConnectToEIS", - name="org.freedesktop.DBus.Error.AccesDenied") + raise dbus.exceptions.DBusException( + "Session must be started before ConnectToEIS", + name="org.freedesktop.DBus.Error.AccesDenied", + ) except KeyError: raise dbus.exceptions.DBusException( - "Invalid session", - name="org.freedesktop.DBus.Error.AccessDenied") + "Invalid session", name="org.freedesktop.DBus.Error.AccessDenied" + ) import socket @@ -333,4 +339,4 @@ def ConnectToEIS(self, session_handle, options): except Exception as e: logger.critical(e) if isinstance(e, dbus.exceptions.DBusException): - raise e + raise e diff --git a/test/test_oeffis.py b/test/test_oeffis.py index 6a0ca9d..b69e028 100644 --- a/test/test_oeffis.py +++ b/test/test_oeffis.py @@ -290,6 +290,7 @@ class TestOeffis(dbusmock.DBusTestCase): """ Test class that sets up a mocked DBus session bus to be used by liboeffis.so. """ + @classmethod def setUpClass(cls): cls.PORTAL_NAME = "RemoteDesktop"