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