From a23f778e119a1e4a98f9adef0d0d22174450c890 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Fri, 14 Sep 2018 10:58:40 -1000 Subject: [PATCH] [tests] support python3 (#3068) --- tests/scripts/thread-cert/command.py | 20 ++++++++++++++++---- tests/scripts/thread-cert/node_cli.py | 5 ++++- tests/scripts/thread-cert/requirements.txt | 5 +++-- tests/scripts/thread-cert/simulator.py | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/scripts/thread-cert/command.py b/tests/scripts/thread-cert/command.py index d29d1abd6..e79b3f74a 100644 --- a/tests/scripts/thread-cert/command.py +++ b/tests/scripts/thread-cert/command.py @@ -1,5 +1,7 @@ -import ipv6 +import sys + +import ipv6 import network_layer import config import mle @@ -22,7 +24,12 @@ def check_address_query(command_msg, source_node, destination_address): + str(ipv6.ip_address(source_rloc)) + ", but the source_address in command msg is: " \ + str(command_msg.ipv6_packet.ipv6_header.source_address) - assert ipv6.ip_address(destination_address.decode('utf-8')) == command_msg.ipv6_packet.ipv6_header.destination_address, "Error: The IPv6 destination address is not expected." + if isinstance(destination_address, bytearray): + destination_address = bytes(destination_address) + elif isinstance(destination_address, str) and sys.version_info[0] == 2: + destination_address = destination_address.decode("utf-8") + + assert ipv6.ip_address(destination_address) == command_msg.ipv6_packet.ipv6_header.destination_address, "Error: The IPv6 destination address is not expected." def check_address_notification(command_msg, source_node, destination_node): """Verify source_node sent a properly formatted Address Notification command message to destination_node. @@ -51,9 +58,14 @@ def check_address_error_notification(command_msg, source_node, destination_addre + str(ipv6.ip_address(source_rloc)) + ", but the source_address in command msg is: " \ + str(command_msg.ipv6_packet.ipv6_header.source_address) - assert ipv6.ip_address(destination_address.decode('utf-8')) == command_msg.ipv6_packet.ipv6_header.destination_address, \ + if isinstance(destination_address, bytearray): + destination_address = bytes(destination_address) + elif isinstance(destination_address, str) and sys.version_info[0] == 2: + destination_address = destination_address.decode("utf-8") + + assert ipv6.ip_address(destination_address) == command_msg.ipv6_packet.ipv6_header.destination_address, \ "Error: The IPv6 destination address is not expected. The destination node's rloc is: " \ - + str(ipv6.ip_address(destination_address.decode('utf-8'))) + ", but the destination_address in command msg is: " \ + + str(ipv6.ip_address(destination_address)) + ", but the destination_address in command msg is: " \ + str(command_msg.ipv6_packet.ipv6_header.destination_address) def check_address_release(command_msg, destination_node): diff --git a/tests/scripts/thread-cert/node_cli.py b/tests/scripts/thread-cert/node_cli.py index 7dd18a32f..9138558a6 100644 --- a/tests/scripts/thread-cert/node_cli.py +++ b/tests/scripts/thread-cert/node_cli.py @@ -56,7 +56,10 @@ class otCli: self.__init_sim(nodeid, mode) if self.verbose: - self.pexpect.logfile_read = sys.stdout + if sys.version_info[0] == 2: + self.pexpect.logfile_read = sys.stdout + else: + self.pexpect.logfile_read = sys.stdout.buffer def __init_sim(self, nodeid, mode): """ Initialize a simulation node. """ diff --git a/tests/scripts/thread-cert/requirements.txt b/tests/scripts/thread-cert/requirements.txt index 6de8b89b9..e4c96963f 100644 --- a/tests/scripts/thread-cert/requirements.txt +++ b/tests/scripts/thread-cert/requirements.txt @@ -1,4 +1,5 @@ -enum34==1.1.2 +enum34==1.1.2;python_version<"3.4" +future==0.16.0 ipaddress==1.0.16 -pexpect==4.0.1 +pexpect==4.6 pycryptodome==3.6.6 diff --git a/tests/scripts/thread-cert/simulator.py b/tests/scripts/thread-cert/simulator.py index 7cb5b8c1d..0a0fc7367 100644 --- a/tests/scripts/thread-cert/simulator.py +++ b/tests/scripts/thread-cert/simulator.py @@ -44,7 +44,7 @@ import pcap def dbg_print(*args): if False: - print args + print(args) class RealTime: