mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-17 20:42:21 +02:00
examples: Fix Python coding style
* Original commit: espressif/esp-idf@57c54f96f1
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
from socket import *
|
||||
import socket
|
||||
from threading import Thread
|
||||
import time
|
||||
|
||||
try:
|
||||
import IDF
|
||||
except ImportError:
|
||||
# this is a test case write with tiny-test-fw.
|
||||
# to run test cases outside tiny-test-fw,
|
||||
# we need to set environment variable `TEST_FW_PATH`,
|
||||
@ -12,28 +15,28 @@ import time
|
||||
test_fw_path = os.getenv("TEST_FW_PATH")
|
||||
if test_fw_path and test_fw_path not in sys.path:
|
||||
sys.path.insert(0, test_fw_path)
|
||||
|
||||
import TinyFW
|
||||
import IDF
|
||||
|
||||
global g_client_response;
|
||||
global g_msg_to_client;
|
||||
global g_client_response
|
||||
global g_msg_to_client
|
||||
|
||||
g_client_response = b""
|
||||
g_msg_to_client = b" 3XYZ"
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
s1 = socket(AF_INET, SOCK_DGRAM)
|
||||
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s1.connect(("8.8.8.8", 80))
|
||||
my_ip = s1.getsockname()[0]
|
||||
s1.close()
|
||||
return my_ip
|
||||
|
||||
|
||||
def chat_server_sketch(my_ip):
|
||||
global g_client_response
|
||||
print("Starting the server on {}".format(my_ip))
|
||||
port = 2222
|
||||
s=socket(AF_INET, SOCK_STREAM)
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(600)
|
||||
s.bind((my_ip, port))
|
||||
s.listen(1)
|
||||
@ -51,6 +54,7 @@ def chat_server_sketch(my_ip):
|
||||
s.close()
|
||||
print("server closed")
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
def test_examples_protocol_asio_chat_client(env, extra_data):
|
||||
"""
|
||||
@ -77,7 +81,7 @@ def test_examples_protocol_asio_chat_client(env, extra_data):
|
||||
thread1.start()
|
||||
# 2. start the dut test and wait till client gets IP address
|
||||
dut1.start_app()
|
||||
data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
# 3. send host's IP to the client i.e. the `dut1`
|
||||
dut1.write(host_ip)
|
||||
# 4. client `dut1` should receive a message
|
||||
@ -97,5 +101,6 @@ def test_examples_protocol_asio_chat_client(env, extra_data):
|
||||
raise ValueError('Wrong data received from asi tcp server: {} (expected:{})'.format(g_client_response[4:7], test_msg))
|
||||
thread1.join()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_protocol_asio_chat_client()
|
||||
|
@ -1,9 +1,12 @@
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
from socket import *
|
||||
import socket
|
||||
|
||||
|
||||
try:
|
||||
import IDF
|
||||
except ImportError:
|
||||
# this is a test case write with tiny-test-fw.
|
||||
# to run test cases outside tiny-test-fw,
|
||||
# we need to set environment variable `TEST_FW_PATH`,
|
||||
@ -11,13 +14,9 @@ from socket import *
|
||||
test_fw_path = os.getenv("TEST_FW_PATH")
|
||||
if test_fw_path and test_fw_path not in sys.path:
|
||||
sys.path.insert(0, test_fw_path)
|
||||
|
||||
import TinyFW
|
||||
import IDF
|
||||
|
||||
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
def test_examples_protocol_asio_chat_server(env, extra_data):
|
||||
"""
|
||||
@ -39,7 +38,7 @@ def test_examples_protocol_asio_chat_server(env, extra_data):
|
||||
# 2. get the server IP address
|
||||
data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
# 3. create tcp client and connect to server
|
||||
cli = socket(AF_INET,SOCK_STREAM)
|
||||
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
cli.settimeout(30)
|
||||
cli.connect((data[0],80))
|
||||
cli.send(test_msg)
|
||||
|
@ -1,9 +1,12 @@
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
from socket import *
|
||||
import socket
|
||||
|
||||
|
||||
try:
|
||||
import IDF
|
||||
except ImportError:
|
||||
# this is a test case write with tiny-test-fw.
|
||||
# to run test cases outside tiny-test-fw,
|
||||
# we need to set environment variable `TEST_FW_PATH`,
|
||||
@ -12,12 +15,9 @@ test_fw_path = os.getenv("TEST_FW_PATH")
|
||||
if test_fw_path and test_fw_path not in sys.path:
|
||||
sys.path.insert(0, test_fw_path)
|
||||
|
||||
import TinyFW
|
||||
import IDF
|
||||
|
||||
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
def test_examples_protocol_asio_tcp_server(env, extra_data):
|
||||
"""
|
||||
@ -40,7 +40,7 @@ def test_examples_protocol_asio_tcp_server(env, extra_data):
|
||||
# 2. get the server IP address
|
||||
data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
# 3. create tcp client and connect to server
|
||||
cli = socket(AF_INET,SOCK_STREAM)
|
||||
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
cli.settimeout(30)
|
||||
cli.connect((data[0],80))
|
||||
cli.send(test_msg)
|
||||
|
@ -1,9 +1,12 @@
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
from socket import *
|
||||
import socket
|
||||
|
||||
|
||||
try:
|
||||
import IDF
|
||||
except ImportError:
|
||||
# this is a test case write with tiny-test-fw.
|
||||
# to run test cases outside tiny-test-fw,
|
||||
# we need to set environment variable `TEST_FW_PATH`,
|
||||
@ -12,12 +15,9 @@ test_fw_path = os.getenv("TEST_FW_PATH")
|
||||
if test_fw_path and test_fw_path not in sys.path:
|
||||
sys.path.insert(0, test_fw_path)
|
||||
|
||||
import TinyFW
|
||||
import IDF
|
||||
|
||||
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
def test_examples_protocol_asio_udp_server(env, extra_data):
|
||||
"""
|
||||
@ -40,7 +40,7 @@ def test_examples_protocol_asio_udp_server(env, extra_data):
|
||||
# 2. get the server IP address
|
||||
data = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
# 3. create tcp client and connect to server
|
||||
cli = socket(AF_INET, SOCK_DGRAM)
|
||||
cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
cli.settimeout(30)
|
||||
cli.connect((data[0], 80))
|
||||
cli.send(test_msg)
|
||||
@ -55,5 +55,6 @@ def test_examples_protocol_asio_udp_server(env, extra_data):
|
||||
# 5. check the client message appears also on server terminal
|
||||
dut1.expect(test_msg.decode())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_protocol_asio_udp_server()
|
||||
|
Reference in New Issue
Block a user