| Conditions | 27 |
| Total Lines | 130 |
| 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 yorm.test.describe_mapper() 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=missing-docstring,redefined-outer-name,unused-variable,expression-not-assigned |
||
| 52 | def describe_mapper(): |
||
| 53 | |||
| 54 | def describe_create(): |
||
| 55 | |||
| 56 | def it_creates_the_file(mapper_real): |
||
| 57 | mapper_real.create() |
||
| 58 | |||
| 59 | expect(mapper_real.path).exists() |
||
| 60 | expect(mapper_real.exists).is_true() |
||
| 61 | expect(mapper_real.deleted).is_false() |
||
| 62 | |||
| 63 | def it_pretends_when_fake(mapper_fake): |
||
| 64 | mapper_fake.create() |
||
| 65 | |||
| 66 | expect(mapper_fake.path).missing() |
||
| 67 | expect(mapper_fake.exists).is_true() |
||
| 68 | expect(mapper_fake.deleted).is_false() |
||
| 69 | |||
| 70 | def it_can_be_called_twice(mapper_real): |
||
| 71 | mapper_real.create() |
||
| 72 | mapper_real.create() # should be ignored |
||
| 73 | |||
| 74 | expect(mapper_real.path).exists() |
||
| 75 | |||
| 76 | def describe_delete(): |
||
| 77 | |||
| 78 | def it_deletes_the_file(mapper): |
||
| 79 | mapper.create() |
||
| 80 | mapper.delete() |
||
| 81 | |||
| 82 | expect(mapper.path).missing() |
||
| 83 | expect(mapper.exists).is_false() |
||
| 84 | expect(mapper.deleted).is_true() |
||
| 85 | |||
| 86 | def it_can_be_called_twice(mapper): |
||
| 87 | mapper.delete() |
||
| 88 | mapper.delete() # should be ignored |
||
| 89 | |||
| 90 | expect(mapper.path).missing() |
||
| 91 | |||
| 92 | def describe_fetch(): |
||
| 93 | |||
| 94 | def it_adds_missing_attributes(obj, mapper): |
||
| 95 | mapper.create() |
||
| 96 | mapper.fetch() |
||
| 97 | |||
| 98 | expect(obj.var1) == 1 |
||
| 99 | expect(obj.var2) == 0 |
||
| 100 | expect(obj.var3) == 0 |
||
| 101 | |||
| 102 | def it_ignores_new_attributes(obj, mapper): |
||
| 103 | mapper.create() |
||
| 104 | mapper.text = "var4: foo" |
||
| 105 | |||
| 106 | mapper.fetch() |
||
| 107 | with expect.raises(AttributeError): |
||
| 108 | print(obj.var4) |
||
| 109 | |||
| 110 | def it_infers_types_on_new_attributes_when_not_strict(obj, mapper): |
||
| 111 | mapper.strict = False |
||
| 112 | mapper.create() |
||
| 113 | mapper.text = "var4: foo" |
||
| 114 | |||
| 115 | mapper.fetch() |
||
| 116 | expect(obj.var4) == "foo" |
||
| 117 | |||
| 118 | obj.var4 = 42 |
||
| 119 | mapper.store() |
||
| 120 | |||
| 121 | mapper.fetch() |
||
| 122 | expect(obj.var4) == "42" |
||
| 123 | |||
| 124 | def it_raises_an_exception_after_delete(mapper): |
||
| 125 | mapper.delete() |
||
| 126 | |||
| 127 | with expect.raises(exceptions.FileDeletedError): |
||
| 128 | mapper.fetch() |
||
| 129 | |||
| 130 | def describe_store(): |
||
| 131 | |||
| 132 | def it_creates_the_file_automatically(mapper_real): |
||
| 133 | mapper_real.store() |
||
| 134 | |||
| 135 | expect(mapper_real.path).exists() |
||
| 136 | |||
| 137 | def describe_modified(): |
||
| 138 | |||
| 139 | def is_true_initially(mapper): |
||
| 140 | expect(mapper.modified).is_true() |
||
| 141 | |||
| 142 | def is_true_after_create(mapper): |
||
| 143 | mapper.create() |
||
| 144 | |||
| 145 | expect(mapper.modified).is_true() |
||
| 146 | |||
| 147 | def is_true_after_delete(mapper): |
||
| 148 | mapper.delete() |
||
| 149 | |||
| 150 | expect(mapper.modified).is_true() |
||
| 151 | |||
| 152 | def is_false_after_fetch(mapper): |
||
| 153 | mapper.create() |
||
| 154 | mapper.fetch() |
||
| 155 | |||
| 156 | expect(mapper.modified).is_false() |
||
| 157 | |||
| 158 | def can_be_set_false(mapper): |
||
| 159 | mapper.modified = False |
||
| 160 | |||
| 161 | expect(mapper.modified).is_false() |
||
| 162 | |||
| 163 | def can_be_set_true(mapper): |
||
| 164 | mapper.modified = True |
||
| 165 | |||
| 166 | expect(mapper.modified).is_true() |
||
| 167 | |||
| 168 | def describe_text(): |
||
| 169 | |||
| 170 | def can_get_the_file_contents(obj, mapper): |
||
| 171 | obj.var3 = 42 |
||
| 172 | mapper.store() |
||
| 173 | |||
| 174 | expect(mapper.text) == "var2: 0\nvar3: 42\n" |
||
| 175 | |||
| 176 | def can_set_the_file_contents(obj, mapper): |
||
| 177 | mapper.create() |
||
| 178 | mapper.text = "var2: 42\n" |
||
| 179 | mapper.fetch() |
||
| 180 | |||
| 181 | expect(obj.var2) == 42 |
||
| 182 |
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.