1+ from typing import Dict , List
2+
13import numpy as np
24import pytest
3- from typing import Dict , List
5+ from orjson import orjson
46
57from docarray import DocList
68from docarray .base_doc import AnyDoc , BaseDoc
9+ from docarray .base_doc .io .json import orjson_dumps_and_decode
710from docarray .typing import NdArray
11+ from docarray .typing .tensor .abstract_tensor import AbstractTensor
812
913
1014def test_any_doc ():
@@ -36,7 +40,7 @@ class InnerDoc(BaseDoc):
3640 class DocTest (BaseDoc ):
3741 text : str
3842 tags : Dict [str , int ]
39- l : List [int ]
43+ l_ : List [int ]
4044 d : InnerDoc
4145 ld : DocList [InnerDoc ]
4246
@@ -46,14 +50,14 @@ class DocTest(BaseDoc):
4650 DocTest (
4751 text = 'type1' ,
4852 tags = {'type' : 1 },
49- l = [1 , 2 ],
53+ l_ = [1 , 2 ],
5054 d = inner_doc ,
5155 ld = DocList [InnerDoc ]([inner_doc ]),
5256 ),
5357 DocTest (
5458 text = 'type2' ,
5559 tags = {'type' : 2 },
56- l = [1 , 2 ],
60+ l_ = [1 , 2 ],
5761 d = inner_doc ,
5862 ld = DocList [InnerDoc ]([inner_doc ]),
5963 ),
@@ -71,7 +75,7 @@ class DocTest(BaseDoc):
7175 for i , d in enumerate (aux ):
7276 assert d .tags ['type' ] == i + 1
7377 assert d .text == f'type{ i + 1 } '
74- assert d .l == [1 , 2 ]
78+ assert d .l_ == [1 , 2 ]
7579 if protocol == 'proto' :
7680 assert isinstance (d .d , AnyDoc )
7781 assert d .d .text == 'I am inner' # inner Document is a Dict
@@ -89,3 +93,20 @@ class DocTest(BaseDoc):
8993 assert isinstance (d .ld [0 ], dict )
9094 assert d .ld [0 ]['text' ] == 'I am inner'
9195 assert d .ld [0 ]['t' ] == {'a' : 'b' }
96+
97+
98+ def test_subclass_config ():
99+ class MyDoc (BaseDoc ):
100+ x : str
101+
102+ class Config (BaseDoc .Config ):
103+ arbitrary_types_allowed = True # just an example setting
104+
105+ assert MyDoc .Config .json_loads == orjson .loads
106+ assert MyDoc .Config .json_dumps == orjson_dumps_and_decode
107+ assert (
108+ MyDoc .Config .json_encoders [AbstractTensor ](3 ) == 3
109+ ) # dirty check that it is identity
110+ assert MyDoc .Config .validate_assignment
111+ assert not MyDoc .Config ._load_extra_fields_from_protobuf
112+ assert MyDoc .Config .arbitrary_types_allowed
0 commit comments