mirror of
https://github.com/espressif/openthread.git
synced 2026-08-07 19:27:46 +00:00
[style] apply google python style guide (#4501)
This commit applies and enforces Google's python style for tests.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user