Test Failed
Pull Request — master (#74)
by
unknown
02:02
created

build.tests.integration.test_paths   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 9

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