In python2, binary_type + bytearray gives bytearray, but it gives
binary_type in python3.  Make sure the result is bytearray in both
cases.  Also, remove some redundunt str()s rather than converting
them to six.binary_type.

Signed-off-by: IWAMOTO Toshihiro <[email protected]>
---
 ryu/tests/unit/packet/test_icmp.py | 20 ++++++++++----------
 ryu/tests/unit/packet/test_igmp.py |  3 ---
 ryu/tests/unit/packet/test_lldp.py |  2 +-
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/ryu/tests/unit/packet/test_icmp.py 
b/ryu/tests/unit/packet/test_icmp.py
index fddf668..f943889 100644
--- a/ryu/tests/unit/packet/test_icmp.py
+++ b/ryu/tests/unit/packet/test_icmp.py
@@ -51,7 +51,7 @@ class Test_icmp(unittest.TestCase):
 
         self.buf = bytearray(struct.pack(
             icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
-        self.csum_calc = packet_utils.checksum(six.binary_type(self.buf))
+        self.csum_calc = packet_utils.checksum(self.buf)
         struct.pack_into('!H', self.buf, 2, self.csum_calc)
 
     def setUp_with_echo(self):
@@ -70,10 +70,10 @@ class Test_icmp(unittest.TestCase):
         self.code = 0
         self.ic = icmp.icmp(self.type_, self.code, self.csum, self.data)
 
-        self.buf = struct.pack(
-            icmp.icmp._PACK_STR, self.type_, self.code, self.csum)
+        self.buf = bytearray(struct.pack(
+            icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
         self.buf += self.data.serialize()
-        self.csum_calc = packet_utils.checksum(str(self.buf))
+        self.csum_calc = packet_utils.checksum(self.buf)
         struct.pack_into('!H', self.buf, 2, self.csum_calc)
 
     def setUp_with_dest_unreach(self):
@@ -88,10 +88,10 @@ class Test_icmp(unittest.TestCase):
         self.code = icmp.ICMP_HOST_UNREACH_CODE
         self.ic = icmp.icmp(self.type_, self.code, self.csum, self.data)
 
-        self.buf = struct.pack(
-            icmp.icmp._PACK_STR, self.type_, self.code, self.csum)
+        self.buf = bytearray(struct.pack(
+            icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
         self.buf += self.data.serialize()
-        self.csum_calc = packet_utils.checksum(str(self.buf))
+        self.csum_calc = packet_utils.checksum(self.buf)
         struct.pack_into('!H', self.buf, 2, self.csum_calc)
 
     def setUp_with_TimeExceeded(self):
@@ -104,10 +104,10 @@ class Test_icmp(unittest.TestCase):
         self.code = 0
         self.ic = icmp.icmp(self.type_, self.code, self.csum, self.data)
 
-        self.buf = struct.pack(
-            icmp.icmp._PACK_STR, self.type_, self.code, self.csum)
+        self.buf = bytearray(struct.pack(
+            icmp.icmp._PACK_STR, self.type_, self.code, self.csum))
         self.buf += self.data.serialize()
-        self.csum_calc = packet_utils.checksum(str(self.buf))
+        self.csum_calc = packet_utils.checksum(self.buf)
         struct.pack_into('!H', self.buf, 2, self.csum_calc)
 
     def test_init(self):
diff --git a/ryu/tests/unit/packet/test_igmp.py 
b/ryu/tests/unit/packet/test_igmp.py
index e2f9b3c..9813450 100644
--- a/ryu/tests/unit/packet/test_igmp.py
+++ b/ryu/tests/unit/packet/test_igmp.py
@@ -394,7 +394,6 @@ class Test_igmpv3_query(unittest.TestCase):
         res = unpack_from(igmpv3_query._PACK_STR, six.binary_type(buf))
         buf = bytearray(buf)
         pack_into('!H', buf, 2, 0)
-        buf = str(buf)
 
         eq_(res[0], IGMP_TYPE_QUERY)
         eq_(res[1], 100)
@@ -664,7 +663,6 @@ class Test_igmpv3_report(unittest.TestCase):
         res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
         buf = bytearray(buf)
         pack_into('!H', buf, 2, 0)
-        buf = str(buf)
 
         eq_(res[0], IGMP_TYPE_REPORT_V3)
         eq_(res[1], checksum(buf))
@@ -689,7 +687,6 @@ class Test_igmpv3_report(unittest.TestCase):
         res = unpack_from(igmpv3_report._PACK_STR, six.binary_type(buf))
         buf = bytearray(buf)
         pack_into('!H', buf, 2, 0)
-        buf = str(buf)
 
         eq_(res[0], IGMP_TYPE_REPORT_V3)
         eq_(res[1], checksum(buf))
diff --git a/ryu/tests/unit/packet/test_lldp.py 
b/ryu/tests/unit/packet/test_lldp.py
index 394bff3..481ac09 100644
--- a/ryu/tests/unit/packet/test_lldp.py
+++ b/ryu/tests/unit/packet/test_lldp.py
@@ -47,7 +47,7 @@ class TestLLDPMandatoryTLV(unittest.TestCase):
         pass
 
     def test_get_tlv_type(self):
-        buf = str(bytearray(b'\x02\x07\x04\x00\x04\x96\x1f\xa7\x26'))
+        buf = b'\x02\x07\x04\x00\x04\x96\x1f\xa7\x26'
         eq_(lldp.LLDPBasicTLV.get_type(buf), lldp.LLDP_TLV_CHASSIS_ID)
 
     def test_parse_without_ethernet(self):
-- 
2.1.4


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to