-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathtest_util_unicode.py
53 lines (41 loc) · 1.51 KB
/
test_util_unicode.py
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
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at:
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
# OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the
# License.
from typing import NamedTuple, Any
from pytest import raises
from tests import parametrize, is_exception, noop_manager
from amazon.ion.util import unicode_iter
def _unichr_list(val):
return list(ord(x) for x in val)
class _P(NamedTuple):
desc: str
input: str
expected: Any
def __str__(self):
return self.desc
@parametrize(
_P('ASCII', u'abcd', _unichr_list(u'abcd')),
_P('BMP SEQUENCE', u'abcd\u3000', _unichr_list(u'abcd\u3000')),
_P('NON-BMP SEQUENCE', u'abcd\U0001f4a9', _unichr_list(u'abcd') + [0x1F4A9]),
_P('UNPAIRED LOW', u'\udc00', ValueError),
_P('UNPAIRED HIGH AT END', u'\ud800', ValueError),
_P('UNPAIRED HIGH IN MID', u'\ud800a', ValueError),
)
def test_unicode_iter(p):
ctx = noop_manager()
if is_exception(p.expected):
ctx = raises(p.expected)
with ctx:
actual = list(unicode_iter(p.input))
if not is_exception(p.expected):
assert p.expected == actual