| Conditions | 13 | 
| Total Lines | 74 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 7 | ||
| 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_cli() 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=redefined-outer-name,unused-variable,expression-not-assigned  | 
            ||
| 35 | |||
| 36 | def describe_cli():  | 
            ||
| 37 | |||
| 38 | def it_fails_when_missing_arguments(env):  | 
            ||
| 39 | cmd = cli(env)  | 
            ||
| 40 | |||
| 41 | expect(cmd.returncode) == 1  | 
            ||
| 42 |         expect(cmd.stderr).contains("Usage:") | 
            ||
| 43 | |||
| 44 | def describe_update():  | 
            ||
| 45 | |||
| 46 | @pytest.fixture  | 
            ||
| 47 | def slug():  | 
            ||
| 48 | return SLUG + "/update"  | 
            ||
| 49 | |||
| 50 | def it_can_update_metrics(env, slug):  | 
            ||
| 51 | cmd = cli(env, slug, 'unit', '100')  | 
            ||
| 52 | |||
| 53 | expect(cmd.returncode) == 0  | 
            ||
| 54 | expect(cmd.stderr) == ""  | 
            ||
| 55 | expect(cmd.stdout) == ""  | 
            ||
| 56 | |||
| 57 | def it_indicates_when_metrics_decrease(env, slug):  | 
            ||
| 58 | cmd = cli(env, slug, 'unit', '0')  | 
            ||
| 59 | |||
| 60 | expect(cmd.returncode) == 0  | 
            ||
| 61 | expect(cmd.stderr) == ""  | 
            ||
| 62 |             expect(cmd.stdout).contains("coverage decreased") | 
            ||
| 63 | expect(cmd.stdout).contains(  | 
            ||
| 64 | "To reset metrics, run: coveragespace " + slug + " --reset"  | 
            ||
| 65 | )  | 
            ||
| 66 | |||
| 67 | def it_fails_when_metrics_decrease_if_requested(env, slug):  | 
            ||
| 68 | cmd = cli(env, slug, 'unit', '0', '--exit-code')  | 
            ||
| 69 | |||
| 70 | expect(cmd.returncode) == 1  | 
            ||
| 71 | expect(cmd.stderr) == ""  | 
            ||
| 72 |             expect(cmd.stdout).contains("coverage decreased") | 
            ||
| 73 | |||
| 74 | def it_always_display_metrics_when_verbose(env, slug):  | 
            ||
| 75 | cmd = cli(env, slug, 'unit', '100', '--verbose')  | 
            ||
| 76 | |||
| 77 | expect(cmd.returncode) == 0  | 
            ||
| 78 | expect(cmd.stderr) != "" # expect lots of logging  | 
            ||
| 79 |             expect(cmd.stdout).contains("coverage increased") | 
            ||
| 80 | |||
| 81 | def it_skips_when_running_on_ci(env, slug):  | 
            ||
| 82 | env.environ['CI'] = 'true'  | 
            ||
| 83 | |||
| 84 | cmd = cli(env, slug, 'unit', '0', '--exit-code', '--verbose')  | 
            ||
| 85 | |||
| 86 | expect(cmd.returncode) == 0  | 
            ||
| 87 |             expect(cmd.stderr).contains("Coverage check skipped") | 
            ||
| 88 | expect(cmd.stdout) == ""  | 
            ||
| 89 | |||
| 90 | def it_fails_on_slugs_missing_a_slash(env):  | 
            ||
| 91 | cmd = cli(env, 'foobar', 'unit', '100')  | 
            ||
| 92 | |||
| 93 | expect(cmd.returncode) == 1  | 
            ||
| 94 | expect(cmd.stderr).contains(  | 
            ||
| 95 | "<owner/repo> slug must contain a slash")  | 
            ||
| 96 | expect(cmd.stdout) == ""  | 
            ||
| 97 | |||
| 98 | def describe_reset():  | 
            ||
| 99 | |||
| 100 | @pytest.fixture  | 
            ||
| 101 | def slug():  | 
            ||
| 102 | return SLUG + "/reset"  | 
            ||
| 103 | |||
| 104 | def it_can_reset_metrics(env, slug):  | 
            ||
| 105 | cmd = cli(env, slug, '--reset')  | 
            ||
| 106 | |||
| 107 | expect(cmd.returncode) == 0  | 
            ||
| 108 | expect(cmd.stderr) == ""  | 
            ||
| 109 |             expect(cmd.stdout).contains("coverage reset") | 
            ||
| 110 |