mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-27 10:18:44 +00:00
examples: Fix Python coding style
This commit is contained in:
@@ -24,26 +24,29 @@ import os
|
||||
import sys
|
||||
import string
|
||||
import random
|
||||
import socket
|
||||
|
||||
# This environment variable is expected on the host machine
|
||||
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)
|
||||
try:
|
||||
import IDF
|
||||
except ImportError:
|
||||
# This environment variable is expected on the host machine
|
||||
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 IDF
|
||||
|
||||
import Utility
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > make app bootloader
|
||||
# > make print_flash_cmd | tail -n 1 > build/download.config
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
|
||||
import TinyFW
|
||||
import IDF
|
||||
import Utility
|
||||
|
||||
# Import client module
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
client = imp.load_source("client", expath + "/scripts/client.py")
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
# Acquire DUT
|
||||
@@ -52,8 +55,8 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size//1024))
|
||||
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
IDF.check_performance("http_server_bin_size", bin_size // 1024)
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting http_server simple test app")
|
||||
@@ -77,7 +80,7 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
raise RuntimeError
|
||||
|
||||
# Acquire host IP. Need a way to check it
|
||||
host_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Found header => Host: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
dut1.expect(re.compile(r"(?:[\s\S]*)Found header => Host: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
|
||||
# Match additional headers sent in the request
|
||||
dut1.expect("Found header => Test-Header-2: Test-Value-2", timeout=30)
|
||||
@@ -94,7 +97,7 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
dut1.expect("Registering /hello and /echo URIs", timeout=30)
|
||||
|
||||
# Generate random data of 10KB
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in range(10*1024))
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable)) - 1] for _ in range(10 * 1024))
|
||||
Utility.console_log("Test /echo POST handler with random data")
|
||||
if not client.test_post_handler(got_ip, got_port, random_data):
|
||||
raise RuntimeError
|
||||
@@ -117,5 +120,6 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
raise RuntimeError
|
||||
dut1.expect("400 Bad Request - Server unable to understand request due to invalid syntax", timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_protocol_http_server_simple()
|
||||
|
Reference in New Issue
Block a user