Passed
Pull Request — develop (#152)
by Jace
01:30
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(foo1=yorm.types.String)
11
@yorm.attr(foo2=yorm.types.String)
12
@yorm.attr(foo3=yorm.types.String)
13
class Foo(yorm.types.Dictionary):  # TODO: Eventually get rid of this base
14
15
    def __init__(self, foo1='a', foo2=None, foo3=None):
16
        super().__init__()  # TODO: Eventually get rid of this line
17
        log.critical("6.0 ### %s", (foo1, foo2, foo3))
18
        self.foo1 = foo1
19
        self.foo2 = foo2 or 'b'
20
        self.foo3 = foo3
21
22
23
@yorm.attr(bar1=yorm.types.String)
24
@yorm.attr(bar2=yorm.types.String)
25
@yorm.attr(bar3=yorm.types.String)
26
@yorm.attr(foo=Foo)  # TODO: Eventually get rid of this line
27
@yorm.sync("sample.yml")
28
class Bar:
29
30
    def __init__(self, bar1='c', bar2=None, bar3=None, foo=None):
31
        self.bar1 = bar1
32
        self.bar2 = bar2 or 'd'
33
        self.bar3 = bar3
34
        self.foo = foo or Foo()
35
36
37
# def test_init_defaults_are_applied_when_blank(expect, tmpdir):
38
#     tmpdir.chdir()
39
#     bar = Bar()
40
41
#     log.info('#' * 80)
42
43
#     bar.__mapper__.text = ""
44
45
#     log.info('#' * 80)
46
47
#     expect(bar.var1) == 'c'
48
#     expect(bar.var2) == 'd'
49
#     expect(bar.var3) == ''
50
#     expect(bar.foo.var1) == 'a'
51
#     expect(bar.foo.var2) == 'b'
52
#     expect(bar.foo.var3) == ''
53
54
55
# 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...
56
#     tmpdir.chdir()
57
#     bar = Bar()
58
59
#     log.info('#' * 80)
60
61
#     bar.__mapper__.text = strip("""
62
#     var3: e
63
#     foo:
64
#       var3: f
65
#     """)
66
67
#     log.info('#' * 80)
68
69
#     expect(bar.var1) == 'c'
70
#     expect(bar.var2) == 'd'
71
#     expect(bar.var3) == 'e'
72
#     expect(bar.foo.var1) == 'a'
73
#     expect(bar.foo.var2) == 'b'
74
#     expect(bar.foo.var3) == 'f'
75
76
77
def test_init_defaults_are_ignored_when_attributes_exist(expect, tmpdir):
78
    tmpdir.chdir()
79
    bar = Bar()
80
81
    log.info('#' * 80)
82
83
    bar.__mapper__.text = strip("""
84
    bar1: bar1
85
    bar2: bar2
86
    bar3: bar3
87
    foo:
88
      foo1: foo1
89
      foo2: foo2
90
      foo3: foo3
91
    """)
92
93
    log.info('#' * 80)
94
95
    expect(bar.bar1) == 'bar1'
96
    expect(bar.bar2) == 'bar2'
97
    expect(bar.bar3) == 'bar3'
98
    expect(bar.foo.foo1) == 'foo1'
99
    expect(bar.foo.foo2) == 'foo2'
100
    expect(bar.foo.foo3) == 'foo3'
101