diff options
author | IWAMOTO Toshihiro <iwamoto@valinux.co.jp> | 2015-07-03 11:27:15 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-07-03 11:38:03 +0900 |
commit | eff5326d47fee92d1799794c22ac1baa051b937b (patch) | |
tree | 0b5f62ab4876c9ec8a435036186297480e533168 | |
parent | 60c51214f383c075fe5079fe07f1bafc8c50c0f1 (diff) |
python3: Misc str related fixups
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 <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/unit/packet/test_icmp.py | 20 | ||||
-rw-r--r-- | ryu/tests/unit/packet/test_igmp.py | 3 | ||||
-rw-r--r-- | 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 fddf668a..f9438893 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 e2f9b3cc..9813450d 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 394bff31..481ac09e 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): |