Passed
Push — master ( b50e97...feedcb )
by Humberto
01:28 queued 14s
created

tests.unit.test_utils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 24
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestUtils.test_unpack_v0x04_packet() 0 5 1
A TestUtils.test_validate_packet_with_invalid_packets() 0 9 1
A TestUtils.test_invalid_packet_with_version_more_then_128() 0 6 1
A TestUtils.test_unpack_v0x01_packet() 0 5 1
1
"""Automate utils tests."""
2
import unittest
3
4
from pyof.utils import UnpackException, unpack, validate_packet
5
from pyof.v0x01.symmetric.hello import Hello as Hello_v0x01
6
from pyof.v0x04.symmetric.hello import Hello as Hello_v0x04
7
8
9
class TestUtils(unittest.TestCase):
10
    """Run tests to verify unpack independent of version."""
11
12
    def test_unpack_v0x01_packet(self):
13
        """Test if the package in version v0x01 is properly unpacked."""
14
        data = Hello_v0x01().pack()
15
        expected = unpack(data)
16
        self.assertEqual(expected.pack(), data)
17
18
    def test_unpack_v0x04_packet(self):
19
        """Test if the package in version v0x04 is properly unpacked."""
20
        data = Hello_v0x04().pack()
21
        expected = unpack(data)
22
        self.assertEqual(expected.pack(), data)
23
24
    def test_invalid_packet_with_version_more_then_128(self):
25
        """Test validate a invalid packet with version more than 128."""
26
        hello = Hello_v0x04()
27
        hello.header.version = 129
28
29
        self.assertRaises(UnpackException, validate_packet, hello.pack())
30
31
    def test_validate_packet_with_invalid_packets(self):
32
        """Test validate a invalid packet with invalid packets."""
33
        hello = Hello_v0x04()
34
35
        hello.header.version = 128
36
        self.assertRaises(UnpackException, validate_packet, hello.pack())
37
38
        hello.header.version = 0
39
        self.assertRaises(UnpackException, validate_packet, hello.pack())
40