1212import unittest
1313import logging
1414
15- from h5json .shape_util import getShapeClass , getShapeDims , getNumElements , getRank
15+ from h5json .shape_util import getShapeClass , getShapeDims , getNumElements , getRank , getShapeJson
1616from h5json .shape_util import isNullSpace , isScalar , getDataSize , isExtensible , getMaxDims
1717
1818
@@ -23,6 +23,64 @@ def __init__(self, *args, **kwargs):
2323 self .logger = logging .getLogger ()
2424 self .logger .setLevel (logging .WARNING )
2525
26+ def testGetShape (self ):
27+
28+ null_shape = getShapeJson ("H5S_NULL" )
29+ self .assertTrue ("class" in null_shape )
30+ self .assertEqual (null_shape ["class" ], "H5S_NULL" )
31+ self .assertFalse ("dims" in null_shape )
32+ self .assertFalse ("maxdims" in null_shape )
33+
34+ null_shape = getShapeJson (None )
35+ self .assertTrue ("class" in null_shape )
36+ self .assertEqual (null_shape ["class" ], "H5S_NULL" )
37+ self .assertFalse ("dims" in null_shape )
38+ self .assertFalse ("maxdims" in null_shape )
39+
40+ scalar_shape = getShapeJson (())
41+ self .assertTrue ("class" in scalar_shape )
42+ self .assertEqual (scalar_shape ["class" ], "H5S_SCALAR" )
43+ self .assertTrue ("dims" not in scalar_shape )
44+ self .assertFalse ("maxdims" in scalar_shape )
45+
46+ simple_shape = getShapeJson (42 )
47+ self .assertTrue ("class" in simple_shape )
48+ self .assertEqual (simple_shape ["class" ], "H5S_SIMPLE" )
49+ self .assertTrue ("dims" in simple_shape )
50+ self .assertEqual (simple_shape ["dims" ], (42 , ))
51+ self .assertFalse ("maxdims" in simple_shape )
52+
53+ simple_shape = getShapeJson ((42 , ))
54+ self .assertTrue ("class" in simple_shape )
55+ self .assertEqual (simple_shape ["class" ], "H5S_SIMPLE" )
56+ self .assertTrue ("dims" in simple_shape )
57+ self .assertEqual (simple_shape ["dims" ], (42 , ))
58+ self .assertFalse ("maxdims" in simple_shape )
59+
60+ extendable_shape = getShapeJson ((4 , 5 ), maxdims = ("H5S_UNLIMITED" , 10 ))
61+ self .assertTrue ("class" in extendable_shape )
62+ self .assertEqual (extendable_shape ["class" ], "H5S_SIMPLE" )
63+ self .assertTrue ("dims" in extendable_shape )
64+ self .assertEqual (extendable_shape ["dims" ], (4 , 5 ))
65+ self .assertTrue ("maxdims" in extendable_shape )
66+ self .assertTrue (extendable_shape ["maxdims" ], ("H5S_UNLIMITED" , 10 ))
67+
68+ extendable_shape = getShapeJson ((4 , 5 ), maxdims = (None , 10 ))
69+ self .assertTrue ("class" in extendable_shape )
70+ self .assertEqual (extendable_shape ["class" ], "H5S_SIMPLE" )
71+ self .assertTrue ("dims" in extendable_shape )
72+ self .assertEqual (extendable_shape ["dims" ], (4 , 5 ))
73+ self .assertTrue ("maxdims" in extendable_shape )
74+ self .assertTrue (extendable_shape ["maxdims" ], ("H5S_UNLIMITED" , 10 ))
75+
76+ extendable_shape = getShapeJson ((4 , 5 ), maxdims = (0 , 10 ))
77+ self .assertTrue ("class" in extendable_shape )
78+ self .assertEqual (extendable_shape ["class" ], "H5S_SIMPLE" )
79+ self .assertTrue ("dims" in extendable_shape )
80+ self .assertEqual (extendable_shape ["dims" ], (4 , 5 ))
81+ self .assertTrue ("maxdims" in extendable_shape )
82+ self .assertTrue (extendable_shape ["maxdims" ], ("H5S_UNLIMITED" , 10 ))
83+
2684 def testSimple (self ):
2785
2886 type_json = {
0 commit comments