examples: Fix Python coding style

* Original commit: espressif/esp-idf@57c54f96f1
This commit is contained in:
Roland Dobai
2018-12-04 08:32:48 +01:00
committed by suren-gabrielyan-espressif
parent ade4aeffa5
commit dce0b26ef8

View File

@ -3,28 +3,31 @@ import os
import sys
import socket
import time
import imp
import struct
import dpkt, dpkt.dns
import dpkt
import dpkt.dns
from threading import Thread
# 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`,
# then get and insert `TEST_FW_PATH` to sys path before import FW module
try:
import IDF
except ImportError:
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
import DUT
g_run_server = True
g_done = False
def mdns_server(esp_host):
global g_run_server
global g_done
@ -52,7 +55,7 @@ def mdns_server(esp_host):
sock.sendto(resp_dns.pack(),(MCAST_GRP,UDP_PORT))
while g_run_server:
try:
m=sock.recvfrom( 1024 );
m = sock.recvfrom(1024)
dns = dpkt.dns.DNS(m[0])
if len(dns.qd) > 0 and dns.qd[0].type == dpkt.dns.DNS_A:
if dns.qd[0].name == u'tinytester.local':
@ -71,6 +74,7 @@ def mdns_server(esp_host):
except socket.timeout:
break
@IDF.idf_example_test(env_tag="Example_WIFI")
def test_examples_protocol_mdns(env, extra_data):
global g_run_server
@ -93,9 +97,8 @@ def test_examples_protocol_mdns(env, extra_data):
# 2. get the dut host name (and IP address)
specific_host = dut1.expect(re.compile(r"mdns hostname set to: \[([^\]]+)\]"), timeout=30)
specific_host = str(specific_host[0])
dut_ip = ""
try:
dut_ip = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
except DUT.ExpectTimeout:
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
# 3. check the mdns name is accessible
@ -108,10 +111,11 @@ def test_examples_protocol_mdns(env, extra_data):
break
g_run_server = False
thread1.join()
if g_done == False:
if g_done is False:
raise ValueError('Test has failed: did not receive mdns answer within timeout')
# 4. check DUT output if mdns advertized host is resolved
dut1.expect(re.compile(r"mdns-test: Query A: tinytester.local resolved to: 127.0.0.1"), timeout=30)
if __name__ == '__main__':
test_examples_protocol_mdns()