In Python 2.7, array.array cannot be converted correctly into binary type by using six.binary_type(). So packet.Packet() cannot skip data effectively. This patch remove to use array.array as input binary in test_packet.
Note: array.array can be used as input binary as the same as before, but in this case, the padding data will be displayed in str or repr representation in Python 2.7. Signed-off-by: IWASE Yusuke <[email protected]> --- ryu/tests/unit/packet/test_packet.py | 44 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/ryu/tests/unit/packet/test_packet.py b/ryu/tests/unit/packet/test_packet.py index b822976..1b4c704 100644 --- a/ryu/tests/unit/packet/test_packet.py +++ b/ryu/tests/unit/packet/test_packet.py @@ -18,12 +18,20 @@ import unittest import logging import struct -import array import inspect -from nose.tools import * +from nose.tools import ok_, eq_ import six from ryu.ofproto import ether, inet -from ryu.lib.packet import * +from ryu.lib.packet import arp +from ryu.lib.packet import bpdu +from ryu.lib.packet import ethernet +from ryu.lib.packet import icmp, icmpv6 +from ryu.lib.packet import ipv4, ipv6 +from ryu.lib.packet import llc +from ryu.lib.packet import packet, packet_utils +from ryu.lib.packet import sctp +from ryu.lib.packet import tcp, udp +from ryu.lib.packet import vlan from ryu.lib import addrconv @@ -101,7 +109,7 @@ class TestPacket(unittest.TestCase): eq_(buf, p.data) # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_arp = protocols['arp'] @@ -201,7 +209,7 @@ class TestPacket(unittest.TestCase): eq_(buf, p.data) # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_vlan = protocols['vlan'] @@ -319,7 +327,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + u_buf + self.payload # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv4 = protocols['ipv4'] @@ -363,7 +371,7 @@ class TestPacket(unittest.TestCase): # payload ok_('payload' in protocols) - eq_(self.payload, protocols['payload'].tostring()) + eq_(self.payload, protocols['payload']) # to string eth_values = {'dst': self.dst_mac, @@ -464,7 +472,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + t_buf + self.payload # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv4 = protocols['ipv4'] @@ -513,7 +521,7 @@ class TestPacket(unittest.TestCase): # payload ok_('payload' in protocols) - eq_(self.payload, protocols['payload'].tostring()) + eq_(self.payload, protocols['payload']) # to string eth_values = {'dst': self.dst_mac, @@ -617,7 +625,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + s_buf # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv4 = protocols['ipv4'] @@ -766,7 +774,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + ic_buf # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv4 = protocols['ipv4'] @@ -896,7 +904,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + u_buf + self.payload # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv6 = protocols['ipv6'] @@ -934,7 +942,7 @@ class TestPacket(unittest.TestCase): # payload ok_('payload' in protocols) - eq_(self.payload, protocols['payload'].tostring()) + eq_(self.payload, protocols['payload']) # to string eth_values = {'dst': 'ff:ff:ff:ff:ff:ff', @@ -1023,7 +1031,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + t_buf + self.payload # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv6 = protocols['ipv6'] @@ -1066,7 +1074,7 @@ class TestPacket(unittest.TestCase): # payload ok_('payload' in protocols) - eq_(self.payload, protocols['payload'].tostring()) + eq_(self.payload, protocols['payload']) # to string eth_values = {'dst': 'ff:ff:ff:ff:ff:ff', @@ -1163,7 +1171,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + s_buf # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv6 = protocols['ipv6'] @@ -1297,7 +1305,7 @@ class TestPacket(unittest.TestCase): buf = e_buf + ip_buf + ic_buf # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_ipv6 = protocols['ipv6'] @@ -1435,7 +1443,7 @@ class TestPacket(unittest.TestCase): eq_(buf, p.data) # parse - pkt = packet.Packet(array.array('B', p.data)) + pkt = packet.Packet(p.data) protocols = self.get_protocols(pkt) p_eth = protocols['ethernet'] p_llc = protocols['llc'] -- 2.7.4 ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
