
    wdX"                        d dl mZmZmZ d dlZd dlZd dlZd dlZd dlmZm	Z	m
Z
mZ  G d dej                  Zej        ej        dej        ej        ddZej                            dd	d
g          d             ZdS )    )absolute_importdivisionprint_functionN)dshapeerror	DataShapeRecordc                   \   e Zd Zd Zd Zd Zd Zej        	                    d          d             Z
d Zej        	                    d	          d
             Zej        	                    d	          d             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zg dZg dZd ZdS )TestDataShapeCreationc                 $   |                      t          t          d            |                      t          t          d            |                      t          j        t          d           |                      t          j        t          d           d S )Nc                     | dz   S )N    )xs    =lib/python3.11/site-packages/datashape/tests/test_creation.py<lambda>z?TestDataShapeCreation.test_raise_on_bad_input.<locals>.<lambda>   s
    qs     z1 *z1,)assertRaises	TypeErrorr   	datashapeDataShapeSyntaxErrorselfs    r   test_raise_on_bad_inputz-TestDataShapeCreation.test_raise_on_bad_input   sp    )VT222)V]];;;)8&%HHH)8&$GGGGGr   c                 H    |                      t          t          d           d S )Nbigint)r   	Exceptionr   r   s    r   test_reserved_future_bigintz1TestDataShapeCreation.test_reserved_future_bigint   s     )VX66666r   c                    |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j	                             |                      t          d          t          t          j
                             |                      t          d	          t          t          j                             |                      t          d
          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          d                     |                      t          d          t          d                     |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             |                      t          d          t          t          j                             d S )Nboolint8int16int32int64uint8uint16uint32uint64float32float64	complex64
complex128zcomplex[float32]zcomplex[float64]stringjsondatetimedatetime)assertEqualr   r   bool_r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   date_time_	datetime_r   s    r   test_atom_shapesz&TestDataShapeCreation.test_atom_shapes   s   	)@)@AAA	)?)?@@@&*A*ABBB&*A*ABBB&*A*ABBB&*A*ABBB))6)2B+C+CDDD))6)2B+C+CDDD))6)2B+C+CDDD	**F93D,E,EFFF	**F93D,E,EFFF,,fY5H.I.IJJJ--vi6J/K/KLLL,,f5G.H.HIII--v6H/I/IJJJ))6)2B+C+CDDD	)?)?@@@	)@)@AAA	)@)@AAA
++VI4G-H-HIIIIIr   c                 6   |                      t          j        t          d           |                      t          j        t          d           |                      t          j        t          d           |                      t          j        t          d           d S )Nbootint3312varr   r   r   r   r   s    r   test_atom_shape_errorsz,TestDataShapeCreation.test_atom_shape_errors0   st    %4ffEEE%4fgFFF%4fdCCC%4feDDDDDr   z5implements has not been implemented in the new parser)reasonc                 R    |                      t          j        t          d           d S )NzA : integral * B : numericr   r   DataShapeTypeErrorr   r   s    r   test_constraints_errorz,TestDataShapeCreation.test_constraints_error6   s.    %2F6	8 	8 	8 	8 	8r   c                     |                      t          j        t          d           |                      t          j        t          d           d S )NzT * ...zT * S...r=   r   s    r   test_ellipsis_errorz)TestDataShapeCreation.test_ellipsis_error;   s>    %4fiHHH%4fjIIIIIr   z,type decl has been removed in the new parserc                 R    |                      t          j        t          d           d S )Nztype X T = 3, TrA   r   s    r   test_type_declz$TestDataShapeCreation.test_type_decl?   s$    %2F<MNNNNNr   c                 f    |                      t          d          t          d                     d S )Nz3, int32ztype X = 3, int32)r2   r   r   s    r   test_type_decl_concretez-TestDataShapeCreation.test_type_decl_concreteC   s/    
++V4G-H-HIIIIIr   c                 F   |                      t          d          t          d                     |                      t          d          d         j        d           |                      t          d          d         j        d           |                      t          d          d         j        d           |                      t          d          d         j        d           |                      t          d	          d         j        d
           |                      t          d          d         j        d
           |                      t          d          d         j        d           |                      t          d          d         j        d           d S )Nr-   zstring['U8']zstring['ascii']r   Azstring['A']zstring['utf-8']U8zstring['utf-16']U16zstring['U16']zstring['utf-32']U32zstring['U32'])r2   r   encodingr   s    r   test_string_atomz&TestDataShapeCreation.test_string_atomG   sb   ))6.+A+ABBB 12215>DDD..q1:C@@@ 12215>EEE//2;TBBB 233A6?GGG003<eDDD 233A6?GGG003<eDDDDDr   c                 z   |                      t          d          d         j        d            |                      t          d          d         j        d           |                      t          d          d         j        d           |                      t          t          d                    d           d S )Nr0   r   ztime[tz="UTC"]UTCztime[tz="America/Vancouver"]America/Vancouverztime[tz='UTC']r2   r   tzstrr   s    r   	test_timezTestDataShapeCreation.test_timeR   s    *-t444 011!47??? >??BE,	. 	. 	.V$455668HIIIIIr   c                 z   |                      t          d          d         j        d            |                      t          d          d         j        d           |                      t          d          d         j        d           |                      t          t          d                    d           d S )Nr1   r   zdatetime[tz="UTC"]rR   z datetime[tz="America/Vancouver"]rS   zdatetime[tz='UTC']rT   r   s    r   test_datetimez#TestDataShapeCreation.test_datetimeY   s    
++A.14888 455a8;UCCC BCCAFI,	. 	. 	.V$899::-	/ 	/ 	/ 	/ 	/r   c                    |                      t          d          d         j        d           |                      t          d          d         j        t          d                     |                      t          d          d         j        d           |                      t          d          d         j        t          d                     d S )Nzunits["second"]r   secondr*   zunits["second", int32]r#   )r2   r   unittpr   s    r   
test_unitsz TestDataShapeCreation.test_unitsa   s     12215:HEEE 122158&:K:KLLL 899!<A8LLL 899!<?	* 	* 	* 	* 	*r   c                     |                      t          d          t          t          g                                d S )Nz{})r2   r   r   r	   r   s    r   test_empty_structz'TestDataShapeCreation.test_empty_structh   s2    y'<'<=====r   c                 &   |                      t          t          d                    d           |                      t          t          d                    d           |                      t          t          d                    d           d S )Nz	5 * int32z{field: 5 * int32}z{field: M * int32})r2   rV   r   r   s    r   test_struct_of_arrayz*TestDataShapeCreation.test_struct_of_arrayk   s    VK0011;???V$899::-	/ 	/ 	/V$899::-	/ 	/ 	/ 	/ 	/r   c                     |                      t          t          d          d         t          j                             d S )Nz3 * var * int32r   )
assertTrue
isinstancer   r   Varr   s    r   test_ragged_arrayz'TestDataShapeCreation.test_ragged_arrayr   sC    
6*;#<#<Q#?!' ' 	( 	( 	( 	( 	(r   c                    dd l }|                    d          }t          j        d|          }|                     |j        g d           |                     |j        t          j        t          j        t          j	        g           d S )Nr   zi4,i8,f8r   )f0f1f2)
numpydtyper   
from_numpyr2   namestypesr#   r$   r*   )r   npdtdss       r   test_from_numpy_fieldsz,TestDataShapeCreation.test_from_numpy_fieldsv   s    XXj!!!"b))#5#5#5666#/9?I<MN	P 	P 	P 	P 	Pr   c                     dd l }t          j        d          }t          j        |          \  }}|                     |d           |                     ||                    ddg                     d S )Nr   z{x: int32, y: float32}r   )r   r#   )yr)   )rl   r   r   to_numpyr2   rm   )r   rq   rs   shaperr   s        r   test_to_numpy_fieldsz*TestDataShapeCreation.test_to_numpy_fields~   sw    677&r**	r###RXX~7G&HIIJJJJJr   c                    |                      t          j        d          t          d          z  t          d                     |                      dt          d          z  t          d                     |                      t          j                    t          d          z  t          d                     |                      t          j                    t          j        z  t          d                     |                      t          j                    dz  t          d                     |                      dt          j        z  t          d                     d S )N   r#   	3 * int32zvar * int32)r2   r   Fixedr   rf   r#   r   s    r   test_syntaxz!TestDataShapeCreation.test_syntax   s:   ++fWoo=,,	. 	. 	.VG__,,,	. 	. 	.6'??:..	0 	0 	09?:..	0 	0 	072..	0 	0 	0Y_,,,	. 	. 	. 	. 	.r   c                 r   t          j                    }t           j        }|                     t	          d          t	          d|f                     |                     t	          d          t	          d|g                     |                     t	          d          t	          |d|f                     d S )Nr|   r{   zvar * 3 * int32)r   rf   r#   r2   r   )r   r<   r#   s      r   test_python_containersz,TestDataShapeCreation.test_python_containers   s    moo,,E
++	- 	- 	-,,E
++	- 	- 	- 122a00	2 	2 	2 	2 	2r   )r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   intrealcomplexintptruintptrz&{id: int8, value: bool, result: int16}z4{a: int32, b: int64, x: uint8, y: uint16, z: uint32}zi{a: float32, b: float64, c: complex64, d: complex128,  e: string, f: json, g: date, h: time, i: datetime})2100z...r<   z2 * var * 2c           
      L   | j         D ]}|                     t          t          t	          |                              t	          |                     | j        D ]G}t	          |dz   |z             }|                     t          t          |                    |           Hd S )Nz * )dshapesr2   evalreprr   
dimensions)r   rs   dmds       r   test_dshape_into_reprz+TestDataShapeCreation.test_dshape_into_repr   s    , 	3 	3BT$vbzz"2"233VBZZ@@@o 3 32:?++  d1gg22223	3 	3r   N)__name__
__module____qualname__r   r   r7   r>   pytestmarkxfailrC   rE   rG   rI   rP   rW   rY   r^   r`   rb   rg   rt   ry   r~   r   r   r   r   r   r   r   r   r      s       H H H7 7 7J J J,E E E [UVV8 8 WV8J J J [LMMO O NMO [LMMJ J NMJ	E 	E 	EJ J J/ / /* * *> > >/ / /( ( (P P PK K K. . .2 2 2F F FG8  J3 3 3 3 3r   r   )r   r   )      kindr   r   c                     t          |           t          t          t          j        t          j                           |                    k    sJ d S )N)r   pointer_sizesctypessizeofc_void_p)r   s    r   test_intptr_sizer      sP    4LL=v!?!?@FGGH I I I I Ir   )
__future__r   r   r   r   unittestr   r   r   r   r   r	   TestCaser   r#   r'   r$   r(   r   r   parametrizer   r   r   r   <module>r      s    @ @ @ @ @ @ @ @ @ @        6 6 6 6 6 6 6 6 6 6 6 6y3 y3 y3 y3 y3H- y3 y3 y3| /# 
 /# 	 	 (I!677I I 87I I Ir   