-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathtest_utils.py
More file actions
78 lines (71 loc) · 2.4 KB
/
Copy pathtest_utils.py
File metadata and controls
78 lines (71 loc) · 2.4 KB
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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import pytest
from smithy_aws_core.utils import parse_document_discriminator, parse_error_code
from smithy_core.documents import Document
from smithy_core.shapes import ShapeID
@pytest.mark.parametrize(
"document, expected",
[
({"__type": "FooError"}, "com.test#FooError"),
({"__type": "com.test#FooError"}, "com.test#FooError"),
(
{
"__type": "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
},
"com.test#FooError",
),
(
{
"__type": "com.test#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate"
},
"com.test#FooError",
),
({"code": "FooError"}, "com.test#FooError"),
({"code": "com.test#FooError"}, "com.test#FooError"),
(
{
"code": "FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/"
},
"com.test#FooError",
),
(
{
"code": "com.test#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate"
},
"com.test#FooError",
),
({"__type": "FooError", "code": "BarError"}, "com.test#FooError"),
("FooError", None),
({"__type": None}, None),
({"__type": ""}, None),
({"__type": ":"}, None),
],
)
def test_aws_json_document_discriminator(
document: dict[str, str], expected: ShapeID | None
) -> None:
actual = parse_document_discriminator(Document(document), "com.test")
assert actual == expected
@pytest.mark.parametrize(
"code, expected",
[
("FooError", "com.test#FooError"),
(
"FooError:http://internal.amazon.com/coral/com.amazon.coral.validate/",
"com.test#FooError",
),
(
"com.test#FooError:http://internal.amazon.com/coral/com.amazon.coral.validate",
"com.test#FooError",
),
("", None),
(":", None),
],
)
def test_parse_error_code(code: str, expected: ShapeID | None) -> None:
actual = parse_error_code(code, "com.test")
assert actual == expected
def test_parse_error_code_without_default_namespace() -> None:
actual = parse_error_code("FooError", None)
assert actual is None