Conditions | 2 |
Total Lines | 67 |
Lines | 0 |
Ratio | 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 | # -*- coding: utf-8 -*- |
||
11 | def test_get_parler_languages_from_django_cms(self): |
||
12 | cms = { |
||
13 | 1: [ |
||
14 | { |
||
15 | 'code': 'en', |
||
16 | 'fallbacks': ['es'], |
||
17 | 'hide_untranslated': True, |
||
18 | 'name': 'English', |
||
19 | 'public': True, |
||
20 | 'redirect_on_fallback': True |
||
21 | }, |
||
22 | { |
||
23 | 'code': 'es', |
||
24 | 'fallbacks': ['en'], |
||
25 | 'hide_untranslated': True, |
||
26 | 'name': 'Spanish', |
||
27 | 'public': True, |
||
28 | 'redirect_on_fallback': True |
||
29 | }, |
||
30 | { |
||
31 | 'code': 'fr', |
||
32 | 'fallbacks': ['en'], |
||
33 | 'hide_untranslated': True, |
||
34 | 'name': 'French', |
||
35 | 'public': True, |
||
36 | 'redirect_on_fallback': True |
||
37 | } |
||
38 | ], |
||
39 | 'default': { |
||
40 | 'fallbacks': ['en', ], |
||
41 | 'hide_untranslated': True, |
||
42 | 'public': True, |
||
43 | 'redirect_on_fallback': True |
||
44 | } |
||
45 | } |
||
46 | |||
47 | parler = { |
||
48 | 1: [ |
||
49 | { |
||
50 | 'code': 'en', |
||
51 | 'fallbacks': ['es'], |
||
52 | 'hide_untranslated': True, |
||
53 | 'redirect_on_fallback': True |
||
54 | }, |
||
55 | { |
||
56 | 'code': 'es', |
||
57 | 'fallbacks': ['en'], |
||
58 | 'hide_untranslated': True, |
||
59 | 'redirect_on_fallback': True |
||
60 | }, |
||
61 | { |
||
62 | 'code': 'fr', |
||
63 | 'fallbacks': ['en'], |
||
64 | 'hide_untranslated': True, |
||
65 | 'redirect_on_fallback': True |
||
66 | } |
||
67 | ], |
||
68 | 'default': { |
||
69 | 'fallbacks': ['en', ], |
||
70 | 'hide_untranslated': True, |
||
71 | 'redirect_on_fallback': True |
||
72 | } |
||
73 | } |
||
74 | |||
75 | computed = get_parler_languages_from_django_cms(cms) |
||
76 | for block, block_config in computed.items(): |
||
77 | self.assertEqual(cmp(computed[block], parler[block]), 0) |
||
78 |