[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
+62 -61
View File
@@ -92,6 +92,7 @@ def any_tlvs_data(count=None):
class TestTargetEid(unittest.TestCase):
def test_should_return_eid_value_when_eid_property_is_called(self):
# GIVEN
eid = any_eid()
@@ -105,7 +106,7 @@ class TestTargetEid(unittest.TestCase):
self.assertEqual(eid, actual_eid)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
eid = any_eid()
@@ -116,8 +117,9 @@ class TestTargetEid(unittest.TestCase):
class TestTargetEidFactory(unittest.TestCase):
def test_should_create_TargetEid_from_bytearray_when_parse_method_is_called(
self):
self):
# GIVEN
eid = any_eid()
@@ -132,8 +134,9 @@ class TestTargetEidFactory(unittest.TestCase):
class TestMacExtendedAddress(unittest.TestCase):
def test_should_return_mac_address_value_when_mac_address_property_is_called(
self):
self):
# GIVEN
mac_address = any_mac_extended_address()
@@ -146,39 +149,38 @@ class TestMacExtendedAddress(unittest.TestCase):
self.assertEqual(mac_address, actual_mac_address)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
mac_address = any_mac_extended_address()
mac_extended_address = network_layer.MacExtendedAddress(mac_address)
# THEN
self.assertEqual(
mac_extended_address, network_layer.MacExtendedAddress(mac_address)
)
self.assertEqual(mac_extended_address,
network_layer.MacExtendedAddress(mac_address))
class TestMacExtendedAddressFactory(unittest.TestCase):
def test_should_create_MacExtendedAddress_from_bytearray_when_parse_method_is_called(
self):
self):
# GIVEN
mac_address = any_mac_extended_address()
factory = network_layer.MacExtendedAddressFactory()
# WHEN
mac_extended_address = factory.parse(
io.BytesIO(mac_address), common.MessageInfo()
)
mac_extended_address = factory.parse(io.BytesIO(mac_address),
common.MessageInfo())
# THEN
self.assertTrue(
isinstance(mac_extended_address, network_layer.MacExtendedAddress)
)
isinstance(mac_extended_address, network_layer.MacExtendedAddress))
self.assertEqual(mac_address, mac_extended_address.mac_address)
class TestRloc16(unittest.TestCase):
def test_should_return_rloc16_value_when_rloc16_property_is_called(self):
# GIVEN
rloc16 = any_rloc16()
@@ -192,7 +194,7 @@ class TestRloc16(unittest.TestCase):
self.assertEqual(rloc16, actual_rloc16)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
rloc16 = any_rloc16()
@@ -203,9 +205,9 @@ class TestRloc16(unittest.TestCase):
class TestRloc16Factory(unittest.TestCase):
def test_should_create_Rloc16_from_bytearray_when_parse_method_is_called(
self
):
self):
# GIVEN
rloc16 = any_rloc16()
@@ -222,6 +224,7 @@ class TestRloc16Factory(unittest.TestCase):
class TestMlEid(unittest.TestCase):
def test_should_return_ml_eid_value_when_ml_eid_property_is_called(self):
# GIVEN
ml_eid = any_ml_eid()
@@ -235,7 +238,7 @@ class TestMlEid(unittest.TestCase):
self.assertEqual(ml_eid, actual_ml_eid)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
ml_eid = any_ml_eid()
@@ -246,9 +249,9 @@ class TestMlEid(unittest.TestCase):
class TestMlEidFactory(unittest.TestCase):
def test_should_create_MlEid_from_bytearray_when_parse_method_is_called(
self
):
self):
# GIVEN
ml_eid = any_ml_eid()
@@ -263,6 +266,7 @@ class TestMlEidFactory(unittest.TestCase):
class TestStatus(unittest.TestCase):
def test_should_return_status_value_when_status_property_is_called(self):
# GIVEN
status = any_status()
@@ -276,7 +280,7 @@ class TestStatus(unittest.TestCase):
self.assertEqual(status, actual_status)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
status = any_status()
@@ -287,9 +291,9 @@ class TestStatus(unittest.TestCase):
class TestStatusFactory(unittest.TestCase):
def test_should_create_Status_from_bytearray_when_parse_method_is_called(
self
):
self):
# GIVEN
status = any_status()
@@ -306,13 +310,13 @@ class TestStatusFactory(unittest.TestCase):
class TestTimeSinceLastTransaction(unittest.TestCase):
def test_should_return_seconds_value_when_seconds_property_is_called(self):
# GIVEN
seconds = any_seconds()
time_since_last_transaction = network_layer.TimeSinceLastTransaction(
seconds
)
seconds)
# WHEN
actual_seconds = time_since_last_transaction.seconds
@@ -321,13 +325,12 @@ class TestTimeSinceLastTransaction(unittest.TestCase):
self.assertEqual(seconds, actual_seconds)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
seconds = any_seconds()
time_since_last_transaction = network_layer.TimeSinceLastTransaction(
seconds
)
seconds)
# THEN
self.assertEqual(
@@ -337,8 +340,9 @@ class TestTimeSinceLastTransaction(unittest.TestCase):
class TestTimeSinceLastTransactionFactory(unittest.TestCase):
def test_should_create_TimeSinceLastTransaction_from_bytearray_when_parse_method_is_called(
self):
self):
# GIVEN
seconds = any_seconds()
@@ -347,29 +351,27 @@ class TestTimeSinceLastTransactionFactory(unittest.TestCase):
data = bytearray(struct.pack(">L", seconds))
# WHEN
time_since_last_transaction = factory.parse(
io.BytesIO(data), common.MessageInfo()
)
time_since_last_transaction = factory.parse(io.BytesIO(data),
common.MessageInfo())
# THEN
self.assertTrue(
isinstance(
time_since_last_transaction,
network_layer.TimeSinceLastTransaction,
)
)
))
self.assertEqual(seconds, time_since_last_transaction.seconds)
class TestRouterMask(unittest.TestCase):
def test_should_return_id_sequence_value_when_id_sequence_property_is_called(
self):
self):
# GIVEN
id_sequence = any_id_sequence()
router_mask = network_layer.RouterMask(
id_sequence, any_router_id_mask()
)
router_mask = network_layer.RouterMask(id_sequence,
any_router_id_mask())
# WHEN
actual_id_sequence = router_mask.id_sequence
@@ -378,13 +380,12 @@ class TestRouterMask(unittest.TestCase):
self.assertEqual(id_sequence, actual_id_sequence)
def test_should_return_router_id_mask_value_when_router_id_mask_property_is_called(
self):
self):
# GIVEN
router_id_mask = any_router_id_mask()
router_mask = network_layer.RouterMask(
any_id_sequence(), router_id_mask
)
router_mask = network_layer.RouterMask(any_id_sequence(),
router_id_mask)
# WHEN
actual_router_id_mask = router_mask.router_id_mask
@@ -393,7 +394,7 @@ class TestRouterMask(unittest.TestCase):
self.assertEqual(router_id_mask, actual_router_id_mask)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
id_sequence = any_id_sequence()
router_id_mask = any_router_id_mask()
@@ -401,14 +402,14 @@ class TestRouterMask(unittest.TestCase):
router_mask = network_layer.RouterMask(id_sequence, router_id_mask)
# THEN
self.assertEqual(
router_mask, network_layer.RouterMask(id_sequence, router_id_mask)
)
self.assertEqual(router_mask,
network_layer.RouterMask(id_sequence, router_id_mask))
class TestRouterMaskFactory(unittest.TestCase):
def test_should_create_RouterMask_from_bytearray_when_parse_method_is_called(
self):
self):
# GIVEN
id_sequence = any_id_sequence()
router_id_mask = any_router_id_mask()
@@ -427,6 +428,7 @@ class TestRouterMaskFactory(unittest.TestCase):
class TestNdOption(unittest.TestCase):
def test_should_return_options_value_when_options_property_is_called(self):
# GIVEN
options = any_options()
@@ -440,7 +442,7 @@ class TestNdOption(unittest.TestCase):
self.assertEqual(options, actual_options)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
options = any_options()
@@ -451,9 +453,9 @@ class TestNdOption(unittest.TestCase):
class TestNdOptionFactory(unittest.TestCase):
def test_should_create_NdOption_from_bytearray_when_parse_method_is_called(
self
):
self):
# GIVEN
options = any_options()
@@ -470,6 +472,7 @@ class TestNdOptionFactory(unittest.TestCase):
class TestThreadNetworkData(unittest.TestCase):
def test_should_return_options_value_when_options_property_is_called(self):
# GIVEN
tlvs = any_tlvs_data()
@@ -483,41 +486,39 @@ class TestThreadNetworkData(unittest.TestCase):
self.assertEqual(tlvs, actual_tlvs)
def test_should_return_True_when_try_to_equal_two_the_same_type_objects_with_the_same_values(
self):
self):
# GIVEN
tlvs = any_tlvs_data()
thread_network_data = network_layer.ThreadNetworkData(tlvs)
# THEN
self.assertEqual(
thread_network_data, network_layer.ThreadNetworkData(tlvs)
)
self.assertEqual(thread_network_data,
network_layer.ThreadNetworkData(tlvs))
class TestThreadNetworkDataFactory(unittest.TestCase):
def test_should_create_ThreadNetworkData_from_bytearray_when_parse_method_is_called(
self):
self):
# GIVEN
tlvs = any_tlvs_data()
class DummyNetworkDataTlvsFactory:
def parse(self, data, message_info):
return bytearray(data.read())
factory = network_layer.ThreadNetworkDataFactory(
DummyNetworkDataTlvsFactory()
)
DummyNetworkDataTlvsFactory())
# WHEN
thread_network_data = factory.parse(
io.BytesIO(tlvs), common.MessageInfo()
)
thread_network_data = factory.parse(io.BytesIO(tlvs),
common.MessageInfo())
# THEN
self.assertTrue(
isinstance(thread_network_data, network_layer.ThreadNetworkData)
)
isinstance(thread_network_data, network_layer.ThreadNetworkData))
self.assertEqual(tlvs, thread_network_data.tlvs)