Passed
Pull Request — develop (#152)
by Jace
01:44
created

Bar.__init__()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
1
# pylint: disable=blacklisted-name,expression-not-assigned,no-member
2
3
import log
4
5
import yorm
6
7
from . import strip
8
9
10
@yorm.attr(var1=yorm.types.String)
11
@yorm.attr(var2=yorm.types.String)
12
@yorm.attr(var3=yorm.types.String)
13
class Foo(yorm.types.Dictionary):  # TODO: Eventually get rid of this base
14
15
    def __init__(self, var1='a', var2=None, var3=None):
16
        super().__init__()  # TODO: Eventually get rid of this line
17
        self.var1 = var1
18
        self.var2 = var2 or 'b'
19
        self.var3 = var3
20
21
22
@yorm.attr(var1=yorm.types.String)
23
@yorm.attr(var2=yorm.types.String)
24
@yorm.attr(var3=yorm.types.String)
25
@yorm.attr(foo=Foo)  # TODO: Eventually get rid of this line
26
@yorm.sync("sample.yml")
27
class Bar:
28
29
    def __init__(self, var1='c', var2=None, var3=None, foo=None):
30
        self.var1 = var1
31
        self.var2 = var2 or 'd'
32
        self.var3 = var3
33
        self.foo = foo or Foo()
34
35
36
# def test_init_defaults_are_applied_when_blank(expect, tmpdir):
37
#     tmpdir.chdir()
38
#     bar = Bar()
39
40
#     log.info('#' * 80)
41
42
#     bar.__mapper__.text = ""
43
44
#     log.info('#' * 80)
45
46
#     expect(bar.var1) == 'c'
47
#     expect(bar.var2) == 'd'
48
#     expect(bar.var3) == ''
49
#     expect(bar.foo.var1) == 'a'
50
#     expect(bar.foo.var2) == 'b'
51
#     expect(bar.foo.var3) == ''
52
53
54
# def test_init_defaults_are_applied_when_attributes_are_missing(expect, tmpdir):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (81/79).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
55
#     tmpdir.chdir()
56
#     bar = Bar()
57
58
#     log.info('#' * 80)
59
60
#     bar.__mapper__.text = strip("""
61
#     var3: e
62
#     foo:
63
#       var3: f
64
#     """)
65
66
#     log.info('#' * 80)
67
68
#     expect(bar.var1) == 'c'
69
#     expect(bar.var2) == 'd'
70
#     expect(bar.var3) == 'e'
71
#     expect(bar.foo.var1) == 'a'
72
#     expect(bar.foo.var2) == 'b'
73
#     expect(bar.foo.var3) == 'f'
74
75
76
def test_init_defaults_are_ignored_when_attributes_exist(expect, tmpdir):
77
    tmpdir.chdir()
78
    bar = Bar()
79
80
    log.info('#' * 80)
81
82
    bar.__mapper__.text = strip("""
83
    var1: bar-var1
84
    var2: bar-var2
85
    var3: bar-var3
86
    foo:
87
      var1: foo-var1
88
      var2: foo-var2
89
      var3: foo-var3
90
    """)
91
92
    log.info('#' * 80)
93
94
    expect(bar.var1) == 'bar-var1'
95
    expect(bar.var2) == 'bar-var2'
96
    expect(bar.var3) == 'bar-var3'
97
    expect(bar.foo.var1) == 'foo-var1'
98
    expect(bar.foo.var2) == 'foo-var2'
99
    expect(bar.foo.var3) == 'foo-var3'
100