Skip to content

Commit

Permalink
[tests] add python3 support (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhui committed Oct 12, 2018
1 parent a2865b5 commit 22dd0e0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions tests/scripts/thread-cert/node_cli.py
Expand Up @@ -441,13 +441,17 @@ def get_addrs(self):
return addrs

def get_addr(self, prefix):
network = ipaddress.ip_network(unicode(prefix))
network = ipaddress.ip_network(u'%s' % str(prefix))
addrs = self.get_addrs()

for addr in addrs:
ipv6_address = ipaddress.ip_address(addr.decode("utf-8"))
if isinstance(addr, bytearray):
addr = bytes(addr)
elif isinstance(addr, str) and sys.version_info[0] == 2:
addr = addr.decode("utf-8")
ipv6_address = ipaddress.ip_address(addr)
if ipv6_address in network:
return ipv6_address.exploded.encode('utf-8')
return ipv6_address.exploded

return None

Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/thread-cert/simulator.py
Expand Up @@ -267,7 +267,7 @@ def receive_events(self):
elif type == self.OT_SIM_EVENT_RADIO_SPINEL_WRITE:
assert not self._is_radio(addr)
radio_addr = self._to_radio_addr(addr)
if not self.devices.has_key(radio_addr):
if not radio_addr in self.devices:
self.awake_devices.add(radio_addr)

event = (event_time, self.event_sequence, radio_addr, self.OT_SIM_EVENT_UART_WRITE, datalen, data)
Expand All @@ -279,7 +279,7 @@ def receive_events(self):
elif type == self.OT_SIM_EVENT_UART_WRITE:
assert self._is_radio(addr)
core_addr = self._to_core_addr(addr)
if not self.devices.has_key(core_addr):
if not core_addr in self.devices:
self.awake_devices.add(core_addr)

event = (event_time, self.event_sequence, core_addr, self.OT_SIM_EVENT_RADIO_SPINEL_WRITE, datalen, data)
Expand Down

0 comments on commit 22dd0e0

Please sign in to comment.