| Conditions | 11 |
| Total Lines | 86 |
| 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:
Complex classes like tests.describe_install() 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-argument,unused-variable,singleton-comparison,expression-not-assigned |
||
| 56 | def describe_install(): |
||
| 57 | |||
| 58 | def it_should_create_missing_directories(config): |
||
| 59 | expect(os.path.isdir(config.location)) == False |
||
| 60 | |||
| 61 | expect(gitman.install('gitman_1', depth=1)) == True |
||
| 62 | |||
| 63 | expect(os.listdir(config.location)) == ['gitman_1'] |
||
| 64 | |||
| 65 | def it_should_not_modify_config(config): |
||
| 66 | expect(gitman.install('gitman_1', depth=1)) == True |
||
| 67 | |||
| 68 | expect(config.__mapper__.text) == CONFIG |
||
| 69 | |||
| 70 | def it_should_merge_sources(config): |
||
| 71 | config.__mapper__.text = strip(""" |
||
| 72 | location: deps |
||
| 73 | sources: |
||
| 74 | - dir: gitman_1 |
||
| 75 | link: '' |
||
| 76 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 77 | rev: example-branch |
||
| 78 | sources_locked: |
||
| 79 | - dir: gitman_2 |
||
| 80 | link: '' |
||
| 81 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 82 | rev: example-branch |
||
| 83 | - dir: gitman_3 |
||
| 84 | link: '' |
||
| 85 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 86 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 87 | """) |
||
| 88 | |||
| 89 | expect(gitman.install(depth=1)) == True |
||
| 90 | |||
| 91 | expect(len(os.listdir(config.location))) == 3 |
||
| 92 | |||
| 93 | def it_can_handle_missing_locked_sources(config): |
||
| 94 | config.__mapper__.text = strip(""" |
||
| 95 | location: deps |
||
| 96 | sources: |
||
| 97 | - dir: gitman_1 |
||
| 98 | link: '' |
||
| 99 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 100 | rev: example-branch |
||
| 101 | sources_locked: |
||
| 102 | - dir: gitman_2 |
||
| 103 | link: '' |
||
| 104 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 105 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 106 | """) |
||
| 107 | |||
| 108 | expect(gitman.install('gitman_1', depth=1)) == True |
||
| 109 | |||
| 110 | expect(os.listdir(config.location)) == ['gitman_1'] |
||
| 111 | |||
| 112 | def describe_links(): |
||
| 113 | |||
| 114 | @pytest.fixture |
||
| 115 | def config_with_link(config): |
||
| 116 | config.__mapper__.text = strip(""" |
||
| 117 | location: deps |
||
| 118 | sources: |
||
| 119 | - dir: gitman_1 |
||
| 120 | link: my_link |
||
| 121 | repo: https://github.com/jacebrowning/gitman-demo |
||
| 122 | rev: 7bd138fe7359561a8c2ff9d195dff238794ccc04 |
||
| 123 | """) |
||
| 124 | |||
| 125 | return config |
||
| 126 | |||
| 127 | def it_should_create(config_with_link): |
||
| 128 | expect(gitman.install(depth=1)) == True |
||
| 129 | |||
| 130 | expect(os.listdir()).contains('my_link') |
||
| 131 | |||
| 132 | def it_should_not_overwrite(config_with_link): |
||
| 133 | os.system("touch my_link") |
||
| 134 | |||
| 135 | with pytest.raises(RuntimeError): |
||
| 136 | gitman.install(depth=1) |
||
| 137 | |||
| 138 | def it_should_overwrite_with_force(config_with_link): |
||
| 139 | os.system("touch my_link") |
||
| 140 | |||
| 141 | expect(gitman.install(depth=1, force=True)) == True |
||
| 142 | |||
| 310 |