Fix spurious test errors in test_ipv6.py (#1072)

This commit is contained in:
Przemysław Fierek
2016-12-14 08:58:24 -08:00
committed by Jonathan Hui
parent e3daefae05
commit 7087f9af69
2 changed files with 25 additions and 9 deletions
+17 -7
View File
@@ -27,18 +27,19 @@
# POSSIBILITY OF SUCH DAMAGE.
#
try:
from itertools import izip_longest as zip_longest
except ImportError:
from itertools import zip_longest
from ipaddress import ip_address
import abc
import io
import struct
import sys
from binascii import hexlify
from ipaddress import ip_address
try:
from itertools import izip_longest as zip_longest
except ImportError:
from itertools import zip_longest
# Next headers for IPv6 protocols
IPV6_NEXT_HEADER_HOP_BY_HOP = 0
@@ -696,6 +697,9 @@ class HopByHopOptionHeader(ConvertibleToBytes, BuildableFromBytes):
def __len__(self):
return self._header_length
def __repr__(self):
return "HopByHopOptionHeader(type={}, length={})".format(self.type, self.length)
class HopByHopOption(ConvertibleToBytes):
@@ -724,6 +728,9 @@ class HopByHopOption(ConvertibleToBytes):
def __len__(self):
return len(self.header) + len(self.value)
def __repr__(self):
return "HopByHopOption(header={}, value={})".format(self.header, self.value)
class MPLOption(ConvertibleToBytes):
@@ -766,6 +773,9 @@ class MPLOption(ConvertibleToBytes):
def __len__(self):
return self._header_length + self._seed_id_length[self.S]
def __repr__(self):
return "MPLOption(S={}, M={}, V={}, sequence={}, seed_id={})".format(self.S, self.M, self.V, self.sequence, hexlify(self.seed_id))
class IPv6PacketFactory(PacketFactory):
+8 -2
View File
@@ -259,7 +259,13 @@ def any_mpl_option():
def any_hop_by_hop_bytes_option_header(length=4):
return HopByHopOptionHeader(any_type(), length)
_type = any_type()
# 0 or 1 means padding, so type have to be higher than 1
while _type <= 1:
_type = any_type()
return HopByHopOptionHeader(_type, length)
def any_hop_by_hop_bytes_value(length=2):
@@ -925,7 +931,7 @@ class TestHopByHopFactory(unittest.TestCase):
return bytearray([0x00])
elif padding_length > 1:
padding_length -= 2
return bytearray([0x01, padding_length]) + bytes([0x00 for _ in range(padding_length)])
return bytearray([0x01, padding_length]) + bytearray([0x00 for _ in range(padding_length)])
return bytearray()