B
    u9a®  ã               @   s”   d Z ddlmZ ddlmZmZ ddlZddlZddlZG dd„ dej	ƒZ
G dd„ dej	ƒZd	d
„ ZedkreejƒdkrŠe ejd ¡ eƒ  dS )aT  
These tests are meant to exercise that requests to create objects bigger
than what the address space allows are properly met with an OverflowError
(rather than crash weirdly).

Primarily, this means 32-bit builds with at least 2 GiB of available memory.
You need to pass the -M option to regrtest (e.g. "-M 2.1G") for tests to
be enabled.
é    )Úsupport)ÚbigaddrspacetestÚMAX_Py_ssize_tNc               @   s0   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZdS )Ú	BytesTestc             C   s.   z"dt d  }|  ttj|d¡ W d d }X d S )Nó   xé€   s€   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r   ÚassertRaisesÚOverflowErrorÚoperatorÚadd)ÚselfÚx© r   ú'/usr/lib/python3.7/test_bigaddrspace.pyÚtest_concat   s    zBytesTest.test_concatc          	   C   sX   zLdt d  }|  t¡}|d }W d Q R X |  t¡}|d7 }W d Q R X W d d }X d S )Nr   r   s€   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r   r   r	   )r   r   Úcmr   r   r   Útest_optimized_concat    s    zBytesTest.test_optimized_concatc             C   s.   z"dt d  }|  ttj|d¡ W d d }X d S )Nr   r   )r   r   r	   r
   Úmul)r   r   r   r   r   Útest_repeat/   s    zBytesTest.test_repeatN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s   r   c               @   sB   e Zd Zejdk rdndZedd„ ƒZedd„ ƒZedd	„ ƒZ	d
S )ÚStrTesti   é   é   c             C   s8   z,dt td| j  ƒ }|  ttj||¡ W d d }X d S )Nr   gš™™™™™ñ?)Úintr   Úunicodesizer   ÚMemoryErrorr
   r   )r   r   r   r   r   r   <   s    zStrTest.test_concatc          	   C   sb   zVdt td| j  ƒ }|  t¡}|| }W d Q R X |  t¡}||7 }W d Q R X W d d }X d S )Nr   gš™™™™™ñ?)r   r   r   r   r   )r   r   r   r   r   r   r   G   s    zStrTest.test_optimized_concatc             C   s8   z,dt td| j  ƒ }|  ttj|d¡ W d d }X d S )Nr   gš™™™™™ñ?r   )r   r   r   r   r   r
   r   )r   r   r   r   r   r   V   s    zStrTest.test_repeatN)
r   r   r   ÚsysÚ
maxunicoder   r   r   r   r   r   r   r   r   r   8   s   r   c               C   s   t  tt¡ d S )N)r   Zrun_unittestr   r   r   r   r   r   Ú	test_main_   s    r    Ú__main__é   )Ú__doc__Ztestr   Ztest.supportr   r   Zunittestr
   r   ZTestCaser   r   r    r   ÚlenÚargvZset_memlimitr   r   r   r   Ú<module>	   s   %'