Completed
Push — develop ( 7d38f7...827c8b )
by Jace
02:04
created

describe_model_mixin()   D

Complexity

Conditions 9

Size

Total Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 60
rs 4.9523
cc 9

How to fix   Long Method   

Long Method

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:

1
# pylint: disable=unused-variable,expression-not-assigned
2
3
from unittest.mock import patch, call
4
5
import pytest
6
from expecter import expect
7
8
import yorm
9
from yorm.mixins import ModelMixin
10
11
12
def describe_model_mixin():
13
14
    @pytest.fixture
15
    def mixed_class():
16
17
        @yorm.sync("tmp/model.yml")
18
        class MyClass(ModelMixin):
19
            pass
20
21
        return MyClass
22
23
    @pytest.fixture
24
    def mixed_instance(mixed_class):
25
        return mixed_class()
26
27
    @patch('yorm.mixins.utilities')
28
    def it_adds_a_new_method(utilities, mixed_class):
29
        mixed_class.new('foobar', overwrite=True)
30
31
        expect(utilities.mock_calls) == [
32
            call.create(mixed_class, 'foobar', overwrite=True)
33
        ]
34
35
    @patch('yorm.mixins.utilities')
36
    def it_adds_a_find_method(utilities, mixed_class):
37
        mixed_class.find('foobar', create=True)
38
39
        expect(utilities.mock_calls) == [
40
            call.find(mixed_class, 'foobar', create=True)
41
        ]
42
43
    @patch('yorm.mixins.utilities')
44
    def it_adds_a_match_method(utilities, mixed_class):
45
        mixed_class.match(foo='bar')
46
47
        expect(utilities.mock_calls) == [
48
            call.match(mixed_class, foo='bar')
49
        ]
50
51
    @patch('yorm.mixins.utilities')
52
    def it_adds_a_load_method(utilities, mixed_instance):
53
        mixed_instance.load()
54
55
        expect(utilities.mock_calls) == [
56
            call.load(mixed_instance)
57
        ]
58
59
    @patch('yorm.mixins.utilities')
60
    def it_adds_a_save_method(utilities, mixed_instance):
61
        mixed_instance.save()
62
63
        expect(utilities.mock_calls) == [
64
            call.save(mixed_instance)
65
        ]
66
67
    @patch('yorm.mixins.utilities')
68
    def it_adds_a_delete_method(utilities, mixed_instance):
69
        mixed_instance.delete()
70
71
        expect(utilities.mock_calls) == [
72
            call.delete(mixed_instance)
73
        ]
74