U
    /d                     @   sP   d dl Z d dlZd dlmZ d dlmZ eddddgdd	gZG d
d dZdS )    N)assert_equal)_make_tuple_bunchResultxyzwbetac                   @   s|  e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zejd%d&d'gd(gfd)d*gd+gfd)d'gd,gfgd-d. Zejd%d)d'd(d'gd+gfd)d'd(gd(d+gfgd/d0 Zejd%d)d1gd+gfd)d'gd2gfgd3d4 Zejd%d)d5gd+gfd)d'gd6gfd7d'gd+gfgd8d9 Zd:d; Zd<S )=TestMakeTupleBunchc                 C   s   t dddddd| _d S )N         c         ?r   r   r   r   r	   )r   resultself r   ?/tmp/pip-unpacked-wheel-9gxwnfpp/scipy/_lib/tests/test_bunch.pysetup_method   s    zTestMakeTupleBunch.setup_methodc                 C   sJ   t | jjd t | jjd t | jjd t | jjd t | jjd d S )Nr   r   r   r   r   )r   r   r   r   r   r   r	   r   r   r   r   test_attribute_access   s
    z(TestMakeTupleBunch.test_attribute_accessc              	   C   sh   t | jd d t | jd d t | jd d t | jd d tjtdd | jd  W 5 Q R X d S )Nr   r   r   r   zindex out of rangematch)r   r   pytestraises
IndexErrorr   r   r   r   test_indexing   s    z TestMakeTupleBunch.test_indexingc                 C   s,   | j \}}}t|||fd t| j d d S Nr   r   r   )r   r   )r   Zx0Zy0Zz0r   r   r   test_unpacking&   s    z!TestMakeTupleBunch.test_unpackingc                 C   sD   t | jdd  d t | jd d d d t | jd d d d d S )Nr   )r   r   r   )r   r   r   )r   r   r   )r   r   r   r   r   r   
test_slice+   s    zTestMakeTupleBunch.test_slicec                 C   s   t t| jd d S )Nr   )r   lenr   r   r   r   r   test_len0   s    zTestMakeTupleBunch.test_lenc                 C   s   t | j}t|d d S )Nz%Result(x=1, y=2, z=3, w=99, beta=0.5))reprr   r   )r   sr   r   r   	test_repr3   s    
zTestMakeTupleBunch.test_reprc                 C   s   t t| jtd d S r   )r   hashr   r   r   r   r   	test_hash7   s    zTestMakeTupleBunch.test_hashc                 C   sx   t | j}t |}t|ts$tt|j| jj t|j	| jj	 t|j
| jj
 t|j| jj t|j| jj d S )N)pickledumpsr   loads
isinstancer   AssertionErrorr   r   r   r   r   r	   )r   r&   objr   r   r   test_pickle:   s    
zTestMakeTupleBunch.test_picklec              	   C   s&   t jtdd d| j_W 5 Q R X d S )Nzcan't set attributer   r   )r   r   AttributeErrorr   r   r   r   r   r   test_read_only_existingD   s    z*TestMakeTupleBunch.test_read_only_existingc                 C   s   d| j _| j jdkstd S )Nzlattice of coincidence)r   Zplate_of_shrimpr.   r   r   r   r   test_read_only_newH   s    z%TestMakeTupleBunch.test_read_only_newc              	   C   s.   t jtdd tddddd W 5 Q R X d S )Nmissingr   r   r   r         ?)r   r   r   r	   r   r   	TypeErrorr   r   r   r   r   "test_constructor_missing_parameterL   s    z5TestMakeTupleBunch.test_constructor_missing_parameterc              	   C   s2   t jtdd tddddddd	 W 5 Q R X d S )
NZ
unexpectedr   r   r   r   {   r5   i  )r   r   r   r   r	   foor6   r   r   r   r   $test_constructor_incorrect_parameterQ   s    z7TestMakeTupleBunch.test_constructor_incorrect_parameterc                 C   s"   d}t tj| t | jj| d S )Nzscipy._lib.tests.test_bunch)r   r   
__module__r   )r   mr   r   r   test_moduleV   s    zTestMakeTupleBunch.test_modulec                 C   s|   t dddddd}t ddd	d
dd}t|jd t|jd t|d d  d t|jd
 t|jd t|d d  d d S )Nr   r   r   r   g        r            r   g      ?r    )r?   r@   rA   )r   r   r   r	   )r   Zresult1Zresult2r   r   r   test_extra_fields_per_instance[   s    z1TestMakeTupleBunch.test_extra_fields_per_instancec                 C   sH   t dddg}|ddd}t|jd t|jd t|}t|d d S )NSquarewidthheightr   r   )rD   rE   zSquare(width=1, height=2))r   r   rD   rE   r%   )r   rC   sqr&   r   r   r   "test_extra_field_names_is_optionaln   s    z5TestMakeTupleBunch.test_extra_field_names_is_optionalc                 C   s>   t dddg}|ddd}t|ts(tt|d ts:td S )NTupabr   r   )rI   rJ   )r   )r   r-   tupler.   )r   rH   Ztur   r   r   test_tuple_likev   s    z"TestMakeTupleBunch.test_tuple_likec                 C   sD   d}t ddgddg|d}|ddd	d
}t|j| t|j| d S )Nzsome.module.nameFoor   rI   rJ   )moduler   ic  q   )r   rI   rJ   )r   r   r<   )r   r=   rM   r:   r   r   r   test_explicit_module|   s
    z'TestMakeTupleBunch.test_explicit_moduleargsZ123rI   rJ   rM   z-3r   z+-*/c              	   C   s&   t jtdd t|  W 5 Q R X d S )NZidentifiersr   r   r   
ValueErrorr   r   rQ   r   r   r   test_identifiers_not_allowed   s    z/TestMakeTupleBunch.test_identifiers_not_allowedc              	   C   s&   t jtdd t|  W 5 Q R X d S )NZ	Duplicater   rR   rT   r   r   r   test_repeated_field_names   s    z,TestMakeTupleBunch.test_repeated_field_namesZ_a_xc              	   C   s&   t jtdd t|  W 5 Q R X d S )NZ
underscorer   rR   rT   r   r   r   #test_leading_underscore_not_allowed   s    z6TestMakeTupleBunch.test_leading_underscore_not_alloweddeforandc              	   C   s&   t jtdd t|  W 5 Q R X d S )Nkeywordr   rR   rT   r   r   r   "test_keyword_not_allowed_in_fields   s    z5TestMakeTupleBunch.test_keyword_not_allowed_in_fieldsc              	   C   s.   t jtdd tdg ddg W 5 Q R X d S )Nzat least one namer   ZQwertyrI   rJ   rR   r   r   r   r   %test_at_least_one_field_name_required   s    z8TestMakeTupleBunch.test_at_least_one_field_name_requiredN)__name__r<   __qualname__r   r   r   r!   r"   r$   r'   r)   r0   r2   r3   r8   r;   r>   rB   rG   rL   rP   r   markZparametrizerU   rV   rX   r]   r^   r   r   r   r   r
      sJ   




r
   )r   r*   Znumpy.testingr   Zscipy._lib._bunchr   r   r
   r   r   r   r   <module>   s
   