Completed
Pull Request — master (#58)
by Jace
02:38
created

describe_data()   F

Complexity

Conditions 12

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 12
c 3
b 0
f 0
dl 0
loc 27
rs 2.7855

7 Methods

Rating   Name   Duplication   Size   Complexity  
A is_false_after_reading() 0 6 2
A is_false_initially() 0 2 2
B describe_modified() 0 16 7
A it_should_always_be_a_simple_name() 0 2 2
A is_true_when_the_counter_changes() 0 4 2
A data() 0 3 1
A describe_repr() 0 4 3

How to fix   Complexity   

Complexity

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
0 ignored issues
show
introduced by
Bad option value 'misplaced-comparison-constant'
Loading history...
2
3
import pytest
4
5
from mine.data import Data
6
7
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