Completed
Push — develop ( b4a21c...b1df34 )
by Jace
02:37
created

yorm.test.describe_integer()   C

Complexity

Conditions 7

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 7
dl 0
loc 27
rs 5.5

1 Method

Rating   Name   Duplication   Size   Complexity  
A it_raises_an_exception_when_unable_to_convert() 3 3 2
1
# pylint: disable=missing-docstring,unused-variable,expression-not-assigned
2
3
import pytest
4
from expecter import expect
0 ignored issues
show
Configuration introduced by
The import expecter could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
6
from yorm.types import Object, String, Integer, Float, Boolean
7
8
9
def describe_object():
10
11
    obj = None
12
    pairs = [
13
        (obj, obj),
14
        (None, None),
15
        (1, 1),
16
        (4.2, 4.2),
17
        (['a', 'b', 'c'], ['a', 'b', 'c']),
18
    ]
19
20
    def describe_to_value():
21
22
        @pytest.mark.parametrize("first,second", pairs)
23
        def it_converts_correctly(first, second):
24
            expect(Object.to_value(first)) == second
25
26
    def describe_to_data():
27
28
        @pytest.mark.parametrize("first,second", pairs)
29
        def it_converts_correctly(first, second):
30
            expect(Object.to_data(first)) == second
31
32
33
def describe_string():
34
35
    obj = "Hello, world!"
36
    pairs = [
37
        (obj, obj),
38
        (None, ""),
39
        ("1.2.3", "1.2.3"),
40
        (['a', 'b', 'c'], "a, b, c"),
41
    ]
42
    pairs_to_value = pairs + [
43
        (1, "1"),
44
        (4.2, "4.2"),
45
        (False, "false"),
46
        (True, "true"),
47
    ]
48
    pairs_to_data = pairs + [
49
        (42, 42),
50
        (4.2, 4.2),
51
        ("true", True),
52
        ("false", False),
53
    ]
54
55
    def describe_to_value():
56
57
        @pytest.mark.parametrize("first,second", pairs_to_value)
58
        def it_converts_correctly(first, second):
59
            expect(String.to_value(first)) == second
60
61
    def describe_to_data():
62
63
        @pytest.mark.parametrize("first,second", pairs_to_data)
64
        def it_converts_correctly(first, second):
65
            expect(String.to_data(first)) == second
66
67
68 View Code Duplication
def describe_integer():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
69
70
    obj = 42
71
    pairs = [
72
        (obj, obj),
73
        (None, 0),
74
        ("1", 1),
75
        ("1.1", 1),
76
        (True, 1),
77
        (False, 0),
78
    ]
79
80
    def describe_to_value():
81
82
        @pytest.mark.parametrize("first,second", pairs)
83
        def it_converts_correctly(first, second):
84
            expect(Integer.to_value(first)) == second
85
86
        def it_raises_an_exception_when_unable_to_convert():
87
            with expect.raises(ValueError):
88
                Integer.to_value("abc")
89
90
    def describe_to_data():
91
92
        @pytest.mark.parametrize("first,second", pairs)
93
        def it_converts_correctly(first, second):
94
            expect(Integer.to_data(first)) == second
95
96
97 View Code Duplication
def describe_float():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
98
99
    obj = 4.2
100
    pairs = [
101
        (obj, obj),
102
        (None, 0.0),
103
        ("1.0", 1.0),
104
        ("1.1", 1.1),
105
    ]
106
107
    def describe_to_value():
108
109
        @pytest.mark.parametrize("first,second", pairs)
110
        def it_converts_correctly(first, second):
111
            expect(Float.to_value(first)) == second
112
113
        def it_raises_an_exception_when_unable_to_convert():
114
            with expect.raises(ValueError):
115
                Float.to_value("abc")
116
117
    def describe_to_data():
118
119
        @pytest.mark.parametrize("first,second", pairs)
120
        def it_converts_correctly(first, second):
121
            expect(Float.to_data(first)) == second
122
123
124
def describe_boolean():
125
126
    obj = True
127
    pairs = [
128
        (obj, obj),
129
        (None, False),
130
        (0, False),
131
        (1, True),
132
        ("", False),
133
        ("True", True),
134
        ("False", False),
135
        ("true", True),
136
        ("false", False),
137
        ("T", True),
138
        ("F", False),
139
        ("yes", True),
140
        ("no", False),
141
        ("Y", True),
142
        ("N", False),
143
        ("enabled", True),
144
        ("disabled", False),
145
        ("on", True),
146
        ("off", False),
147
        ("Hello, world!", True)
148
    ]
149
150
    def describe_to_value():
151
152
        @pytest.mark.parametrize("first,second", pairs)
153
        def it_converts_correctly(first, second):
154
            expect(Boolean.to_value(first)) == second
155
156
    def describe_to_data():
157
158
        @pytest.mark.parametrize("first,second", pairs)
159
        def it_converts_correctly(first, second):
160
            expect(Boolean.to_data(first)) == second
161