1 | # pylint: disable=redefined-outer-name,expression-not-assigned,attribute-defined-outside-init,no-member |
||
2 | |||
3 | from expecter import expect |
||
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): |
||
0 ignored issues
–
show
|
|||
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): |
||
0 ignored issues
–
show
The name
test_existing_files_are_reorderd does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site.
Loading history...
|
|||
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 |
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.