Completed
Push — develop ( 930f7a...b4a21c )
by Jace
05:43
created

tests.test_existing_files_are_reorderd()   B

Complexity

Conditions 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 24
rs 8.9713
1
# pylint: disable=redefined-outer-name,expression-not-assigned,attribute-defined-outside-init,no-member
2
3
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...
4
5
import yorm
6
7
from . import strip
8
9
10
@yorm.attr(status=yorm.types.Boolean)
11
@yorm.attr(label=yorm.types.String)
12
class StatusDictionary(yorm.types.Dictionary):
13
    """Sample dictionary converter with ordered attributes."""
14
15
16
@yorm.attr(string=yorm.types.String)
17
@yorm.attr(number_int=yorm.types.Integer)
18
@yorm.attr(dictionary=StatusDictionary)
19
@yorm.attr(number_real=yorm.types.Float)
20
@yorm.attr(truthy=yorm.types.Boolean)
21
@yorm.attr(falsey=yorm.types.Boolean)
22
@yorm.sync("sample.yml")
23
class Sample:
24
    """Sample class with ordered attributes."""
25
26
27
def test_attribute_order_is_maintained(tmpdir):
28
    tmpdir.chdir()
29
    sample = Sample()
30
    sample.string = "Hello, world!"
31
    sample.number_int = 42
32
    sample.number_real = 4.2
33
    sample.truthy = False
34
    sample.falsey = True
35
    sample.dictionary['status'] = 1
36
37
    expect(sample.__mapper__.text) == strip("""
38
    string: Hello, world!
39
    number_int: 42
40
    dictionary:
41
      status: true
42
      label: ''
43
    number_real: 4.2
44
    truthy: false
45
    falsey: true
46
    """)
47
48
49
def test_existing_files_are_reorderd(tmpdir):
50
    tmpdir.chdir()
51
    with open("sample.yml", 'w') as stream:
52
        stream.write(strip("""
53
        falsey: 1
54
        number_int: 2
55
        number_real: 3
56
        string: 4
57
        truthy: 5
58
        dictionary: {label: foo}
59
        """))
60
    sample = Sample()
61
    sample.falsey = 0
62
63
    expect(sample.__mapper__.text) == strip("""
64
    string: 4
65
    number_int: 2
66
    dictionary:
67
      status: false
68
      label: foo
69
    number_real: 3.0
70
    truthy: true
71
    falsey: false
72
    """)
73