Test Failed
Pull Request — master (#58)
by
unknown
07:38
created

TestSearchResults.get_path()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
"""Module to test the KytosGraph in graph.py."""
2
from unittest import TestCase
3
from unittest.mock import Mock
4
5
import networkx as nx
6
from kytos.core.interface import Interface
7
from kytos.core.link import Link
8
# Core modules to import
9
from kytos.core.switch import Switch
10
11
# module under test
12
from graph import KytosGraph
13
14
15
class TestSearchResults(TestCase):
16
17
    def setup(self):
18
        """Setup for most tests"""
19
        switches, links = self.generate_topology()
20
        self.graph = KytosGraph()
21
        self.graph.clear()
22
        self.graph.update_nodes(switches)
23
        self.graph.update_links(links)
24
        self.graph.set_path_fun(nx.shortest_simple_paths)
25
26
    def get_path(self, source, destination):
27
        '''Return the shortest path'''
28
        results = self.graph.shortest_paths(source, destination)
29
        return results
30
31
    def get_path_constrained(self, source, destination, flexible=0, **metrics):
32
        '''Return the constrained shortest path'''
33
        results = self.graph.constrained_flexible_paths(
34
            source, destination, {}, metrics, flexible)
35
        return results
36
37
    def get_path_constrained2(self, source, destination, metrics,
38
                              flexible_metrics):
39
        '''Return the constrained shortest path'''
40
        return self.graph.constrained_flexible_paths(source, destination,
41
                                                     metrics, flexible_metrics)
42
43
    def test_setup(self):
44
        """Provides information on default test setup"""
45
        self.setup()
46
47
    @staticmethod
48
    def generate_topology():
49
        """Generates a predetermined topology"""
50
        switches = {}
51
        links = {}
52
        return (switches, links)
53
54
    @staticmethod
55
    def create_switch(name, switches):
56
        '''Add a new switch to the list of switches'''
57
        switches[name] = Switch(name)
58
59
    @staticmethod
60
    def add_interfaces(count, switch, interfaces):
61
        '''Add a new interface to the list of interfaces'''
62
        for i in range(1, count + 1):
63
            str1 = "{}:{}".format(switch.dpid, i)
64
            interface = Interface(str1, i, switch)
65
            interfaces[str1] = interface
66
            switch.update_interface(interface)
67
68
    @staticmethod
69
    def create_link(interface_a, interface_b, interfaces, links):
70
        '''Add a new link between two interfaces into the list of links'''
71
        compounded = "{}|{}".format(interface_a, interface_b)
72
        final_name = compounded
73
        links[final_name] = Link(
74
            interfaces[interface_a], interfaces[interface_b])
75
76
    @staticmethod
77
    def add_metadata_to_link(interface_a, interface_b, metrics, links):
78
        '''Add metadata to an existing link in the list of links'''
79
        compounded = "{}|{}".format(interface_a, interface_b)
80
        links[compounded].extend_metadata(metrics)
81