Conditions | 5 |
Total Lines | 79 |
Code Lines | 71 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | """Module to help to create tests.""" |
||
42 | def get_topology_with_metadata_mock(): |
||
43 | """Create a topology with metadata.""" |
||
44 | switches = {} |
||
45 | interfaces = {} |
||
46 | links = {} |
||
47 | i = 0 |
||
48 | |||
49 | switches_to_interface_counts = {"S1": 2, "S2": 2, "S3": 6, "S4": 2, |
||
50 | "S5": 6, "S6": 5, "S7": 2, "S8": 8, |
||
51 | "S9": 4, "S10": 3, "S11": 3, |
||
52 | "User1": 4, "User2": 2, |
||
53 | "User3": 2, "User4": 3} |
||
54 | |||
55 | links_to_interfaces = [["S1:1", "S2:1"], ["S1:2", "User1:1"], |
||
56 | ["S2:2", "User4:1"], ["S3:1", "S5:1"], |
||
57 | ["S3:2", "S7:1"], ["S3:3", "S8:1"], |
||
58 | ["S3:4", "S11:1"], |
||
59 | ["S3:5", "User3:1"], ["S3:6", "User4:2"], |
||
60 | ["S4:1", "S5:2"], ["S4:2", "User1:2"], |
||
61 | ["S5:3", "S6:1"], |
||
62 | ["S5:4", "S6:2"], ["S5:5", "S8:2"], |
||
63 | ["S5:6", "User1:3"], ["S6:3", "S9:1"], |
||
64 | ["S6:4", "S9:2"], ["S6:5", "S10:1"], |
||
65 | ["S7:2", "S8:3"], |
||
66 | ["S8:4", "S9:3"], ["S8:5", "S9:4"], |
||
67 | ["S8:6", "S10:2"], |
||
68 | ["S8:7", "S11:2"], ["S8:8", "User3:2"], |
||
69 | ["S10:3", "User2:1"], ["S11:3", "User2:2"], |
||
70 | ["User1:4", "User4:3"]] |
||
71 | |||
72 | links_to_metadata = [ |
||
73 | {"reliability": 5, "bandwidth": 100, "delay": 105}, |
||
74 | {"reliability": 5, "bandwidth": 100, "delay": 1}, |
||
75 | {"reliability": 5, "bandwidth": 100, "delay": 10}, |
||
76 | {"reliability": 5, "bandwidth": 10, "delay": 112}, |
||
77 | {"reliability": 5, "bandwidth": 100, "delay": 1}, |
||
78 | {"reliability": 5, "bandwidth": 100, "delay": 1}, |
||
79 | {"reliability": 3, "bandwidth": 100, "delay": 6}, |
||
80 | {"reliability": 5, "bandwidth": 100, "delay": 1}, |
||
81 | {"reliability": 5, "bandwidth": 100, "delay": 10}, |
||
82 | {"reliability": 1, "bandwidth": 100, "delay": 30, "ownership": "A"}, |
||
83 | {"reliability": 3, "bandwidth": 100, "delay": 110, "ownership": "A"}, |
||
84 | {"reliability": 1, "bandwidth": 100, "delay": 40}, |
||
85 | {"reliability": 3, "bandwidth": 100, "delay": 40, "ownership": "A"}, |
||
86 | {"reliability": 5, "bandwidth": 100, "delay": 112}, |
||
87 | {"reliability": 3, "bandwidth": 100, "delay": 60}, |
||
88 | {"reliability": 3, "bandwidth": 100, "delay": 60}, |
||
89 | {"reliability": 5, "bandwidth": 100, "delay": 62}, |
||
90 | {"bandwidth": 100, "delay": 108, "ownership": "A"}, |
||
91 | {"reliability": 5, "bandwidth": 100, "delay": 1}, |
||
92 | {"reliability": 3, "bandwidth": 100, "delay": 32}, |
||
93 | {"reliability": 3, "bandwidth": 100, "delay": 110}, |
||
94 | {"reliability": 5, "bandwidth": 100, "ownership": "A"}, |
||
95 | {"reliability": 3, "bandwidth": 100, "delay": 7}, |
||
96 | {"reliability": 5, "bandwidth": 100, "delay": 1}, |
||
97 | {"reliability": 3, "bandwidth": 100, "delay": 10, "ownership": "A"}, |
||
98 | {"reliability": 3, "bandwidth": 100, "delay": 6}, |
||
99 | {"reliability": 5, "bandwidth": 10, "delay": 105}] |
||
100 | |||
101 | for switch in switches_to_interface_counts: |
||
102 | switches[switch] = get_switch_mock(switch) |
||
103 | |||
104 | for key, value in switches_to_interface_counts.items(): |
||
105 | switches[key].interfaces = {} |
||
106 | for interface in _get_interfaces(value, switches[key]): |
||
107 | switches[key].interfaces[interface.id] = interface |
||
108 | interfaces[interface.id] = interface |
||
109 | |||
110 | for interfaces_str in links_to_interfaces: |
||
111 | interface_a = interfaces[interfaces_str[0]] |
||
112 | interface_b = interfaces[interfaces_str[1]] |
||
113 | links[str(i)] = get_link_mock(interface_a, interface_b) |
||
|
|||
114 | links[str(i)].metadata = links_to_metadata[i] |
||
115 | i += 1 |
||
116 | |||
117 | topology = MagicMock() |
||
118 | topology.links = links |
||
119 | topology.switches = switches |
||
120 | return topology |
||
121 | |||
144 |