|
1 | 1 | from smithy_core.deserializers import DeserializeableShape, ShapeDeserializer |
2 | | -from smithy_core.documents import Document |
| 2 | +from smithy_core.documents import Document, TypeRegistry |
3 | 3 | from smithy_core.schemas import Schema |
4 | 4 | from smithy_core.shapes import ShapeID, ShapeType |
5 | | -from smithy_core.type_registry import TypeRegistry |
6 | 5 | import pytest |
7 | 6 |
|
8 | 7 |
|
9 | | -class TestTypeRegistry: |
10 | | - def test_get(self): |
11 | | - registry = TypeRegistry({ShapeID("com.example#Test"): TestShape}) |
| 8 | +def test_get(): |
| 9 | + registry = TypeRegistry({ShapeID("com.example#Test"): TestShape}) |
12 | 10 |
|
13 | | - result = registry.get(ShapeID("com.example#Test")) |
| 11 | + result = registry.get(ShapeID("com.example#Test")) |
14 | 12 |
|
15 | | - assert result == TestShape |
| 13 | + assert result == TestShape |
16 | 14 |
|
17 | | - def test_get_sub_registry(self): |
18 | | - sub_registry = TypeRegistry({ShapeID("com.example#Test"): TestShape}) |
19 | | - registry = TypeRegistry({}, sub_registry) |
20 | 15 |
|
21 | | - result = registry.get(ShapeID("com.example#Test")) |
| 16 | +def test_get_sub_registry(): |
| 17 | + sub_registry = TypeRegistry({ShapeID("com.example#Test"): TestShape}) |
| 18 | + registry = TypeRegistry({}, sub_registry) |
22 | 19 |
|
23 | | - assert result == TestShape |
| 20 | + result = registry.get(ShapeID("com.example#Test")) |
24 | 21 |
|
25 | | - def test_get_no_match(self): |
26 | | - registry = TypeRegistry({ShapeID("com.example#Test"): TestShape}) |
| 22 | + assert result == TestShape |
27 | 23 |
|
28 | | - with pytest.raises(KeyError, match="Unknown shape: com.example#Test2"): |
29 | | - registry.get(ShapeID("com.example#Test2")) |
30 | 24 |
|
31 | | - def test_deserialize(self): |
32 | | - shape_id = ShapeID("com.example#Test") |
33 | | - registry = TypeRegistry({shape_id: TestShape}) |
| 25 | +def test_get_no_match(): |
| 26 | + registry = TypeRegistry({ShapeID("com.example#Test"): TestShape}) |
34 | 27 |
|
35 | | - result = registry.deserialize(Document("abc123", schema=TestShape.schema)) |
| 28 | + with pytest.raises(KeyError, match="Unknown shape: com.example#Test2"): |
| 29 | + registry.get(ShapeID("com.example#Test2")) |
36 | 30 |
|
37 | | - assert isinstance(result, TestShape) and result.value == "abc123" |
| 31 | + |
| 32 | +def test_deserialize(): |
| 33 | + shape_id = ShapeID("com.example#Test") |
| 34 | + registry = TypeRegistry({shape_id: TestShape}) |
| 35 | + |
| 36 | + result = registry.deserialize(Document("abc123", schema=TestShape.schema)) |
| 37 | + |
| 38 | + assert isinstance(result, TestShape) and result.value == "abc123" |
38 | 39 |
|
39 | 40 |
|
40 | 41 | class TestShape(DeserializeableShape): |
|
0 commit comments