a
    ߙfb                     @   sJ   d dl Z d dlmZmZ dd ZG dd dZdd Zd	d
 Zdd ZdS )    N)fnpickle
fnunpicklec                 C   s   t | d}d}t|| t|d}||ks2J t|d}t|| W d   n1 s\0    Y  t|d$}t|}||ksJ W d   n1 s0    Y  dS )z
    Tests the `fnpickle` and `fnupickle` functions' basic operation by
    pickling and unpickling a string, using both a filename and a
    file.
    ztest1.pickleastringr   wbNrb)strjoinr   r   open)tmpdirfnobj1resf r   Hlib/python3.9/site-packages/astropy/io/misc/tests/test_pickle_helpers.pytest_fnpickling_simple   s    

(r   c                   @   s   e Zd Zdd Zdd ZdS )ToBePickledc                 C   s
   || _ d S )N)item)selfr   r   r   r   __init__   s    zToBePickled.__init__c                 C   s   t |tr| j|jkS dS d S )NF)
isinstancer   r   )r   otherr   r   r   __eq__!   s    
zToBePickled.__eq__N)__name__
__module____qualname__r   r   r   r   r   r   r      s   r   c                 C   s<   t | d}d}t|}t|| t|}||ks8J dS )zl
    Tests the `fnpickle` and `fnupickle` functions' ability to pickle
    and unpickle custom classes.
    ztest2.pickler   N)r   r   r   r   r   )r
   r   r   obj2r   r   r   r   test_fnpickling_class(   s    
r   c                 C   sd   ddl }d}t|}t|jd D ]<}t| d| d}t|||d t|}||ks"J q"dS )z|
    Tests the `fnpickle` and `fnupickle` functions' ability to pickle
    and unpickle pickle files from all protcols.
    r   Nr      Ztestpz.pickle)Zprotocol)pickler   rangeZHIGHEST_PROTOCOLr   r   r   r   )r
   r   r   r   pr   r   r   r   r   test_fnpickling_protocol6   s    r"   c                 C   s   t | d}d}d}t|| t||dd t|dd}t|dksJJ |d	 |ksZJ |d
 |ksjJ t||dd t|dd}t|dksJ tt t|dd W d   n1 s0    Y  dS )z
    Tests the `fnpickle` and `fnupickle` functions' ability to pickle
    and unpickle multiple objects from a single file.
    ztest3.picklegH}t@ZblahblahfooT)append)Znumber   r   r      N)r   r   r   r   lenpytestZraisesEOFError)r
   r   Zobj3Zobj4r   r   r   r   test_fnpickling_manyG   s    
r*   )	r(   Zastropy.io.miscr   r   r   r   r   r"   r*   r   r   r   r   <module>   s   