| Conditions | 13 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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:
Complex classes like describe_display() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # pylint: disable=unused-variable,expression-not-assigned |
||
| 13 | def describe_display(): |
||
| 14 | |||
| 15 | @pytest.fixture |
||
| 16 | def app(): |
||
| 17 | app = create_app(get_config('test')) |
||
| 18 | app.config['GOOGLE_ANALYTICS_TID'] = 'my_tid' |
||
| 19 | return app |
||
| 20 | |||
| 21 | request_html = Mock(url="it's a path?alt=style") |
||
| 22 | request_html.headers.get = Mock(return_value="text/html") |
||
| 23 | request_html.base_url = "it's a path" |
||
| 24 | request_html.args = {'alt': ['style']} |
||
| 25 | |||
| 26 | request_image = Mock(url="it's a path") |
||
| 27 | request_image.headers.get = Mock(return_value="(not a browser)") |
||
| 28 | request_image.base_url = "it's a path" |
||
| 29 | request_image.args = {} |
||
| 30 | |||
| 31 | request_share = Mock(url="it's a path?alt=style&share=true") |
||
| 32 | request_share.headers.get = Mock(return_value="*/*") |
||
| 33 | request_share.base_url = "it's a path" |
||
| 34 | request_share.args = {'alt': ['style'], 'share': ['true']} |
||
| 35 | |||
| 36 | @patch('memegen.routes._utils.request', request_html) |
||
| 37 | def it_returns_html_for_browsers(app): |
||
| 38 | |||
| 39 | with app.test_request_context(): |
||
| 40 | html = display("my_title", "my_path", raw=True) |
||
| 41 | |||
| 42 | print(html) |
||
| 43 | assert "<title>my_title</title>" in html |
||
| 44 | assert 'url("it\'s a path?alt=style")' in html |
||
| 45 | assert "ga('create', 'my_tid', 'auto');" in html |
||
| 46 | |||
| 47 | @patch('memegen.routes._utils.send_file') |
||
| 48 | @patch('memegen.routes._utils.request', request_image) |
||
| 49 | def it_returns_an_image_otherwise(mock_send_file): |
||
| 50 | |||
| 51 | display("my_title", "my_path") |
||
| 52 | |||
| 53 | expect(mock_send_file.mock_calls) == [ |
||
| 54 | call("my_path", mimetype='image/jpeg'), |
||
| 55 | ] |
||
| 56 | |||
| 57 | @patch('memegen.routes._utils.request', request_share) |
||
| 58 | def it_returns_html_when_sharing(app): |
||
| 59 | |||
| 60 | with app.test_request_context(): |
||
| 61 | html = display("my_title", "my_path", share=True, raw=True) |
||
| 62 | |||
| 63 | print(html) |
||
| 64 | assert "<title>my_title</title>" in html |
||
| 65 | assert 'url("it\'s a path?alt=style")' in html |
||
| 66 | assert "ga('create', 'my_tid', 'auto');" in html |
||
| 67 |
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.