summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-08 16:24:15 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-11-16 09:15:47 +0900
commit6ec8802a00723758f255dea1a0be7456bb3e3bb4 (patch)
treeabca1b6ca48c3ae36e7ba9ffca318be385e7410d
parentf3d752178cc84799e0d364ac657b3240d6e9f801 (diff)
test_icmpv6: Catch proper Exception
In some test cases in test_icmpv6.py, @raises() decorator does not catch the correct Exception, because "pack" function cannot be resolved and it need to be specified as "struct.pack". This patch fixes to this unresolved references and make it more strictly matching of Exception class (e.g., AssertionError). Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r--ryu/tests/unit/packet/test_icmpv6.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/ryu/tests/unit/packet/test_icmpv6.py b/ryu/tests/unit/packet/test_icmpv6.py
index 9bb7482b..414eee20 100644
--- a/ryu/tests/unit/packet/test_icmpv6.py
+++ b/ryu/tests/unit/packet/test_icmpv6.py
@@ -84,7 +84,7 @@ class Test_icmpv6_header(unittest.TestCase):
eq_(code, self.code)
eq_(csum, self.csum)
- @raises(Exception)
+ @raises(struct.error)
def test_malformed_icmpv6(self):
m_short_buf = self.buf[1:self.icmp._MIN_LEN]
self.icmp.parser(m_short_buf)
@@ -1329,29 +1329,31 @@ class Test_mldv2_query(unittest.TestCase):
self.setUp_with_srcs()
self.test_to_string()
- @raises(Exception)
+ @raises(AssertionError)
def test_num_larger_than_srcs(self):
self.srcs = ['ff80::1', 'ff80::2', 'ff80::3']
self.num = len(self.srcs) + 1
- self.buf = pack(icmpv6.mldv2_query._PACK_STR, self.maxresp,
- addrconv.ipv6.text_to_bin(self.address),
- self.s_qrv, self.qqic, self.num)
+ self.buf = struct.pack(
+ icmpv6.mldv2_query._PACK_STR,
+ self.maxresp, addrconv.ipv6.text_to_bin(self.address),
+ self.s_qrv, self.qqic, self.num)
for src in self.srcs:
- self.buf += pack('16s', addrconv.ipv6.text_to_bin(src))
+ self.buf += struct.pack('16s', addrconv.ipv6.text_to_bin(src))
self.mld = icmpv6.mldv2_query(
self.maxresp, self.address, self.s_flg, self.qrv, self.qqic,
self.num, self.srcs)
self.test_parser()
- @raises(Exception)
+ @raises(AssertionError)
def test_num_smaller_than_srcs(self):
self.srcs = ['ff80::1', 'ff80::2', 'ff80::3']
self.num = len(self.srcs) - 1
- self.buf = pack(icmpv6.mldv2_query._PACK_STR, self.maxresp,
- addrconv.ipv6.text_to_bin(self.address),
- self.s_qrv, self.qqic, self.num)
+ self.buf = struct.pack(
+ icmpv6.mldv2_query._PACK_STR,
+ self.maxresp, addrconv.ipv6.text_to_bin(self.address),
+ self.s_qrv, self.qqic, self.num)
for src in self.srcs:
- self.buf += pack('16s', addrconv.ipv6.text_to_bin(src))
+ self.buf += struct.pack('16s', addrconv.ipv6.text_to_bin(src))
self.mld = icmpv6.mldv2_query(
self.maxresp, self.address, self.s_flg, self.qrv, self.qqic,
self.num, self.srcs)
@@ -1596,7 +1598,7 @@ class Test_mldv2_report(unittest.TestCase):
self.setUp_with_records()
self.test_to_string()
- @raises(Exception)
+ @raises(AssertionError)
def test_record_num_larger_than_records(self):
self.record1 = icmpv6.mldv2_report_group(
icmpv6.MODE_IS_INCLUDE, 0, 0, 'ff00::1')
@@ -1620,7 +1622,7 @@ class Test_mldv2_report(unittest.TestCase):
self.mld = icmpv6.mldv2_report(self.record_num, self.records)
self.test_parser()
- @raises(Exception)
+ @raises(AssertionError)
def test_record_num_smaller_than_records(self):
self.record1 = icmpv6.mldv2_report_group(
icmpv6.MODE_IS_INCLUDE, 0, 0, 'ff00::1')
@@ -1923,7 +1925,7 @@ class Test_mldv2_report_group(unittest.TestCase):
self.setUp_with_srcs_and_aux()
eq_(len(self.mld), 76)
- @raises
+ @raises(AssertionError)
def test_num_larger_than_srcs(self):
self.srcs = ['fe80::1', 'fe80::2', 'fe80::3']
self.num = len(self.srcs) + 1
@@ -1931,13 +1933,13 @@ class Test_mldv2_report_group(unittest.TestCase):
icmpv6.mldv2_report_group._PACK_STR, self.type_, self.aux_len,
self.num, addrconv.ipv6.text_to_bin(self.address))
for src in self.srcs:
- self.buf += pack('16s', addrconv.ipv6.text_to_bin(src))
+ self.buf += struct.pack('16s', addrconv.ipv6.text_to_bin(src))
self.mld = icmpv6.mldv2_report_group(
self.type_, self.aux_len, self.num, self.address,
self.srcs, self.aux)
self.test_parser()
- @raises
+ @raises(AssertionError)
def test_num_smaller_than_srcs(self):
self.srcs = ['fe80::1', 'fe80::2', 'fe80::3']
self.num = len(self.srcs) - 1
@@ -1945,13 +1947,13 @@ class Test_mldv2_report_group(unittest.TestCase):
icmpv6.mldv2_report_group._PACK_STR, self.type_, self.aux_len,
self.num, addrconv.ipv6.text_to_bin(self.address))
for src in self.srcs:
- self.buf += pack('16s', addrconv.ipv6.text_to_bin(src))
+ self.buf += struct.pack('16s', addrconv.ipv6.text_to_bin(src))
self.mld = icmpv6.mldv2_report_group(
self.type_, self.aux_len, self.num, self.address,
self.srcs, self.aux)
self.test_parser()
- @raises
+ @raises(struct.error)
def test_aux_len_larger_than_aux(self):
self.aux = b'\x01\x02\x03\x04\x05\x06\x07\x08'
self.aux_len = len(self.aux) // 4 + 1
@@ -1964,7 +1966,7 @@ class Test_mldv2_report_group(unittest.TestCase):
self.srcs, self.aux)
self.test_parser()
- @raises
+ @raises(AssertionError)
def test_aux_len_smaller_than_aux(self):
self.aux = b'\x01\x02\x03\x04\x05\x06\x07\x08'
self.aux_len = len(self.aux) // 4 - 1