build.tests.unit.test_utils   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 84
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestUtils.test_get_cookie() 0 5 1
A TestUtils.test_int_dpid() 0 15 3

1 Function

Rating   Name   Duplication   Size   Complexity  
B test_try_to_gen_intf_mac() 0 50 1
1
"""Test utils module."""
2 1
from unittest import TestCase
3
4 1
import pytest
5 1
from napps.kytos.of_lldp.utils import get_cookie, int_dpid, try_to_gen_intf_mac
6
7
8 1
@pytest.mark.parametrize(
9
    "address,dpid,port_number,expected",
10
    [
11
        (
12
            "00:00:00:00:00:00",
13
            "00:00:00:00:00:00:00:01",
14
            1,
15
            "0e:00:00:00:01:01",
16
        ),
17
        (
18
            "00:00:00:00:00:00",
19
            "00:00:01:22:03:04:05:06",
20
            1,
21
            "2e:03:04:05:06:01",
22
        ),
23
        (
24
            "00:00:00:00:00:00",
25
            "00:00:00:00:00:00:02:01",
26
            258,
27
            "0e:00:00:02:01:02",
28
        ),
29
        (
30
            "da:47:01:d8:03:44",
31
            "00:00:00:00:00:00:00:01",
32
            1,
33
            "da:47:01:d8:03:44",
34
        ),
35
        (
36
            "db:47:01:d8:03:44",
37
            "00:00:00:00:00:00:00:01",
38
            1,
39
            "0e:00:00:00:01:01"
40
        ),
41
        (
42
            "00:00:00:00:00:00",
43
            "00:" * 20,
44
            1,
45
            "00:00:00:00:00:00",
46
        ),
47
        (
48
            "00:00:00:00:00:00",
49
            "00:00:00:00:00:16:00:02",
50
            1,
51
            "0e:00:16:00:02:01",
52
        ),
53
    ],
54
)
55 1
def test_try_to_gen_intf_mac(address, dpid, port_number, expected) -> None:
56
    """Test try_to_gen_intf_mac."""
57 1
    assert try_to_gen_intf_mac(address, dpid, port_number) == expected
58
59
60 1
class TestUtils(TestCase):
61
    """Tests for the utils module."""
62
63 1
    def test_int_dpid(self):
64
        """Test int dpid."""
65 1
        test_data = [
66
            (
67
                "21:00:10:00:00:00:00:02",
68
                0x2100100000000002,
69
            ),
70
            (
71
                "00:00:00:00:00:00:00:07",
72
                0x0000000000000007,
73
            ),
74
        ]
75 1
        for dpid, expected_dpid in test_data:
76 1
            with self.subTest(dpid=dpid, expected_dpid=expected_dpid):
77 1
                assert int_dpid(dpid) == expected_dpid
78
79 1
    @staticmethod
80 1
    def test_get_cookie():
81
        """Test get_cookie."""
82 1
        dpid = "00:00:00:00:00:00:00:01"
83
        assert hex(get_cookie(dpid)) == hex(0xab00000000000001)
84