From 41e1a0a3686ab46b66af3ce6f9ccdf8857cdd20c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:29:34 +0000 Subject: [PATCH] style: format code with Autopep8 This commit fixes the style issues introduced in 861ab62 according to the output from Autopep8. Details: None --- server.py | 14 ++++++++------ tests/test_unittest.py | 43 ++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/server.py b/server.py index 636df5f..babd708 100644 --- a/server.py +++ b/server.py @@ -10,7 +10,6 @@ states = {} - @app.route('/set//') def set(pin, state): if pin not in pins: @@ -22,10 +21,11 @@ def set(pin, state): states[pin] = state return "pin "+str(pin)+" changed to "+str(states[pin]) + @app.get('/setAll/') def setAll(state): - if state not in (1,0): - abort(code=404, text= "invalid state "+str(state)) + if state not in (1, 0): + abort(code=404, text="invalid state "+str(state)) gpio.output(pins, state) for pin in states: states[pin] = state @@ -64,7 +64,9 @@ def switch(pin): def index(): return static_file("index.html", root="static") -#create control route on /control +# create control route on /control + + @app.get('/control') def control(): return static_file("control.html", root="static") @@ -77,11 +79,11 @@ def control(): for pin in pins: states[pin] = defaultState - #setting up the pins + # setting up the pins gpio.setmode(gpio.BOARD) gpio.setup(pins, gpio.OUT, initial=defaultState) - #main server + # main server run(app, server='paste', host='0', port=3000) finally: diff --git a/tests/test_unittest.py b/tests/test_unittest.py index f254713..eae6991 100644 --- a/tests/test_unittest.py +++ b/tests/test_unittest.py @@ -1,13 +1,12 @@ import unittest import http.client + class Test_TestAPI(unittest.TestCase): @classmethod def setUpClass(self): self.conn = http.client.HTTPConnection("localhost:3000") - - def test_connexion(self): self.conn.request("GET", "/") @@ -19,64 +18,58 @@ def test_control(self): res = self.conn.getresponse() self.assertEqual(res.status, 200) - def test_setWrongPin(self): - self.conn.request("GET","/set/14/0") + self.conn.request("GET", "/set/14/0") res = self.conn.getresponse() - self.assertEqual(res.status,404) + self.assertEqual(res.status, 404) def test_setWrongState(self): - self.conn.request("GET","/set/11/2") + self.conn.request("GET", "/set/11/2") res = self.conn.getresponse() - self.assertEqual(res.status,400) + self.assertEqual(res.status, 400) def test_set(self): - self.conn.request("GET","/set/11/1") + self.conn.request("GET", "/set/11/1") res = self.conn.getresponse() - self.assertEqual(res.status,200) + self.assertEqual(res.status, 200) - self.conn.request("GET","/set/11/0") + self.conn.request("GET", "/set/11/0") res = self.conn.getresponse() - self.assertEqual(res.status,200) - - + self.assertEqual(res.status, 200) def test_pins(self): self.conn.request("GET", "/pins") res = self.conn.getresponse() - self.assertEqual(res.status,200) - - + self.assertEqual(res.status, 200) def test_getAll(self): self.conn.request("GET", "/get") res = self.conn.getresponse() - self.assertEqual(res.status,200) + self.assertEqual(res.status, 200) def test_getWrongPin(self): self.conn.request("GET", "/get/14") res = self.conn.getresponse() - self.assertEqual(res.status,404) + self.assertEqual(res.status, 404) def test_getPin(self): self.conn.request("GET", "/get/11") res = self.conn.getresponse() - self.assertEqual(res.status,200) - - + self.assertEqual(res.status, 200) def test_switchWrongPin(self): self.conn.request("GET", "/switch/14") res = self.conn.getresponse() - self.assertEqual(res.status,404) + self.assertEqual(res.status, 404) def test_switch(self): self.conn.request("GET", "/switch/11") res = self.conn.getresponse() - self.assertEqual(res.status,200) + self.assertEqual(res.status, 200) self.conn.request("GET", "/switch/11") res = self.conn.getresponse() - self.assertEqual(res.status,200) + self.assertEqual(res.status, 200) + if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()