[style] apply google python style guide (#4501)

This commit applies and enforces Google's python style for tests.
This commit is contained in:
Yakun Xu
2020-02-04 10:27:50 -08:00
committed by GitHub
parent 8368d440dd
commit 33808ebfba
501 changed files with 6674 additions and 5515 deletions
+14 -21
View File
@@ -37,14 +37,12 @@ import ipaddress
def expect_the_same_class(self, other):
if not isinstance(other, self.__class__):
raise TypeError(
"Expected the same class. Got {} and {}".format(
type(self), type(other)
)
)
raise TypeError("Expected the same class. Got {} and {}".format(
type(self), type(other)))
class MessageInfo(object):
def __init__(self):
self.aux_sec_hdr = None
self.aux_sec_hdr_bytes = None
@@ -109,6 +107,7 @@ class MacAddressType(IntEnum):
class MacAddress(object):
def __init__(self, mac_address, _type, big_endian=True):
if _type == MacAddressType.SHORT:
length = 2
@@ -135,15 +134,11 @@ class MacAddress(object):
def convert_to_iid(self):
if self._type == MacAddressType.SHORT:
return (
bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00])
+ self._mac_address[:2]
)
return (bytearray([0x00, 0x00, 0x00, 0xff, 0xfe, 0x00]) +
self._mac_address[:2])
elif self._type == MacAddressType.LONG:
return (
bytearray([self._mac_address[0] ^ 0x02])
+ self._mac_address[1:]
)
return (bytearray([self._mac_address[0] ^ 0x02]) +
self._mac_address[1:])
else:
raise RuntimeError(
"Could not convert to IID. Invalid MAC address type: {}".format(
@@ -153,8 +148,8 @@ class MacAddress(object):
def from_eui64(cls, eui64, big_endian=True):
if not isinstance(eui64, bytearray):
raise RuntimeError(
"Could not create MAC address from EUI64. Invalid data type: {}".format(
type(eui64)))
"Could not create MAC address from EUI64. Invalid data type: {}"
.format(type(eui64)))
return cls(eui64, MacAddressType.LONG)
@@ -166,17 +161,15 @@ class MacAddress(object):
mac_address = rloc16[:2]
else:
raise RuntimeError(
"Could not create MAC address from RLOC16. Invalid data type: {}".format(
type(rloc16)))
"Could not create MAC address from RLOC16. Invalid data type: {}"
.format(type(rloc16)))
return cls(mac_address, MacAddressType.SHORT)
def __eq__(self, other):
return (self.type == other.type) and (
self.mac_address == other.mac_address
)
self.mac_address == other.mac_address)
def __repr__(self):
return "MacAddress(mac_address=b'{}', type={})".format(
hexlify(self.mac_address), MacAddressType(self._type)
)
hexlify(self.mac_address), MacAddressType(self._type))