From 312f1005516e4218f5bf22d22724f3a70cad8bc3 Mon Sep 17 00:00:00 2001 From: Chen Yu Dong Date: Tue, 27 Oct 2020 15:35:56 +0800 Subject: [PATCH] bugfix: import error in example tests relative import error in lib_ble_client import Queue error in blehr_test import http server error in ota tests --- examples/bluetooth/nimble/blehr/blehr_test.py | 6 +++++- .../system/ota/advanced_https_ota/example_test.py | 13 +++++++++---- .../system/ota/native_ota_example/example_test.py | 11 ++++++++--- .../system/ota/simple_ota_example/example_test.py | 11 ++++++++--- tools/ble/__init__.py | 0 tools/ble/lib_ble_client.py | 9 +++++++-- 6 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 tools/ble/__init__.py diff --git a/examples/bluetooth/nimble/blehr/blehr_test.py b/examples/bluetooth/nimble/blehr/blehr_test.py index 7cc10ed88..0801ae455 100644 --- a/examples/bluetooth/nimble/blehr/blehr_test.py +++ b/examples/bluetooth/nimble/blehr/blehr_test.py @@ -20,9 +20,13 @@ import sys import re import threading import traceback -import Queue import subprocess +try: + import Queue +except ImportError: + import queue as Queue + try: # This environment variable is expected on the host machine test_fw_path = os.getenv("TEST_FW_PATH") diff --git a/examples/system/ota/advanced_https_ota/example_test.py b/examples/system/ota/advanced_https_ota/example_test.py index 26a96ff38..c8255ea01 100644 --- a/examples/system/ota/advanced_https_ota/example_test.py +++ b/examples/system/ota/advanced_https_ota/example_test.py @@ -2,11 +2,16 @@ import re import os import sys import socket -import BaseHTTPServer -import SimpleHTTPServer from threading import Thread import ssl +try: + import BaseHTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler +except ImportError: + import http.server as BaseHTTPServer + from http.server import SimpleHTTPRequestHandler + try: import IDF except ImportError: @@ -110,7 +115,7 @@ def get_ca_cert(ota_image_dir): def start_https_server(ota_image_dir, server_ip, server_port): server_file, key_file = get_ca_cert(ota_image_dir) httpd = BaseHTTPServer.HTTPServer((server_ip, server_port), - SimpleHTTPServer.SimpleHTTPRequestHandler) + SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=key_file, @@ -128,7 +133,7 @@ def redirect_handler_factory(url): """ Returns a request handler class that redirects to supplied `url` """ - class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): + class RedirectHandler(SimpleHTTPRequestHandler): def do_GET(self): print("Sending resp, URL: " + url) self.send_response(301) diff --git a/examples/system/ota/native_ota_example/example_test.py b/examples/system/ota/native_ota_example/example_test.py index 1ad6a1777..db0e266cf 100644 --- a/examples/system/ota/native_ota_example/example_test.py +++ b/examples/system/ota/native_ota_example/example_test.py @@ -2,11 +2,16 @@ import re import os import sys import socket -import BaseHTTPServer -import SimpleHTTPServer from threading import Thread import ssl +try: + import BaseHTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler +except ImportError: + import http.server as BaseHTTPServer + from http.server import SimpleHTTPRequestHandler + try: import IDF except ImportError: @@ -110,7 +115,7 @@ def get_ca_cert(ota_image_dir): def start_https_server(ota_image_dir, server_ip, server_port): server_file, key_file = get_ca_cert(ota_image_dir) httpd = BaseHTTPServer.HTTPServer((server_ip, server_port), - SimpleHTTPServer.SimpleHTTPRequestHandler) + SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=key_file, diff --git a/examples/system/ota/simple_ota_example/example_test.py b/examples/system/ota/simple_ota_example/example_test.py index 7c732a542..7b168322a 100644 --- a/examples/system/ota/simple_ota_example/example_test.py +++ b/examples/system/ota/simple_ota_example/example_test.py @@ -2,11 +2,16 @@ import re import os import sys import socket -import BaseHTTPServer -import SimpleHTTPServer from threading import Thread import ssl +try: + import BaseHTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler +except ImportError: + import http.server as BaseHTTPServer + from http.server import SimpleHTTPRequestHandler + try: import IDF except ImportError: @@ -99,7 +104,7 @@ def start_https_server(ota_image_dir, server_ip, server_port): key_file_handle.close() httpd = BaseHTTPServer.HTTPServer((server_ip, server_port), - SimpleHTTPServer.SimpleHTTPRequestHandler) + SimpleHTTPRequestHandler) httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=key_file, diff --git a/tools/ble/__init__.py b/tools/ble/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tools/ble/lib_ble_client.py b/tools/ble/lib_ble_client.py index 929d305df..4cc12dab5 100644 --- a/tools/ble/lib_ble_client.py +++ b/tools/ble/lib_ble_client.py @@ -35,8 +35,13 @@ except ImportError as e: print("Run `pip install -r $IDF_PATH/tools/ble/requirements.txt` for resolving the issue") raise -from . import lib_gatt -from . import lib_gap +try: + import lib_gatt + import lib_gap +except ImportError: + # for python3 assign_test + from . import lib_gatt + from . import lib_gap srv_added_old_cnt = 0 srv_added_new_cnt = 0