build.tests.integration.test_paths   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 70
ccs 42
cts 45
cp 0.9333
rs 10
c 0
b 0
f 0
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestPaths.add_interfaces() 0 10 2
A TestPaths.add_metadata_to_link() 0 5 1
A TestPaths.create_link() 0 11 1
A TestPaths.generate_topology() 0 6 1
A TestPaths.create_switch() 0 7 3
A TestPaths.initializer() 0 13 2
1
"""Module to test the KytosGraph in graph.py"""
2
3 1
from kytos.core.interface import Interface
4 1
from kytos.core.link import Link
5 1
from kytos.core.switch import Switch
6
7 1
from napps.kytos.pathfinder.graph import KytosGraph
8
9
10 1
class TestPaths:
11
    """Tests for the graph class."""
12
13 1
    def initializer(self, val=0):
14
        """Test setup for a specific topology"""
15
16 1
        method_name = (
17
            "generate_topology" if not val else "generate_topology_" + str(val)
18
        )
19 1
        method = getattr(self, method_name)
20 1
        switches, links = method()
21
22 1
        self.graph = KytosGraph()
23 1
        self.graph.clear()
24 1
        self.graph.update_nodes(switches)
25 1
        self.graph.update_links(links)
26
27 1
    @staticmethod
28 1
    def generate_topology():
29
        """Generates a predetermined topology"""
30
        switches = {}
31
        links = {}
32
        return switches, links
33
34 1
    @staticmethod
35 1
    def create_switch(name, switches):
36
        """Add a new switch to the list of switches"""
37 1
        switch = Switch(name)
38 1
        switch.is_active = lambda: True
39 1
        switch.is_enabled = lambda: True
40 1
        switches[name] = switch
41
42 1
    @staticmethod
43 1
    def add_interfaces(count, switch, interfaces):
44
        """Add a new interface to the list of interfaces"""
45 1
        for i in range(1, count + 1):
46 1
            str1 = f"{switch.dpid}:{i}"
47 1
            interface = Interface(str1, i, switch)
48 1
            interface.enable()
49 1
            interface.activate()
50 1
            interfaces[str1] = interface
51 1
            switch.update_interface(interface)
52
53 1
    @staticmethod
54 1
    def create_link(interface_a, interface_b, interfaces, links):
55
        """Add a new link between two interfaces into the list of links"""
56 1
        compounded = f"{interface_a}|{interface_b}"
57 1
        final_name = compounded
58 1
        link = Link(
59
            interfaces[interface_a], interfaces[interface_b]
60
        )
61 1
        link.enable()
62 1
        link.activate()
63 1
        links[final_name] = link
64
65 1
    @staticmethod
66 1
    def add_metadata_to_link(interface_a, interface_b, metrics, links):
67
        """Add metadata to an existing link in the list of links"""
68 1
        compounded = f"{interface_a}|{interface_b}"
69
        links[compounded].extend_metadata(metrics)
70