2222OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323THE SOFTWARE.
2424"""
25+ import pytest
26+
27+ import numpy as np
2528
2629import logging
2730logger = logging .getLogger (__name__ )
2831
2932
33+ # {{{ test_pt_actx_key_stringification_uniqueness
34+
3035def test_pt_actx_key_stringification_uniqueness ():
3136 from arraycontext .impl .pytato .compile import _ary_container_key_stringifier
3237
@@ -36,13 +41,63 @@ def test_pt_actx_key_stringification_uniqueness():
3641 assert (_ary_container_key_stringifier (("tup" , 3 , "endtup" ))
3742 != _ary_container_key_stringifier (((3 ,),)))
3843
44+ # }}}
45+
46+
47+ # {{{ test_dataclass_array_container
48+
49+ def test_dataclass_array_container ():
50+ from typing import Optional
51+ from dataclasses import dataclass , field
52+ from arraycontext import dataclass_array_container
53+
54+ # {{{ string fields
55+
56+ @dataclass
57+ class ArrayContainerWithStringTypes :
58+ x : np .ndarray
59+ y : "np.ndarray"
60+
61+ with pytest .raises (TypeError ):
62+ # NOTE: cannot have string annotations in container
63+ dataclass_array_container (ArrayContainerWithStringTypes )
64+
65+ # }}}
66+
67+ # {{{ optional fields
68+
69+ @dataclass
70+ class ArrayContainerWithOptional :
71+ x : np .ndarray
72+ y : Optional [np .ndarray ]
73+
74+ with pytest .raises (TypeError ):
75+ # NOTE: cannot have wrapped annotations (here by `Optional`)
76+ dataclass_array_container (ArrayContainerWithOptional )
77+
78+ # }}}
79+
80+ # {{{ field(init=False)
81+
82+ @dataclass
83+ class ArrayContainerWithInitFalse :
84+ x : np .ndarray
85+ y : np .ndarray = field (default = np .zeros (42 ), init = False , repr = False )
86+
87+ with pytest .raises (ValueError ):
88+ # NOTE: init=False fields are not allowed
89+ dataclass_array_container (ArrayContainerWithInitFalse )
90+
91+ # }}}
92+
93+ # }}}
94+
3995
4096if __name__ == "__main__" :
4197 import sys
4298 if len (sys .argv ) > 1 :
4399 exec (sys .argv [1 ])
44100 else :
45- from pytest import main
46- main ([__file__ ])
101+ pytest .main ([__file__ ])
47102
48103# vim: fdm=marker
0 commit comments