Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit818f79f

Browse files
committed
refactor: simplify serial test functions by removing unused parameters
1 parentbae632a commit818f79f

File tree

1 file changed

+19
-74
lines changed

1 file changed

+19
-74
lines changed

‎tests/test_ws.py‎

Lines changed: 19 additions & 74 deletions
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-
deftest_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-
deftest_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-
deftest_open_serial_timedraw(socketio,serial_port,baudrate,message):
69-
general_open_serial(socketio,serial_port,baudrate,message,"timedraw")
70-
52+
deftest_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-
deftest_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-
deftest_send_serial_timed(socketio,close_port,serial_port,baudrate,message):
86-
general_send_serial(socketio,close_port,serial_port,baudrate,message,"timed")
60+
deftest_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-
deftest_send_serial_timedraw(socketio,close_port,serial_port,baudrate,message):
94-
general_send_serial(socketio,close_port,serial_port,baudrate,message,"timedraw")
68+
deftest_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-
deftest_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-
deftest_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-
deftest_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-
defgeneral_open_serial(socketio,serial_port,baudrate,message,buffertype):
122-
open_serial_port(socketio,serial_port,baudrate,message,buffertype)
72+
defgeneral_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
assertany("\"IsOpen\": false,"iniforiinmessage)
12980

13081

131-
defgeneral_send_serial(socketio,close_port,serial_port,baudrate,message,buffertype):
132-
open_serial_port(socketio,serial_port,baudrate,message,buffertype)
82+
defgeneral_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
assertany("send "+serial_port+" ciao"iniforiinmessage)
13990
#check if message has been sent back by the connected board
140-
ifbuffertype=="timedraw":
141-
output=decode_output(extract_serial_data(message))
142-
elifbuffertypein ("default","timed"):
143-
output=extract_serial_data(message)
91+
output=extract_serial_data(message)
14492
assert"ciao"inoutput
14593
# the serial connection is closed by close_port() fixture: even if in case of test failure
14694

14795

148-
defgeneral_send_emoji_serial(socketio,close_port,serial_port,baudrate,message,buffertype):
149-
open_serial_port(socketio,serial_port,baudrate,message,buffertype)
96+
defgeneral_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
assertany("send "+serial_port+" /\"🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\""iniforiinmessage)
156-
ifbuffertype=="timedraw":
157-
output=decode_output(extract_serial_data(message))
158-
elifbuffertypein ("default","timed"):
159-
output=extract_serial_data(message)
104+
output=extract_serial_data(message)
160105
assert"/\"🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\""inoutput
161106
# the serial connection is closed by close_port() fixture: even if in case of test failure
162107

163108

164-
defopen_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+
defopen_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
deftest_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
returnserial_data
205-
150+
206151
defdecode_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)

[8]ページ先頭

©2009-2025 Movatter.jp