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

build.tests.unit.test_results   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A TestResults.generate_topology() 0 6 1
A TestResults.get_path() 0 4 1
A TestResults.get_path_constrained() 0 6 1
A TestResults.setUp() 0 7 1
A TestResults.create_link() 0 7 1
A TestResults.create_switch() 0 4 1
A TestResults.add_interfaces() 0 8 2
A TestResults.add_metadata_to_link() 0 5 1
1
"""Module to test the KytosGraph in graph.py."""
2
from unittest import TestCase
3
4
import networkx as nx
5
from kytos.core.interface import Interface
6
from kytos.core.link import Link
7
from kytos.core.switch import Switch
8
9
# module under test
10
from graph import KytosGraph
11
12
13
class TestResults(TestCase):
14
    """Tests for the graph class."""
15
16
    def setUp(self):
17
        """Setup for most tests"""
18
        switches, links = self.generate_topology()
19
        self.graph = KytosGraph()
20
        self.graph.clear()
21
        self.graph.update_nodes(switches)
22
        self.graph.update_links(links)
23
24
    def get_path(self, source, destination):
25
        """Return the shortest path"""
26
        results = self.graph.shortest_paths(source, destination)
27
        return results
28
29
    def get_path_constrained(self, source, destination, maximum_misses=None,
30
                             **metrics):
31
        """Return the constrained shortest path"""
32
        return self.graph.constrained_flexible_paths(source, destination,
33
                                                     maximum_misses,
34
                                                     **metrics)
35
36
    @ staticmethod
37
    def generate_topology():
38
        """Generates a predetermined topology"""
39
        switches = {}
40
        links = {}
41
        return (switches, links)
42
43
    @ staticmethod
44
    def create_switch(name, switches):
45
        '''Add a new switch to the list of switches'''
46
        switches[name] = Switch(name)
47
48
    @ staticmethod
49
    def add_interfaces(count, switch, interfaces):
50
        '''Add a new interface to the list of interfaces'''
51
        for i in range(1, count + 1):
52
            str1 = "{}:{}".format(switch.dpid, i)
53
            interface = Interface(str1, i, switch)
54
            interfaces[str1] = interface
55
            switch.update_interface(interface)
56
57
    @ staticmethod
58
    def create_link(interface_a, interface_b, interfaces, links):
59
        '''Add a new link between two interfaces into the list of links'''
60
        compounded = "{}|{}".format(interface_a, interface_b)
61
        final_name = compounded
62
        links[final_name] = Link(
63
            interfaces[interface_a], interfaces[interface_b])
64
65
    @ staticmethod
66
    def add_metadata_to_link(interface_a, interface_b, metrics, links):
67
        '''Add metadata to an existing link in the list of links'''
68
        compounded = "{}|{}".format(interface_a, interface_b)
69
        links[compounded].extend_metadata(metrics)
70