aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/wcwidth/py2/tests/test_ucslevel.py
blob: 654e835fc721e78030d0b9fafe5bff33e4d2bd74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# coding: utf-8
"""Unicode version level tests for wcwidth."""
# std imports
import warnings

# 3rd party
import pytest

# local
import wcwidth


def test_latest():
    """wcwidth._wcmatch_version('latest') returns tail item."""
    # given,
    expected = wcwidth.list_versions()[-1]

    # exercise,
    result = wcwidth._wcmatch_version('latest')

    # verify.
    assert result == expected


def test_exact_410_str():
    """wcwidth._wcmatch_version('4.1.0') returns equal value (str)."""
    # given,
    given = expected = '4.1.0'

    # exercise,
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_exact_410_unicode():
    """wcwidth._wcmatch_version(u'4.1.0') returns equal value (unicode)."""
    # given,
    given = expected = u'4.1.0'

    # exercise,
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_505_str():
    """wcwidth._wcmatch_version('5.0.5') returns nearest '5.0.0'. (str)"""
    # given
    given, expected = '5.0.5', '5.0.0'

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_505_unicode():
    """wcwidth._wcmatch_version(u'5.0.5') returns nearest u'5.0.0'. (unicode)"""
    # given
    given, expected = u'5.0.5', u'5.0.0'

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_lowint40_str():
    """wcwidth._wcmatch_version('4.0') returns nearest '4.1.0'."""
    # given
    given, expected = '4.0', '4.1.0'
    warnings.resetwarnings()
    wcwidth._wcmatch_version.cache_clear()

    # exercise
    with pytest.warns(UserWarning):
        # warns that given version is lower than any available
        result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_lowint40_unicode():
    """wcwidth._wcmatch_version(u'4.0') returns nearest u'4.1.0'."""
    # given
    given, expected = u'4.0', u'4.1.0'
    warnings.resetwarnings()
    wcwidth._wcmatch_version.cache_clear()

    # exercise
    with pytest.warns(UserWarning):
        # warns that given version is lower than any available
        result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_800_str():
    """wcwidth._wcmatch_version('8') returns nearest '8.0.0'."""
    # given
    given, expected = '8', '8.0.0'

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_800_unicode():
    """wcwidth._wcmatch_version(u'8') returns nearest u'8.0.0'."""
    # given
    given, expected = u'8', u'8.0.0'

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_999_str():
    """wcwidth._wcmatch_version('999.0') returns nearest (latest)."""
    # given
    given, expected = '999.0', wcwidth.list_versions()[-1]

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nearest_999_unicode():
    """wcwidth._wcmatch_version(u'999.0') returns nearest (latest)."""
    # given
    given, expected = u'999.0', wcwidth.list_versions()[-1]

    # exercise
    result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nonint_unicode():
    """wcwidth._wcmatch_version(u'x.y.z') returns latest (unicode)."""
    # given
    given, expected = u'x.y.z', wcwidth.list_versions()[-1]
    warnings.resetwarnings()
    wcwidth._wcmatch_version.cache_clear()

    # exercise
    with pytest.warns(UserWarning):
        # warns that given version is not valid
        result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected


def test_nonint_str():
    """wcwidth._wcmatch_version(u'x.y.z') returns latest (str)."""
    # given
    given, expected = 'x.y.z', wcwidth.list_versions()[-1]
    warnings.resetwarnings()
    wcwidth._wcmatch_version.cache_clear()

    # exercise
    with pytest.warns(UserWarning):
        # warns that given version is not valid
        result = wcwidth._wcmatch_version(given)

    # verify.
    assert result == expected