Completed
Push — develop ( a3345f...b4f58a )
by Jace
04:25
created

yorm.test.TestObject   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %
Metric Value
dl 0
loc 29
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B yorm.test.describe_object() 0 22 5
A yorm.test.describe_to_value() 0 5 4
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
    ]
46
    pairs_to_data = pairs + [
47
        (42, 42),
48
        (4.2, 4.2),
49
    ]
50
51
    def describe_to_value():
52
53
        @pytest.mark.parametrize("first,second", pairs_to_value)
54
        def it_converts_correctly(first, second):
55
            expect(String.to_value(first)) == second
56
57
    def describe_to_data():
58
59
        @pytest.mark.parametrize("first,second", pairs_to_data)
60
        def it_converts_correctly(first, second):
61
            expect(String.to_data(first)) == second
62
63
64
def describe_integer():
65
66
    obj = 42
67
    pairs = [
68
        (obj, obj),
69
        (None, 0),
70
        ("1", 1),
71
        ("1.1", 1),
72
        (True, 1),
73
        (False, 0),
74
    ]
75
76
    def describe_to_value():
77
78
        @pytest.mark.parametrize("first,second", pairs)
79
        def it_converts_correctly(first, second):
80
            expect(Integer.to_value(first)) == second
81
82
        def it_raises_an_exception_when_unable_to_convert():
83
            with expect.raises(ValueError):
84
                Integer.to_value("abc")
85
86
    def describe_to_data():
87
88
        @pytest.mark.parametrize("first,second", pairs)
89
        def it_converts_correctly(first, second):
90
            expect(Integer.to_data(first)) == second
91
92
93
def describe_float():
94
95
    obj = 4.2
96
    pairs = [
97
        (obj, obj),
98
        (None, 0.0),
99
        ("1.0", 1.0),
100
        ("1.1", 1.1),
101
    ]
102
103
    def describe_to_value():
104
105
        @pytest.mark.parametrize("first,second", pairs)
106
        def it_converts_correctly(first, second):
107
            expect(Float.to_value(first)) == second
108
109
        def it_raises_an_exception_when_unable_to_convert():
110
            with expect.raises(ValueError):
111
                Float.to_value("abc")
112
113
    def describe_to_data():
114
115
        @pytest.mark.parametrize("first,second", pairs)
116
        def it_converts_correctly(first, second):
117
            expect(Float.to_data(first)) == second
118
119
120
def describe_boolean():
121
122
    obj = True
123
    pairs = [
124
        (obj, obj),
125
        (None, False),
126
        (0, False),
127
        (1, True),
128
        ("", False),
129
        ("True", True),
130
        ("False", False),
131
        ("true", True),
132
        ("false", False),
133
        ("T", True),
134
        ("F", False),
135
        ("yes", True),
136
        ("no", False),
137
        ("Y", True),
138
        ("N", False),
139
        ("enabled", True),
140
        ("disabled", False),
141
        ("on", True),
142
        ("off", False),
143
        ("Hello, world!", True)
144
    ]
145
146
    def describe_to_value():
147
148
        @pytest.mark.parametrize("first,second", pairs)
149
        def it_converts_correctly(first, second):
150
            expect(Boolean.to_value(first)) == second
151
152
    def describe_to_data():
153
154
        @pytest.mark.parametrize("first,second", pairs)
155
        def it_converts_correctly(first, second):
156
            expect(Boolean.to_data(first)) == second
157