Skip to content

Commit 818f79f

Browse files
committed
refactor: simplify serial test functions by removing unused parameters
1 parent bae632a commit 818f79f

File tree

1 file changed

+19
-74
lines changed

1 file changed

+19
-74
lines changed

β€Žtests/test_ws.py

+19-74
Original file line numberDiff line numberDiff line change
@@ -49,77 +49,28 @@ def test_list(socketio, message):
4949
running_on_ci(),
5050
reason="VMs have no serial ports",
5151
)
52-
def test_open_serial_default(socketio, serial_port, baudrate, message):
53-
general_open_serial(socketio, serial_port, baudrate, message, "default")
54-
55-
56-
@pytest.mark.skipif(
57-
running_on_ci(),
58-
reason="VMs have no serial ports",
59-
)
60-
def test_open_serial_timed(socketio, serial_port, baudrate, message):
61-
general_open_serial(socketio, serial_port, baudrate, message, "timed")
62-
63-
64-
@pytest.mark.skipif(
65-
running_on_ci(),
66-
reason="VMs have no serial ports",
67-
)
68-
def test_open_serial_timedraw(socketio, serial_port, baudrate, message):
69-
general_open_serial(socketio, serial_port, baudrate, message, "timedraw")
70-
52+
def test_open_serial(socketio, serial_port, baudrate, message):
53+
general_open_serial(socketio, serial_port, baudrate, message)
7154

7255
# NOTE run the following tests with a board connected to the PC and with the sketch found in tests/testdata/SerialEcho.ino on it be sure to change serial_address in conftest.py
7356
@pytest.mark.skipif(
7457
running_on_ci(),
7558
reason="VMs have no serial ports",
7659
)
77-
def test_send_serial_default(socketio, close_port, serial_port, baudrate, message):
78-
general_send_serial(socketio, close_port, serial_port, baudrate, message, "default")
79-
80-
81-
@pytest.mark.skipif(
82-
running_on_ci(),
83-
reason="VMs have no serial ports",
84-
)
85-
def test_send_serial_timed(socketio, close_port, serial_port, baudrate, message):
86-
general_send_serial(socketio, close_port, serial_port, baudrate, message, "timed")
60+
def test_send_serial(socketio, close_port, serial_port, baudrate, message):
61+
general_send_serial(socketio, close_port, serial_port, baudrate, message)
8762

8863

8964
@pytest.mark.skipif(
9065
running_on_ci(),
9166
reason="VMs have no serial ports",
9267
)
93-
def test_send_serial_timedraw(socketio, close_port, serial_port, baudrate, message):
94-
general_send_serial(socketio, close_port, serial_port, baudrate, message, "timedraw")
68+
def test_send_emoji_serial(socketio, close_port, serial_port, baudrate, message):
69+
general_send_emoji_serial(socketio, close_port, serial_port, baudrate, message)
9570

9671

97-
@pytest.mark.skipif(
98-
running_on_ci(),
99-
reason="VMs have no serial ports",
100-
)
101-
def test_send_emoji_serial_default(socketio, close_port, serial_port, baudrate, message):
102-
general_send_emoji_serial(socketio, close_port, serial_port, baudrate, message, "default")
103-
104-
105-
@pytest.mark.skipif(
106-
running_on_ci(),
107-
reason="VMs have no serial ports",
108-
)
109-
def test_send_emoji_serial_timed(socketio, close_port, serial_port, baudrate, message):
110-
general_send_emoji_serial(socketio, close_port, serial_port, baudrate, message, "timed")
111-
112-
113-
@pytest.mark.skipif(
114-
running_on_ci(),
115-
reason="VMs have no serial ports",
116-
)
117-
def test_send_emoji_serial_timedraw(socketio, close_port, serial_port, baudrate, message):
118-
general_send_emoji_serial(socketio, close_port, serial_port, baudrate, message, "timedraw")
119-
120-
121-
def general_open_serial(socketio, serial_port, baudrate, message, buffertype):
122-
open_serial_port(socketio, serial_port, baudrate, message, buffertype)
72+
def general_open_serial(socketio, serial_port, baudrate, message):
73+
open_serial_port(socketio, serial_port, baudrate, message)
12374
# test the closing of the serial port, we are gonna use close_port for the other tests
12475
socketio.emit('command', 'close ' + serial_port)
12576
time.sleep(.2)
@@ -128,42 +79,36 @@ def general_open_serial(socketio, serial_port, baudrate, message, buffertype):
12879
assert any("\"IsOpen\": false," in i for i in message)
12980

13081

131-
def general_send_serial(socketio, close_port, serial_port, baudrate, message, buffertype):
132-
open_serial_port(socketio, serial_port, baudrate, message, buffertype)
82+
def general_send_serial(socketio, close_port, serial_port, baudrate, message):
83+
open_serial_port(socketio, serial_port, baudrate, message)
13384
# send the string "ciao" using the serial connection
13485
socketio.emit('command', 'send ' + serial_port + ' ciao')
13586
time.sleep(1)
13687
print(message)
13788
# check if the send command has been registered
13889
assert any("send " + serial_port + " ciao" in i for i in message)
13990
#check if message has been sent back by the connected board
140-
if buffertype == "timedraw":
141-
output = decode_output(extract_serial_data(message))
142-
elif buffertype in ("default", "timed"):
143-
output = extract_serial_data(message)
91+
output = extract_serial_data(message)
14492
assert "ciao" in output
14593
# the serial connection is closed by close_port() fixture: even if in case of test failure
14694

14795

148-
def general_send_emoji_serial(socketio, close_port, serial_port, baudrate, message, buffertype):
149-
open_serial_port(socketio, serial_port, baudrate, message, buffertype)
96+
def general_send_emoji_serial(socketio, close_port, serial_port, baudrate, message):
97+
open_serial_port(socketio, serial_port, baudrate, message)
15098
# send a lot of emoji: they can be messed up
15199
socketio.emit('command', 'send ' + serial_port + ' /"πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€/"')
152100
time.sleep(1)
153101
print(message)
154102
# check if the send command has been registered
155103
assert any("send " + serial_port + " /\"πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€/\"" in i for i in message)
156-
if buffertype == "timedraw":
157-
output = decode_output(extract_serial_data(message))
158-
elif buffertype in ("default", "timed"):
159-
output = extract_serial_data(message)
104+
output = extract_serial_data(message)
160105
assert "/\"πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€πŸ§€/\"" in output
161106
# the serial connection is closed by close_port() fixture: even if in case of test failure
162107

163108

164-
def open_serial_port(socketio, serial_port, baudrate, message, buffertype):
165-
#open a new serial connection with the specified buffertype
166-
socketio.emit('command', 'open ' + serial_port + ' ' + baudrate + ' ' + buffertype)
109+
def open_serial_port(socketio, serial_port, baudrate, message):
110+
#open a new serial connection
111+
socketio.emit('command', 'open ' + serial_port + ' ' + baudrate)
167112
# give time to the message var to be filled
168113
time.sleep(.5)
169114
print(message)
@@ -176,7 +121,7 @@ def open_serial_port(socketio, serial_port, baudrate, message, buffertype):
176121
reason="VMs have no serial ports",
177122
)
178123
def test_sendraw_serial(socketio, close_port, serial_port, baudrate, message):
179-
open_serial_port(socketio, serial_port, baudrate, message, "timedraw")
124+
open_serial_port(socketio, serial_port, baudrate, message)
180125
#test with bytes
181126
integers = [1, 2, 3, 4, 5]
182127
bytes_array=bytearray(integers)
@@ -202,7 +147,7 @@ def extract_serial_data(msg):
202147
serial_data+=json.loads(i)["D"]
203148
print("serialdata:"+serial_data)
204149
return serial_data
205-
150+
206151
def decode_output(raw_output):
207152
# print(raw_output)
208153
base64_bytes = raw_output.encode('ascii') #encode rawoutput message into a bytes-like object

0 commit comments

Comments
Β (0)