Conditions | 12 |
Total Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like describe_data() 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=misplaced-comparison-constant,unused-variable |
||
8 | def describe_data(): |
||
9 | |||
10 | @pytest.fixture |
||
11 | def data(): |
||
12 | return Data() |
||
13 | |||
14 | def describe_repr(): |
||
15 | |||
16 | def it_should_always_be_a_simple_name(data): |
||
17 | assert "settings" == repr(data) |
||
18 | |||
19 | def describe_modified(): |
||
20 | |||
21 | def is_false_initially(data): |
||
22 | assert False is data.modified |
||
23 | |||
24 | def is_true_when_the_counter_changes(data): |
||
25 | data.status.counter += 1 |
||
26 | |||
27 | assert True is data.modified |
||
28 | |||
29 | def is_false_after_reading(data): |
||
30 | data.status.counter += 1 |
||
31 | |||
32 | print(data.modified) |
||
33 | |||
34 | assert False is data.modified |
||
35 |