From 8da785e990c8f94e083f433646f47e0221459632 Mon Sep 17 00:00:00 2001 From: Gabriel Tanase Date: Sat, 21 Dec 2019 19:10:28 +0000 Subject: [PATCH] Reformat code --- .gitignore | 3 + hooks/build | 9 ++- requirements.txt | 2 +- resolver.py | 1 + sense_wrappers/joystick.py | 4 +- sense_wrappers/led_matrix.py | 6 +- sense_wrappers/sensors.py | 6 +- senseapi.py | 2 + specification.yml | 78 +++++++++---------- .../test_led_matrix.tavern.yml | 50 ++++++------ tests/test_senseapi.py | 3 +- 11 files changed, 88 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 894a44c..ff8ef67 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,6 @@ venv.bak/ # mypy .mypy_cache/ + +# PyCharm +.idea/ \ No newline at end of file diff --git a/hooks/build b/hooks/build index 47f8241..f514663 100755 --- a/hooks/build +++ b/hooks/build @@ -1,7 +1,8 @@ #!/bin/bash echo "[***] Build hook running" -docker build --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ - --build-arg VCS_REF=`git rev-parse --short HEAD` \ - --cache-from $IMAGE_NAME \ - -t $IMAGE_NAME . + +docker build --build-arg "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ + --build-arg VCS_REF="$(git rev-parse --short HEAD)" \ + --cache-from "$IMAGE_NAME" \ + -t "$IMAGE_NAME" . diff --git a/requirements.txt b/requirements.txt index 0ee7554..4b6182f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -41,7 +41,7 @@ six==1.12.0 stevedore==1.31.0 swagger-ui-bundle==0.0.5 tavern==0.30.3 -urllib3==1.25.3 +urllib3==1.25.7 wcwidth==0.1.7 Werkzeug==0.15.6 zipp==0.6.0 diff --git a/resolver.py b/resolver.py index 888795b..586d226 100755 --- a/resolver.py +++ b/resolver.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import sys + from sense_wrappers import sensors, led_matrix, joystick if "emulation" in sys.argv: diff --git a/sense_wrappers/joystick.py b/sense_wrappers/joystick.py index 02f647e..debf5fa 100755 --- a/sense_wrappers/joystick.py +++ b/sense_wrappers/joystick.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 + class Joystick(object): def __init__(self, sense): self.__sense = sense @@ -8,5 +9,6 @@ def get_events(self): events = self.__sense.stick.get_events()[:1000] return [self.__event_dict(event) for event in events] - def __event_dict(self, event): + @staticmethod + def __event_dict(event): return dict(event._asdict()) diff --git a/sense_wrappers/led_matrix.py b/sense_wrappers/led_matrix.py index 3eaef66..63603eb 100755 --- a/sense_wrappers/led_matrix.py +++ b/sense_wrappers/led_matrix.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 + class LedMatrix(object): def __init__(self, sense): self.__sense = sense @@ -40,7 +41,7 @@ def show_letter(self, body): self.__sense.show_letter( body["letter"], body.get("text_colour", [255, 255, 255]), - body.get("back_colour", [0,0,0]) + body.get("back_colour", [0, 0, 0]) ) def show_message(self, body): @@ -48,6 +49,5 @@ def show_message(self, body): body["message"], body.get("scroll_speed", 0.1), body.get("text_colour", [255, 255, 255]), - body.get("back_colour", [0,0,0]) + body.get("back_colour", [0, 0, 0]) ) - diff --git a/sense_wrappers/sensors.py b/sense_wrappers/sensors.py index 4fb0d8f..e69c488 100755 --- a/sense_wrappers/sensors.py +++ b/sense_wrappers/sensors.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 + class Sensors(object): def __init__(self, sense): self.__sense = sense @@ -43,9 +44,10 @@ def accelerometer(self): def get(self, name): return getattr(self, name)() - def __u_v_dict(self, u, v): + @staticmethod + def __u_v_dict(u, v): if isinstance(v, int): v = float(v) elif isinstance(v, dict): - v = { key:float(value) for key,value in v.items() } + v = {key: float(value) for key, value in v.items()} return {"unit": u, "value": v} diff --git a/senseapi.py b/senseapi.py index a170a3d..de6f3b1 100755 --- a/senseapi.py +++ b/senseapi.py @@ -5,9 +5,11 @@ application = connexion.App(__name__, specification_dir='./') application.add_api('specification.yml') + @application.route('/') def home(): return redirect('senseapi/v1/ui/') + if __name__ == '__main__': application.run(host='0.0.0.0') diff --git a/specification.yml b/specification.yml index 21e6857..3dbd538 100755 --- a/specification.yml +++ b/specification.yml @@ -8,22 +8,22 @@ info: email: tanase.gabriel91@gmail.com servers: -- url: /senseapi/v1 + - url: /senseapi/v1 paths: /sensors/{name}: get: operationId: resolver.sensors.get tags: - - Sensors + - Sensors summary: Individual sensor values parameters: - - name: name - in: path - description: Name of the sensor - required: true - schema: - $ref: '#/components/schemas/sensor' + - name: name + in: path + description: Name of the sensor + required: true + schema: + $ref: '#/components/schemas/sensor' responses: 200: description: OK @@ -34,7 +34,7 @@ paths: get: operationId: resolver.led.get_settings tags: - - LED Matrix + - LED Matrix summary: Get the customizable settings responses: 200: @@ -42,7 +42,7 @@ paths: post: operationId: resolver.led.update_settings tags: - - LED Matrix + - LED Matrix summary: Update settings requestBody: content: @@ -63,21 +63,21 @@ paths: get: operationId: resolver.led.get_pixel tags: - - LED Matrix + - LED Matrix summary: Get the colour of a specific pixel parameters: - - name: x - in: query - description: Position of the pixel on the X xis - required: true - schema: - $ref: '#/components/schemas/pixel_position' - - name: y - in: query - description: Position of the pixel on the Y xis - required: true - schema: - $ref: '#/components/schemas/pixel_position' + - name: x + in: query + description: Position of the pixel on the X xis + required: true + schema: + $ref: '#/components/schemas/pixel_position' + - name: y + in: query + description: Position of the pixel on the Y xis + required: true + schema: + $ref: '#/components/schemas/pixel_position' responses: 200: description: OK @@ -86,7 +86,7 @@ paths: post: operationId: resolver.led.update_pixel tags: - - LED Matrix + - LED Matrix summary: Update the colour of a specific pixel requestBody: content: @@ -108,7 +108,7 @@ paths: get: operationId: resolver.led.get_pixels tags: - - LED Matrix + - LED Matrix summary: Get the colour of all pixels responses: 200: @@ -116,7 +116,7 @@ paths: post: operationId: resolver.led.update_pixels tags: - - LED Matrix + - LED Matrix summary: Update the colour of all pixels requestBody: content: @@ -124,14 +124,14 @@ paths: schema: $ref: '#/components/schemas/pixels' example: [ - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], - [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], + [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], [0,255,0], [0,0,255], ] responses: 200: @@ -141,7 +141,7 @@ paths: post: operationId: resolver.led.clear tags: - - LED Matrix + - LED Matrix summary: Clear the pixels requestBody: content: @@ -160,7 +160,7 @@ paths: post: operationId: resolver.led.flip tags: - - LED Matrix + - LED Matrix summary: Flip the pixels horizontally or vertically requestBody: content: @@ -176,7 +176,7 @@ paths: post: operationId: resolver.led.show_letter tags: - - LED Matrix + - LED Matrix summary: Display one letter requestBody: content: @@ -196,7 +196,7 @@ paths: post: operationId: resolver.led.show_message tags: - - LED Matrix + - LED Matrix summary: Scroll a text message requestBody: content: @@ -216,7 +216,7 @@ paths: get: operationId: resolver.joystick.get_events tags: - - Joystick + - Joystick summary: Get joystick events since last call (max 1000) responses: 200: diff --git a/tests/tavern_senseapi_v1/test_led_matrix.tavern.yml b/tests/tavern_senseapi_v1/test_led_matrix.tavern.yml index 61ba75e..24756c5 100644 --- a/tests/tavern_senseapi_v1/test_led_matrix.tavern.yml +++ b/tests/tavern_senseapi_v1/test_led_matrix.tavern.yml @@ -201,14 +201,14 @@ stages: response: status_code: 200 body: [ - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], ] @@ -219,14 +219,14 @@ stages: url: http://127.0.0.1:8000/senseapi/v1/led/pixels method: POST json: [ - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], - [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], + [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], ] response: status_code: 200 @@ -236,14 +236,14 @@ stages: url: http://127.0.0.1:8000/senseapi/v1/led/pixels method: POST json: [ - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], - [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], + [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], [256,256,256], ] response: status_code: 400 @@ -452,7 +452,7 @@ stages: - 128 - 128 - 128 - message: TEST + message: TEST scroll_speed: 0.05 response: status_code: 200 diff --git a/tests/test_senseapi.py b/tests/test_senseapi.py index 7c69f6d..10e7388 100755 --- a/tests/test_senseapi.py +++ b/tests/test_senseapi.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 import atexit -import pytest import subprocess +import pytest + sense_emulator = subprocess.Popen(["sense_play", "tests/sense_fixture.hat"]) atexit.register(sense_emulator.terminate)