[style] update python style to conform to PEP 8 (#3951)

With the exception of line length set to 119 vs. 79.

Add tests/ and tools/ to py-pretty-check.
This commit is contained in:
Jonathan Hui
2019-07-11 11:45:55 -04:00
committed by GitHub
parent a938ee2845
commit f924adcb60
341 changed files with 8702 additions and 4460 deletions
@@ -28,9 +28,7 @@
#
import copy
import time
import unittest
import ipaddress
import command
import config
@@ -43,12 +41,13 @@ DUT_ROUTER2 = 3
ROUTER3 = 4
SED1 = 5
class Cert_5_3_09_AddressQuery(unittest.TestCase):
def setUp(self):
self.simulator = config.create_default_simulator()
self.nodes = {}
for i in range(1,6):
for i in range(1, 6):
self.nodes[i] = node.Node(i, (i == SED1), simulator=self.simulator)
self.nodes[LEADER].set_panid(0xface)
@@ -84,9 +83,9 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
self.nodes[SED1].enable_whitelist()
def tearDown(self):
for node in list(self.nodes.values()):
node.stop()
node.destroy()
for n in list(self.nodes.values()):
n.stop()
n.destroy()
self.simulator.stop()
def test(self):
@@ -95,7 +94,8 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
self.simulator.go(5)
self.assertEqual(self.nodes[LEADER].get_state(), 'leader')
# Configure the LEADER to be a DHCPv6 Border Router for prefixes 2001:: & 2002::
# Configure the LEADER to be a DHCPv6 Border Router for prefixes 2001::
# & 2002::
self.nodes[LEADER].add_prefix('2001::/64', 'pdros')
self.nodes[LEADER].add_prefix('2002::/64', 'pdro')
self.nodes[LEADER].register_netdata()
@@ -120,7 +120,8 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
self.simulator.go(5)
self.assertEqual(self.nodes[SED1].get_state(), 'child')
# 3 SED1: The SED1 sends an ICMPv6 Echo Request to ROUTER3 using GUA 2001:: address
# 3 SED1: The SED1 sends an ICMPv6 Echo Request to ROUTER3 using GUA
# 2001:: address
router3_addr = self.nodes[ROUTER3].get_addr("2001::/64")
self.assertTrue(router3_addr is not None)
self.assertTrue(self.nodes[SED1].ping(router3_addr))
@@ -128,15 +129,24 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
# Verify DUT_ROUTER2 sent an Address Query Request
dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2)
msg = dut_router2_messages.next_coap_message('0.02', '/a/aq')
msg.assertSentToDestinationAddress(config.REALM_LOCAL_ALL_ROUTERS_ADDRESS)
command.check_address_query(msg, self.nodes[DUT_ROUTER2], config.REALM_LOCAL_ALL_ROUTERS_ADDRESS)
msg.assertSentToDestinationAddress(
config.REALM_LOCAL_ALL_ROUTERS_ADDRESS
)
command.check_address_query(
msg,
self.nodes[DUT_ROUTER2],
config.REALM_LOCAL_ALL_ROUTERS_ADDRESS,
)
# Verify the DUT_ROUTER2 forwarded the ICMPv6 Echo Request to ROUTER3
msg = dut_router2_messages.get_icmp_message(ipv6.ICMP_ECHO_REQUEST)
assert msg is not None, "Error: The DUT_ROUTER2 didn't forward ICMPv6 Echo Request to ROUTER3"
assert (
msg is not None
), "Error: The DUT_ROUTER2 didn't forward ICMPv6 Echo Request to ROUTER3"
msg.assertSentToNode(self.nodes[ROUTER3])
# 4 ROUTER1: ROUTER1 sends an ICMPv6 Echo Request to the SED1 using GUA 2001:: address
# 4 ROUTER1: ROUTER1 sends an ICMPv6 Echo Request to the SED1 using GUA
# 2001:: address
sed1_addr = self.nodes[SED1].get_addr("2001::/64")
self.assertTrue(sed1_addr is not None)
self.assertTrue(self.nodes[ROUTER1].ping(sed1_addr))
@@ -147,9 +157,12 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
# Verify DUT_ROUTER2 sent an Address Notification message
dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2)
msg = dut_router2_messages.next_coap_message('0.02', '/a/an')
command.check_address_notification(msg, self.nodes[DUT_ROUTER2], self.nodes[ROUTER1])
command.check_address_notification(
msg, self.nodes[DUT_ROUTER2], self.nodes[ROUTER1]
)
# 5 SED1: SED1 sends an ICMPv6 Echo Request to the ROUTER3 using GUA 2001:: address
# 5 SED1: SED1 sends an ICMPv6 Echo Request to the ROUTER3 using GUA
# 2001:: address
self.assertTrue(self.nodes[SED1].ping(router3_addr))
# Wait for sniffer got the ICMPv6 Echo Reply
@@ -159,14 +172,21 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2)
dut_router2_messages_temp = copy.deepcopy(dut_router2_messages)
msg = dut_router2_messages.next_coap_message('0.02', '/a/aq', False)
assert msg is None, "Error: The DUT_ROUTER2 sent an unexpected Address Query Request"
assert (
msg is None
), "Error: The DUT_ROUTER2 sent an unexpected Address Query Request"
# Verify DUT_ROUTER2 forwarded the ICMPv6 Echo Reply to SED1
msg = dut_router2_messages_temp.get_icmp_message(ipv6.ICMP_ECHO_RESPONSE)
assert msg is not None, "Error: The DUT_ROUTER2 didn't forward ICMPv6 Echo Reply to SED1"
msg = dut_router2_messages_temp.get_icmp_message(
ipv6.ICMP_ECHO_RESPONSE
)
assert (
msg is not None
), "Error: The DUT_ROUTER2 didn't forward ICMPv6 Echo Reply to SED1"
msg.assertSentToNode(self.nodes[SED1])
# 6 DUT_ROUTER2: Power off ROUTER3 and wait 580s to alow LEADER to expire its Router ID
# 6 DUT_ROUTER2: Power off ROUTER3 and wait 580s to alow LEADER to
# expire its Router ID
self.nodes[ROUTER3].stop()
self.simulator.go(580)
@@ -176,9 +196,12 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
# Verify DUT_ROUTER2 sent an Address Query Request
dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2)
msg = dut_router2_messages.next_coap_message('0.02', '/a/aq')
msg.assertSentToDestinationAddress(config.REALM_LOCAL_ALL_ROUTERS_ADDRESS)
msg.assertSentToDestinationAddress(
config.REALM_LOCAL_ALL_ROUTERS_ADDRESS
)
# 7 SED1: Power off SED1 and wait to allow DUT_ROUTER2 to timeout the child
# 7 SED1: Power off SED1 and wait to allow DUT_ROUTER2 to timeout the
# child
self.nodes[SED1].stop()
self.simulator.go(5)
@@ -189,7 +212,10 @@ class Cert_5_3_09_AddressQuery(unittest.TestCase):
# Verify DUT_ROUTER2 didn't generate an Address Notification message
dut_router2_messages = self.simulator.get_messages_sent_by(DUT_ROUTER2)
msg = dut_router2_messages.next_coap_message('0.02', '/a/an', False)
assert msg is None, "Error: The DUT_ROUTER2 sent an unexpected Address Notification message"
assert (
msg is None
), "Error: The DUT_ROUTER2 sent an unexpected Address Notification message"
if __name__ == '__main__':
unittest.main()