@@ -14,125 +14,128 @@ def test_list(socketio):
14
14
global message
15
15
socketio .on ('message' , message_handler )
16
16
socketio .emit ('command' , 'list' )
17
- time .sleep (.1 )
18
- # print (message)
19
- assert "list" in message [ 0 ]
20
- assert "Ports" in message [ 1 ]
21
- assert "Network" in message [ 2 ]
17
+ time .sleep (.2 )
18
+ print (message )
19
+ assert any ( "list" in i for i in message )
20
+ assert any ( "Ports" in i for i in message )
21
+ assert any ( "Network" in i for i in message )
22
22
23
23
# NOTE run the following tests on linux with a board connected to the PC and with this sketch on it: https://gist.github.com/Protoneer/96db95bfb87c3befe46e
24
24
@pytest .mark .skipif (
25
25
running_on_ci (),
26
26
reason = "VMs have no serial ports" ,
27
27
)
28
- def test__open_serial_default (socketio ):
28
+ def test_open_serial_default (socketio ):
29
+ time .sleep (.2 )
29
30
global message
30
31
message = []
31
32
socketio .on ('message' , message_handler )
32
33
socketio .emit ('command' , 'open /dev/ttyACM0 9600' )
33
- time .sleep (.1 ) # give time to message to be filled
34
- assert "\" IsOpen\" : true" in message [ 2 ]
34
+ time .sleep (.5 ) # give time to message to be filled
35
+ assert any ( "\" IsOpen\" : true" in i for i in message )
35
36
socketio .emit ('command' , 'send /dev/ttyACM0 /"ciao/"' )
36
- time .sleep (.1 )
37
- assert "send /dev/ttyACM0 /\" ciao/\" " in message [ 3 ]
37
+ time .sleep (.2 )
38
+ assert any ( "send /dev/ttyACM0 /\" ciao/\" " in i for i in message )
38
39
assert "ciao" in extract_serial_data (message )
39
40
40
41
# test with a lot of emoji: they can be messed up
41
- message = [] # reinitialize the message buffer
42
+ # message = [] # reinitialize the message buffer
42
43
socketio .emit ('command' , 'send /dev/ttyACM0 /"🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/"' )
43
- time .sleep (.1 )
44
- assert "send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in message [0 ]
44
+ time .sleep (.2 )
45
+ print (message )
46
+ assert any ("send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in i for i in message )
45
47
emoji_output = extract_serial_data (message )
46
- assert "/\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in emoji_output # this is failing because of UTF8 encoding problems
48
+ assert "/\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in emoji_output # this could be failing because of UTF8 encoding problems
47
49
message = []
48
50
socketio .emit ('command' , 'close /dev/ttyACM0' )
49
- time .sleep (.1 )
50
- # print (message)
51
- assert "\" IsOpen\" : false," in message [8 ]
51
+ time .sleep (.2 )
52
+ assert any ("\" IsOpen\" : false," in i for i in message )
52
53
53
54
@pytest .mark .skipif (
54
55
running_on_ci (),
55
56
reason = "VMs have no serial ports" ,
56
57
)
57
- def test__open_serial_timed (socketio ):
58
+ def test_open_serial_timed (socketio ):
59
+ time .sleep (.2 )
58
60
global message
59
61
message = []
60
62
socketio .on ('message' , message_handler )
61
63
socketio .emit ('command' , 'open /dev/ttyACM0 9600 timed' )
62
- time .sleep (.1 ) # give time to message to be filled
63
- assert "\" IsOpen\" : true" in message [2 ]
64
+ time .sleep (.5 ) # give time to message to be filled
65
+ print (message )
66
+ assert any ("\" IsOpen\" : true" in i for i in message )
64
67
socketio .emit ('command' , 'send /dev/ttyACM0 /"ciao/"' )
65
- time .sleep (.1 )
66
- assert "send /dev/ttyACM0 /\" ciao/\" " in message [ 3 ]
68
+ time .sleep (.2 )
69
+ assert any ( "send /dev/ttyACM0 /\" ciao/\" " in i for i in message )
67
70
assert "ciao" in extract_serial_data (message )
68
71
69
72
# test with a lot of emoji: usually they get messed up
70
73
message = [] # reinitialize the message buffer
71
74
socketio .emit ('command' , 'send /dev/ttyACM0 /"🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/"' )
72
- time .sleep (.1 )
73
- assert "send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in message [0 ]
74
- emoji_output = extract_serial_data (message )
75
- assert "/\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in emoji_output
75
+ time .sleep (.2 )
76
+ assert any ("send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in i for i in message )
77
+ assert "/\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in extract_serial_data (message )
76
78
message = []
77
79
socketio .emit ('command' , 'close /dev/ttyACM0' )
78
- time .sleep (.1 )
80
+ time .sleep (.2 )
79
81
# print (message)
80
- assert "\" IsOpen\" : false," in message [ 8 ]
82
+ assert any ( "\" IsOpen\" : false," in i for i in message )
81
83
82
84
@pytest .mark .skipif (
83
85
running_on_ci (),
84
86
reason = "VMs have no serial ports" ,
85
87
)
86
- def test__open_serial_timedraw (socketio ):
88
+ def test_open_serial_timedraw (socketio ):
87
89
global message
88
90
message = []
89
91
socketio .on ('message' , message_handler )
90
92
socketio .emit ('command' , 'open /dev/ttyACM0 9600 timedraw' )
91
- time .sleep (.1 ) # give time to message to be filled
92
- assert "\" IsOpen\" : true" in message [ 2 ]
93
+ time .sleep (.5 ) # give time to message to be filled
94
+ assert any ( "\" IsOpen\" : true" in i for i in message )
93
95
socketio .emit ('command' , 'send /dev/ttyACM0 /"ciao/"' )
94
- time .sleep (.1 )
95
- assert "send /dev/ttyACM0 /\" ciao/\" " in message [ 3 ]
96
+ time .sleep (.2 )
97
+ assert any ( "send /dev/ttyACM0 /\" ciao/\" " in i for i in message )
96
98
assert "ciao" in decode_output (extract_serial_data (message ))
97
99
98
100
# test with a lot of emoji: usually they get messed up
99
101
message = [] # reinitialize the message buffer
100
102
socketio .emit ('command' , 'send /dev/ttyACM0 /"🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/"' )
101
- time .sleep (.1 )
102
- assert "send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in message [ 0 ]
103
+ time .sleep (.2 )
104
+ assert any ( "send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in i for i in message )
103
105
# print (message)
104
106
assert "/\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in decode_output (extract_serial_data (message ))
105
107
socketio .emit ('command' , 'close /dev/ttyACM0' )
106
- time .sleep (.1 )
108
+ time .sleep (.2 )
107
109
# print (message)
108
- assert "\" IsOpen\" : false," in message [ 10 ]
110
+ assert any ( "\" IsOpen\" : false," in i for i in message )
109
111
110
112
@pytest .mark .skipif (
111
113
running_on_ci (),
112
114
reason = "VMs have no serial ports" ,
113
115
)
114
- def test__open_serial_timedbinary (socketio ):
116
+ def test_open_serial_timedbinary (socketio ):
115
117
global message
116
118
message = []
117
119
socketio .on ('message' , message_handler )
118
120
socketio .emit ('command' , 'open /dev/ttyACM0 9600 timedbinary' )
119
- time .sleep (1 ) # give time to message to be filled
120
- assert "\" IsOpen\" : true" in message [ 2 ]
121
+ time .sleep (.5 ) # give time to message to be filled
122
+ assert any ( "\" IsOpen\" : true" in i for i in message )
121
123
socketio .emit ('command' , 'send /dev/ttyACM0 /"ciao/"' )
122
- time .sleep (.1 )
123
- assert "send /dev/ttyACM0 /\" ciao/\" " in message [3 ]
124
+ time .sleep (.2 )
125
+ assert any ("send /dev/ttyACM0 /\" ciao/\" " in i for i in message )
126
+ print (message )
124
127
assert "ciao" in decode_output (extract_serial_data (message ))
125
128
126
129
# test with a lot of emoji: usually they get messed up
127
130
message = [] # reinitialize the message buffer
128
131
socketio .emit ('command' , 'send /dev/ttyACM0 /"🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/"' )
129
- time .sleep (.1 )
130
- assert "send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in message [ 0 ]
132
+ time .sleep (.2 )
133
+ assert any ( "send /dev/ttyACM0 /\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in i for i in message )
131
134
assert "/\" 🧀🧀🧀🧀🧀🧀🧀🧀🧀🧀/\" " in decode_output (extract_serial_data (message ))
132
135
socketio .emit ('command' , 'close /dev/ttyACM0' )
133
- time .sleep (.1 )
136
+ time .sleep (.2 )
134
137
# print (message)
135
- assert "\" IsOpen\" : false," in message [ 10 ]
138
+ assert any ( "\" IsOpen\" : false," in i for i in message )
136
139
137
140
138
141
# callback called by socketio when a message is received
@@ -147,9 +150,9 @@ def extract_serial_data(msg):
147
150
serial_data = ""
148
151
for i in msg :
149
152
if "{\" P\" " in i :
150
- # print (json.loads(i)["D"])
153
+ print (json .loads (i )["D" ])
151
154
serial_data += json .loads (i )["D" ]
152
- # print("serialdata:"+serial_data)
155
+ print ("serialdata:" + serial_data )
153
156
return serial_data
154
157
155
158
def decode_output (raw_output ):
0 commit comments