File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1010# specific language governing permissions and limitations under the License.
1111
1212import dataclasses
13+ import json
14+ from typing import TypedDict
1315
1416import avro .schema
1517import orjson
1618
1719import py_avro_schema as pas
20+ from py_avro_schema ._alias import register_type_alias , register_type_aliases
1821
1922
2023def test_package_has_version ():
@@ -43,3 +46,21 @@ class PyType:
4346 json_data = pas .generate (PyType )
4447 assert json_data == orjson .dumps (expected )
4548 assert avro .schema .parse (json_data )
49+
50+
51+ def test_avro_type_aliases ():
52+ @register_type_aliases (aliases = ["test_avro_schema.VeryOldDict" , "test_avro_schema.OldDict" ])
53+ class PyTypedDict (TypedDict ):
54+ value : str
55+
56+ json_data = pas .generate (PyTypedDict )
57+ assert json .loads (json_data )["aliases" ] == ["test_avro_schema.OldDict" , "test_avro_schema.VeryOldDict" ]
58+
59+ register_type_alias (alias = "test_avro_schema.SuperOldDict" )(PyTypedDict )
60+ pas .generate .cache_clear ()
61+ json_data = pas .generate (PyTypedDict )
62+ assert json .loads (json_data )["aliases" ] == [
63+ "test_avro_schema.OldDict" ,
64+ "test_avro_schema.SuperOldDict" ,
65+ "test_avro_schema.VeryOldDict" ,
66+ ]
You can’t perform that action at this time.
0 commit comments