| Conditions | 5 |
| Total Lines | 64 |
| Code Lines | 59 |
| 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 test the EVCBase class.""" |
||
| 150 | def test_as_dict(self): |
||
| 151 | """Test the method as_dict.""" |
||
| 152 | attributes = { |
||
| 153 | "id": "custom_id", |
||
| 154 | "name": "custom_name", |
||
| 155 | "uni_a": get_uni_mocked(is_valid=True), |
||
| 156 | "uni_z": get_uni_mocked(is_valid=True), |
||
| 157 | "start_date": '2018-08-21T18:44:54', |
||
| 158 | "end_date": '2018-08-21T18:44:55', |
||
| 159 | 'primary_links': [], |
||
| 160 | 'request_time': '2018-08-21T19:10:41', |
||
| 161 | 'creation_time': '2018-08-21T18:44:54', |
||
| 162 | 'owner': "my_name", |
||
| 163 | 'circuit_scheduler': [], |
||
| 164 | 'enabled': True, |
||
| 165 | 'priority': 2 |
||
| 166 | } |
||
| 167 | evc = EVC(**attributes) |
||
| 168 | |||
| 169 | expected_dict = { |
||
| 170 | 'id': 'custom_id', |
||
| 171 | 'name': 'custom_name', |
||
| 172 | 'uni_a': attributes['uni_a'].as_dict(), |
||
| 173 | 'uni_z': attributes['uni_z'].as_dict(), |
||
| 174 | 'start_date': '2018-08-21T18:44:54', |
||
| 175 | 'end_date': '2018-08-21T18:44:55', |
||
| 176 | 'bandwidth': 0, |
||
| 177 | 'primary_links': [], |
||
| 178 | 'backup_links': [], |
||
| 179 | 'current_path': [], |
||
| 180 | 'primary_path': [], |
||
| 181 | 'backup_path': [], |
||
| 182 | 'dynamic_backup_path': False, |
||
| 183 | '_requested': { |
||
| 184 | "id": "custom_id", |
||
| 185 | "name": "custom_name", |
||
| 186 | "uni_a": attributes['uni_a'].as_dict(), |
||
| 187 | "uni_z": attributes['uni_z'].as_dict(), |
||
| 188 | "start_date": '2018-08-21T18:44:54', |
||
| 189 | "end_date": '2018-08-21T18:44:55', |
||
| 190 | 'primary_links': [], |
||
| 191 | 'request_time': '2018-08-21T19:10:41', |
||
| 192 | 'creation_time': '2018-08-21T18:44:54', |
||
| 193 | 'owner': "my_name", |
||
| 194 | 'circuit_scheduler': [], |
||
| 195 | 'enabled': True, |
||
| 196 | 'priority': 2 |
||
| 197 | }, |
||
| 198 | 'request_time': '2018-08-21T19:10:41', |
||
| 199 | 'creation_time': '2018-08-21T18:44:54', |
||
| 200 | 'owner': 'my_name', |
||
| 201 | 'circuit_scheduler': [], |
||
| 202 | 'active': False, |
||
| 203 | 'enabled': True, |
||
| 204 | 'priority': 2 |
||
| 205 | } |
||
| 206 | actual_dict = evc.as_dict() |
||
| 207 | for name, value in expected_dict.items(): |
||
| 208 | actual = actual_dict.get(name) |
||
| 209 | if name == '_requested': |
||
| 210 | for requested_name, requested_value in value.items(): |
||
| 211 | if isinstance(requested_value, UNI): |
||
| 212 | value[requested_name] = requested_value.as_dict() |
||
| 213 | self.assertEqual(value, actual) |
||
| 214 |