Completed
Push — develop ( e2d982...ac8aad )
by Jace
02:50
created

yorm.test.TestMarkdown   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %
Metric Value
dl 0
loc 30
rs 10
wmc 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.utilities import attr
7
from yorm.types.standard import Integer, String, Float
8
from yorm.types.extended import (NullableString, Markdown,
9
                                 AttributeDictionary, SortedList)
10
11
12
# CLASSES ######################################################################
13
14
15
@attr(var1=Integer, var2=String)
16
class SampleAttributeDictionary(AttributeDictionary):
17
    """Sample attribute dictionary."""
18
19
20
@attr(all=Float)
21
class SampleSortedList(SortedList):
22
    """Sample sorted list."""
23
24
25
class UnknownSortedList(SortedList):
26
    """Sample list."""
27
28
29
# TESTS ########################################################################
30
31
32
def describe_nullable_string():
33
34
    def describe_to_value():
35
36
        def it_allows_none():
37
            expect(NullableString.to_value(None)).is_none()
38
39
    def describe_to_data():
40
41
        def it_allows_none():
42
            expect(NullableString.to_data(None)).is_none()
43
44
45
def describe_markdown():
46
47
    obj = "This is **the** sentence."
48
    pairs_to_value = [
49
        (obj, obj),
50
        (None, ""),
51
        (['a', 'b', 'c'], "a, b, c"),
52
        ("This is\na sentence.", "This is a sentence."),
53
        ("Sentence one.\nSentence two.", "Sentence one. Sentence two."),
54
    ]
55
    pairs_to_data = [
56
        (obj, obj + '\n'),
57
        ("Sentence one. Sentence two.", "Sentence one.\nSentence two.\n"),
58
        ("", ""),
59
        (" \t ", ""),
60
    ]
61
62
    def describe_to_value():
63
64
        @pytest.mark.parametrize("first,second", pairs_to_value)
65
        def it_converts_correctly(first, second):
66
            expect(Markdown.to_value(first)) == second
67
68
    def describe_to_data():
69
70
        @pytest.mark.parametrize("first,second", pairs_to_data)
71
        def it_converts_correctly(first, second):
72
            expect(Markdown.to_data(first)) == second
73
74
75
def describe_attribute_dictionary():
76
77
    @pytest.fixture
78
    def converter():
79
        return SampleAttributeDictionary()
80
81
    def it_cannot_be_used_directly():
82
        with expect.raises(NotImplementedError):
83
            AttributeDictionary.to_value(None)
84
        with expect.raises(NotImplementedError):
85
            AttributeDictionary.to_data(None)
86
87
    def it_has_keys_available_as_attributes(converter):
88
        value = converter.to_value({'var1': 1, 'var2': "2"})
89
        expect(value.var1) == 1
90
        expect(value.var2) == "2"
91
92
93
def describe_sorted_list():
94
95
    @pytest.fixture
96
    def converter():
97
        return SampleSortedList()
98
99
    def it_cannot_be_used_directly():
100
        with expect.raises(NotImplementedError):
101
            SortedList.to_value(None)
102
        with expect.raises(NotImplementedError):
103
            SortedList.to_data(None)
104
105
    def it_cannot_be_subclassed_without_a_type():
106
        with expect.raises(NotImplementedError):
107
            UnknownSortedList.to_value(None)
108
        with expect.raises(NotImplementedError):
109
            UnknownSortedList.to_data(None)
110
111
    def describe_to_data():
112
113
        def it_sorts(converter):
114
            data = converter.to_data([4, 2, 0, 1, 3])
115
            expect(data) == [0.0, 1.0, 2.0, 3.0, 4.0]
116