a
    =Ā×_Ø  ć                   @   s  d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZmZmZmZ d	d
 ZG dd deeZG dd deeZd*ddZG dd deeZG dd deeZG dd deeZG dd deeZG dd deZG dd deeZG dd deeZ G d d! d!eZ!G d"d# d#e!Z"G d$d% d%eeZ#d&d' Z$e%d(krddl&Z&ee&j' e  ej(d'd) dS )+z"Unit test for the filenode module.é    )Śabsolute_importN©Śresource_filenameé   )Ś	open_fileŚfileŚNoSuchNodeError)Śfilenode)ŚunittestŚTempFileMixinŚ
parse_argvŚprint_versionsŚPyTablesTestCasec                 C   s
   t d| S )Nztables.nodes.testsr   ©Śname© r   ś?lib/python3.9/site-packages/tables/nodes/tests/test_filenode.pyŚ	test_file   s    r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ŚNewFileTestCasez<Tests creating a new file node with the new_node() function.c                 C   sT   z"t j| jddd}| j d”}W n ty>   |  d” Y n0 |  |j|d” dS )z"Creation of a brand new file node.ś/Śtest©Śwherer   ś/testz0filenode.new_node() failed to create a new node.z6filenode.new_node() created a node in the wrong place.N)r	   Śnew_nodeŚh5fileŚget_nodeŚLookupErrorŚfailŚassertEqualŚnode)ŚselfŚfnoder    r   r   r   Śtest00_NewFile%   s    žzNewFileTestCase.test00_NewFilec                 C   s   |   ttj| j” dS )z@Creation of a new file node without arguments for node creation.N©ŚassertRaisesŚ	TypeErrorr	   r   r   ©r!   r   r   r   Śtest01_NewFileTooFewArgs2   s    z(NewFileTestCase.test01_NewFileTooFewArgsc                 C   s:   zt j| jdddd W n ty4   |  d” Y n0 dS )z9Creation of a new file node with 'expectedsize' argument.r   r   é  )r   r   Zexpectedsizez=filenode.new_node() failed to accept 'expectedsize' argument.N)r	   r   r   r&   r   r'   r   r   r   Śtest02_NewFileWithExpectedSize7   s    
’
z.NewFileTestCase.test02_NewFileWithExpectedSizec                 C   s   | j ttj| jdddd dS )zACreation of a new file node with illegal 'expectedrows' argument.r   r   r)   )r   r   ZexpectedrowsNr$   r'   r   r   r   Śtest03_NewFileWithExpectedRowsA   s    
žz.NewFileTestCase.test03_NewFileWithExpectedRowsN)Ś__name__Ś
__module__Ś__qualname__Ś__doc__r#   r(   r*   r+   r   r   r   r   r   "   s
   
r   c                       s   e Zd ZdZ fddZ f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  ZS )ŚClosedFileTestCasez/Tests calling several methods on a closed file.c                    s0   t t|  ”  tj| jddd| _| j ”  dS )a  setUp() -> None

        This method sets the following instance attributes:
          * 'h5fname', the name of the temporary HDF5 file
          * 'h5file', the writable, temporary HDF5 file with a '/test' node
          * 'fnode', the closed file node in '/test'

        r   r   r   N)Śsuperr0   ŚsetUpr	   r   r   r"   Ścloser'   ©Ś	__class__r   r   r2   L   s    
zClosedFileTestCase.setUpc                    s   d| _ tt|  ”  dS )zItearDown() -> None

        Closes 'h5file'; removes 'h5fname'.

        N)r"   r1   r0   ŚtearDownr'   r4   r   r   r6   Z   s    zClosedFileTestCase.tearDownc                 C   s0   z| j  ”  W n ty*   |  d” Y n0 dS )zClosing a closed file.z'Could not close an already closed file.N)r"   r3   Ś
ValueErrorr   r'   r   r   r   Śtest00_Closef   s    zClosedFileTestCase.test00_Closec                 C   s   |   t| jj” dS )zFlushing a closed file.N)r%   r7   r"   Śflushr'   r   r   r   Śtest01_Flushn   s    zClosedFileTestCase.test01_Flushc                 C   s   |   tt| j” dS )z'Getting the next line of a closed file.N)r%   r7   Śnextr"   r'   r   r   r   Śtest02_Nexts   s    zClosedFileTestCase.test02_Nextc                 C   s   |   t| jj” dS )zReading a closed file.N)r%   r7   r"   Śreadr'   r   r   r   Śtest03_Readx   s    zClosedFileTestCase.test03_Readc                 C   s   |   t| jj” dS )z"Reading a line from a closed file.N)r%   r7   r"   Śreadliner'   r   r   r   Śtest04_Readline}   s    z"ClosedFileTestCase.test04_Readlinec                 C   s   |   t| jj” dS )z!Reading lines from a closed file.N)r%   r7   r"   Ś	readlinesr'   r   r   r   Śtest05_Readlines   s    z#ClosedFileTestCase.test05_Readlinesc                 C   s   |   t| jjd” dS )zSeeking a closed file.r   N)r%   r7   r"   Śseekr'   r   r   r   Śtest06_Seek   s    zClosedFileTestCase.test06_Seekc                 C   s   |   t| jj” dS )z.Getting the pointer position in a closed file.N)r%   r7   r"   Śtellr'   r   r   r   Śtest07_Tell   s    zClosedFileTestCase.test07_Tellc                 C   s   |   t| jj” dS )zTruncating a closed file.N)r%   r7   r"   Śtruncater'   r   r   r   Śtest08_Truncate   s    z"ClosedFileTestCase.test08_Truncatec                 C   s   |   t| jjd” dS )zWriting a closed file.s   fooN©r%   r7   r"   Śwriter'   r   r   r   Śtest09_Write   s    zClosedFileTestCase.test09_Writec                 C   s   |   t| jjdg” dS )zWriting lines to a closed file.s   foo
N)r%   r7   r"   Ś
writelinesr'   r   r   r   Śtest10_Writelines   s    z$ClosedFileTestCase.test10_Writelines)r,   r-   r.   r/   r2   r6   r8   r:   r<   r>   r@   rB   rD   rF   rH   rK   rM   Ś__classcell__r   r   r4   r   r0   I   s   r0   é   c                 C   s0   |   |”}t|dkr,| |” |   |”}q
dS )zÄcopyFileToFile(srcfile, dstfile[, blocksize]) -> None

    Copies a readable opened file 'srcfile' to a writable opened file
    'destfile' in blocks of 'blocksize' bytes (4 KiB by default).

    r   N)r=   ŚlenrJ   )ZsrcfileZdstfileZ	blocksizeŚdatar   r   r   ŚcopyFileToFile”   s    

rR   c                       sH   e Zd ZdZdZ fddZ fddZdd Zd	d
 Zdd Z	  Z
S )ŚWriteFileTestCasez6Tests writing, seeking and truncating a new file node.śtest_filenode.datc                    s2   t t|  ”  tj| jddd| _t| j| _dS ©a  setUp() -> None

        This method sets the following instance attributes:
          * 'h5fname', the name of the temporary HDF5 file
          * 'h5file', the writable, temporary HDF5 file with a '/test' node
          * 'fnode', the writable file node in '/test'

        r   r   r   N)	r1   rS   r2   r	   r   r   r"   r   Ś	datafnamer'   r4   r   r   r2   “   s    
zWriteFileTestCase.setUpc                    s"   | j  ”  d| _ tt|  ”  dS ©zUtearDown() -> None

        Closes 'fnode' and 'h5file'; removes 'h5fname'.

        N)r"   r3   r1   rS   r6   r'   r4   r   r   r6   Ā   s    
zWriteFileTestCase.tearDownc                 C   s4   t | jd}zt|| j W | ”  n
| ”  0 dS )zWriting a whole file node.ŚrbN)ŚopenrV   rR   r"   r3   )r!   Śdatafiler   r   r   Śtest00_WriteFileĶ   s    z"WriteFileTestCase.test00_WriteFilec                 C   s  | j  d” | j  d” | j  d” | j  d” | j  d”}|  |dd” | j  d” | j  d	” | j  d” | j  d
”}|  |d	d” | j  dd” | j  d
”}|  |d	d” | j  dd” | j  ” }| j  dd” | j  d	” | j  ” }|  ||d d
 d” dS )zSeeking and writing file node.s   0123é   s   4567r   é   s   3    4z3Gap caused by forward seek was not properly filled.r   ó   testé   z)Data was overwritten instead of appended.éü’’’é   zWritten data was not appended.éž’’’z*Pointer was not correctly moved on append.N)r"   rJ   rC   r=   r   ZassertNotEqualrE   )r!   rQ   Z	oldendoffZ	newendoffr   r   r   Śtest01_SeekFileÖ   s8    ž’

žz!WriteFileTestCase.test01_SeekFilec                 C   s   | j  d” | j  d” |  t| j j” | j  d” | j  ”  | j  d” | j  ” }|  |dd” | j  d” | j  d” | j  ” }|  |dd	” d
S )zTruncating a file node.r^   ra   r]   r   s   test  z)File was not grown to the current offset.r\   s   test    z'File was not grown to an absolute size.N)r"   rJ   rC   r%   ŚIOErrorrG   r=   r   )r!   rQ   r   r   r   Śtest02_TruncateFile÷   s     

’
’z%WriteFileTestCase.test02_TruncateFile)r,   r-   r.   r/   rV   r2   r6   r[   rc   re   rN   r   r   r4   r   rS   Æ   s   	!rS   c                       s8   e Zd ZdZ fddZdd Zdd Zdd	 Z  ZS )
ŚOpenFileTestCasez<Tests opening an existing file node for reading and writing.c                    s,   t t|  ”  tj| jddd}| ”  dS )zŻsetUp() -> None

        This method sets the following instance attributes:
          * 'h5fname', the name of the temporary HDF5 file
          * 'h5file', the writable, temporary HDF5 file with a '/test' node

        r   r   r   N)r1   rf   r2   r	   r   r   r3   ©r!   r"   r4   r   r   r2     s    	zOpenFileTestCase.setUpc                 C   s^   | j  d”}t |”}|  |j|d” |  |jddt|j ” |  | ” dd” | 	”  dS )z*Opening an existing file node for reading.r   ś+filenode.open_node() opened the wrong node.Śrś(File was opened with an invalid mode %s.r   ś7Pointer is not positioned at the beginning of the file.N©
r   r   r	   Ś	open_noder   r    ŚmodeŚreprrE   r3   ©r!   r    r"   r   r   r   Śtest00_OpenFileRead  s    
’žžz$OpenFileTestCase.test00_OpenFileReadc                 C   s`   | j  d”}t |d”}|  |j|d” |  |jddt|j ” |  | ” dd” | 	”  dS )z8Opening an existing file node for reading and appending.r   śa+rh   rj   r   rk   Nrl   rp   r   r   r   Śtest01_OpenFileReadAppend,  s    ’žžz*OpenFileTestCase.test01_OpenFileReadAppendc                 C   s   |   ttj| j d”d” dS )z3Opening an existing file node with an invalid mode.r   ŚwN)r%   rd   r	   rm   r   r   r'   r   r   r   Śtest02_OpenFileInvalidMode<  s    ’z+OpenFileTestCase.test02_OpenFileInvalidMode)	r,   r-   r.   r/   r2   rq   rs   ru   rN   r   r   r4   r   rf     s
   rf   c                       sH   e Zd ZdZdZ fddZ fddZdd Zd	d
 Zdd Z	  Z
S )ŚReadFileTestCasez)Tests reading from an existing file node.ztest_filenode.xbmc                    sr   t | j| _t| jd| _tt|  ”  tj| j	ddd}t
| j| | ”  | j d” t | j	 d””| _dS )aR  setUp() -> None

        This method sets the following instance attributes:
          * 'datafile', the opened data file
          * 'h5fname', the name of the temporary HDF5 file
          * 'h5file', the writable, temporary HDF5 file with a '/test' node
          * 'fnode', the readable file node in '/test', with data in it

        rX   r   r   r   r   r   N)r   rV   rY   rZ   r1   rv   r2   r	   r   r   rR   r3   rC   rm   r   r"   rg   r4   r   r   r2   T  s    zReadFileTestCase.setUpc                    s2   | j  ”  d| _ | j ”  d| _tt|  ”  dS )zatearDown() -> None

        Closes 'fnode', 'h5file' and 'datafile'; removes 'h5fname'.

        N)r"   r3   rZ   r1   rv   r6   r'   r4   r   r   r6   k  s
    

zReadFileTestCase.tearDownc                 C   s   z4ddl }| | j ” ” ” }| | j ” ” ” }W nB tyv   ddl}| | j ” ” ” }| | j ” ” ” }Y n0 |  ||d” dS )z(Reading and comparing a whole file node.r   Nz?Data read from file node differs from that in the file on disk.)	ŚhashlibŚmd5rZ   r=   Zdigestr"   ŚImportErrorŚnewr   )r!   rw   ZdfiledigestZfnodedigestrx   r   r   r   Śtest00_CompareFilez  s    žz#ReadFileTestCase.test00_CompareFilec                 C   s   |   t| jjd” dS )zWriting on a read-only file.zno wayN)r%   rd   r"   rJ   r'   r   r   r   Śtest01_Write  s    zReadFileTestCase.test01_Writec                 C   sN   zddl m} | | j” W n, ty.   Y n tyH   |  d” Y n0 dS )z.Using a file node with Python Imaging Library.r   )ŚImagez7PIL was not able to create an image from the file node.N)ZPILr}   rY   r"   ry   rd   r   )r!   r}   r   r   r   Śtest02_UseAsImageFile  s    ’z&ReadFileTestCase.test02_UseAsImageFile)r,   r-   r.   r/   rV   r2   r6   r{   r|   r~   rN   r   r   r4   r   rv   O  s   rv   c                       s\   e Zd ZdZ fddZ fddZdd Zdd	 Zd
d Zdd Z	dd Z
dd Z  ZS )ŚReadlineTestCasez¹Base class for text line-reading test cases.

    It provides a set of tests independent of the line separator string.
    Sub-classes must provide the 'line_separator' attribute.

    c                    s   t t|  ”  | j}tj| jddd}| |” d| d”fd  }| 	d”}| |” | d| ” | d” | 
”  t | j d	””| _d
S )a  This method sets the following instance attributes:

        * ``h5fname``: the name of the temporary HDF5 file.
        * ``h5file``: the writable, temporary HDF5 file with a ``/test`` node.
        * ``fnode``: the readable file node in ``/test``, with text in it.

        r   r   r   zshort line%sshort line%s%sŚasciir   óČ   long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line long line ó   unterminatedr   N)r1   r   r2   Śline_separatorr	   r   r   rJ   ŚdecodeŚencoder3   rm   r   r"   )r!   Ślinesepr"   rQ   r4   r   r   r2   §  s    	



zReadlineTestCase.setUpc                    s"   | j  ”  d| _ tt|  ”  dS rW   )r"   r3   r1   r   r6   r'   r4   r   r   r6   Ć  s    
zReadlineTestCase.tearDownc                 C   s¶   | j }| j ” }|  ||” | j ” }| j ” }|  |d| ” | j ” }|  ||” | j ” }|  |d| ” | j ” }|  |d” | j ” }|  |d” | j ” }|  |d” dS )zReading individual lines.ó
   short liner   r   ó    N)r   r"   r?   r   ©r!   r   Śliner   r   r   Śtest00_ReadlineĪ  s     







z ReadlineTestCase.test00_Readlinec                 C   s   | j }t|}| j ”  | j ”  | j |d  d” | j ” }|  |d| d” | j |d d” | j ” }|  ||d  d d| d	” dS )
z4Reading individual lines and seeking back and forth.r_   é   s   linez$Seeking back yielded different data.é   é
   Ns
   long line z&Seeking forth yielded unexpected data.)r   rP   r"   r?   rC   r   ©r!   r   Zlseplenr   r   r   r   Śtest01_ReadlineSeekč  s    


’
žz$ReadlineTestCase.test01_ReadlineSeekc                 C   sb   | j }| jD ]}q|  tt| j” | j d” t| j}|  ||” t| j}|  |d| ” dS )zIterating over the lines.r   r   N)r   r"   r%   ŚStopIterationr;   rC   r   r   r   r   r   Śtest02_Iterateü  s    


zReadlineTestCase.test02_Iteratec              	   C   s8   | j }| j ” }|  ||d| d| |d| dg” dS )zReading a list of lines.r   r   r   N)r   r"   rA   r   )r!   r   Ślinesr   r   r   Śtest03_Readlines  s    

žz!ReadlineTestCase.test03_Readlinesc                 C   sŲ   | j }t|}| j ” }| j |d ”}|  |d| ” | j d”}|  |d” | j |d ”}|  |d| ” | j |”}|  ||” | j dd” | j d”}|  |d	” | j dd” | j d”}|  |d	” d
S )z)Reading individual lines of limited size.r   r   é   ó   shorts    liner`   ra   r_   s   atedN)r   rP   r"   r?   r   rC   r   r   r   r   Śtest04_ReadlineSize  s"    
z$ReadlineTestCase.test04_ReadlineSizec                 C   s   | j }d| d”fd  }| d”}| j t|”}|  t|t| d”” |  |dd |d| g” |  |d  	d”” dS )	z,Reading a list of lines with a limited size.z%sshort line%sshortr   ra   ó   
Né’’’’r   r   )
r   r   r   r"   rA   rP   r   ŚsplitŚ
assertTrueŚ
startswith)r!   r   rQ   r   r   r   r   Śtest05_ReadlinesSize5  s    
z%ReadlineTestCase.test05_ReadlinesSize)r,   r-   r.   r/   r2   r6   r   r   r   r   r   r   rN   r   r   r4   r   r     s   
r   c                   @   s   e Zd ZdZdZdS )ŚMonoReadlineTestCasezKTests reading one-byte-separated text lines from an existing
    file node.r   N)r,   r-   r.   r/   r   r   r   r   r   r   I  s   r   c                       sD   e Zd ZdZ fddZ fddZdd Zdd	 Zd
d Z  Z	S )ŚAttrsTestCasez/Tests setting and getting file node attributes.c                    s&   t t|  ”  tj| jddd| _dS rU   )r1   r   r2   r	   r   r   r"   r'   r4   r   r   r2     s    
zAttrsTestCase.setUpc                    s"   | j  ”  d| _ tt|  ”  dS rW   )r"   r3   r1   r   r6   r'   r4   r   r   r6     s    
zAttrsTestCase.tearDownc                 C   sF   t | jjdd}|  |tjd” t | jjdd}|  |tjv d” dS )z,Mangling the type attributes on a file node.Z	NODE_TYPENz6File node does not have a valid 'NODE_TYPE' attribute.ZNODE_TYPE_VERSIONz>File node does not have a valid 'NODE_TYPE_VERSION' attribute.)Śgetattrr"   Śattrsr   r	   ZNodeTyper   ZNodeTypeVersions)r!   ZnodeTypeZnodeTypeVersionr   r   r   Śtest00_MangleTypeAttrs®  s    žžz$AttrsTestCase.test00_MangleTypeAttrsc                 C   s   |   t| jjdddd” d| jj_|   t| jjdddd” d| jj_|   t| jjdddd” | jj`|   t| jjdddd” dS )	z(Setting a user attribute on a file node.ŚuserAttrNz4Inexistent attribute has a value that is not 'None'.Śfoobarś%User attribute was not correctly set.Śbazquuxś)User attribute was not correctly changed.śUser attribute was not deleted.)r   r    r"   r”   r£   r'   r   r   r   Śtest02_SetGetDelUserAttrŃ  s&    ž
ž
žžz&AttrsTestCase.test02_SetGetDelUserAttrc                 C   s    | j  ”  |  tt| j d” dS )z+Accessing attributes on a closed file node.r”   N)r"   r3   r%   ŚAttributeErrorr    r'   r   r   r   Śtest03_AttrsOnClosedFileź  s    
z&AttrsTestCase.test03_AttrsOnClosedFile)
r,   r-   r.   r/   r2   r6   r¢   r©   r«   rN   r   r   r4   r   r     s   #r   c                       s<   e Zd ZdZ fddZ fddZdd Zdd	 Z  ZS )
ŚClosedH5FileTestCasez6Tests accessing a file node in a closed PyTables file.c                    s0   t t|  ”  tj| jddd| _| j ”  dS )a  setUp() -> None

        This method sets the following instance attributes:
          * 'h5fname', the name of the temporary HDF5 file
          * 'h5file', the closed HDF5 file with a '/test' node
          * 'fnode', the writable file node in '/test'

        r   r   r   N)r1   r¬   r2   r	   r   r   r"   r3   r'   r4   r   r   r2   ō  s    
zClosedH5FileTestCase.setUpc              
      sl   t jdtd z4z| j ”  W n ty0   Y n0 W t jdtd nt jdtd 0 d| _tt|  ”  dS )zHtearDown() -> None

        Closes 'fnode'; removes 'h5fname'.

        Śignore)ŚcategoryŚdefaultN)	ŚwarningsŚfilterwarningsŚUserWarningr"   r3   r7   r1   r¬   r6   r'   r4   r   r   r6     s    
 zClosedH5FileTestCase.tearDownc                 C   s   |   t| jjd” dS )z1Writing to a file node in a closed PyTables file.rQ   NrI   r'   r   r   r   Śtest00_Write  s    z!ClosedH5FileTestCase.test00_Writec                 C   s   |   tt| jd” dS )zJAccessing the attributes of a file node in a closed
        PyTables file.r”   N)r%   r7   r    r"   r'   r   r   r   Śtest01_Attrs  s    z!ClosedH5FileTestCase.test01_Attrs)	r,   r-   r.   r/   r2   r6   r³   r“   rN   r   r   r4   r   r¬   ń  s
   r¬   c                       sD   e Zd ZdZ fddZ fddZdd Zdd	 Zd
d Z  Z	S )ŚOldVersionTestCasezäBase class for old version compatibility test cases.

    It provides some basic tests for file operations and attribute handling.
    Sub-classes must provide the 'oldversion' attribute
    and the 'oldh5fname' attribute.

    c                    sp   t t|  ”  tjdd| _t| j| _t| j}| 	| j” | 
”  t| jddd| _t | jjjd”| _dS )a  This method sets the following instance attributes:

        * ``h5fname``: the name of the temporary HDF5 file.
        * ``h5file``: the writable, temporary HDF5 file with a ``/test`` node.
        * ``fnode``: the readable file node in ``/test``.

        ś.h5©Śsuffixzr+z,Test for file node old version compatibility)Śtitlerr   N)r1   rµ   r2   ŚtempfileŚmktempŚh5fnamer   Ś
oldh5fnamer   Z	copy_filer3   r   r	   rm   Śrootr   r"   )r!   Zoldh5fr4   r   r   r2   ,  s    	
žzOldVersionTestCase.setUpc                    s>   | j  ”  d| _ | j ”  d| _t | j” tt|  ”  dS )z5Closes ``fnode`` and ``h5file``; removes ``h5fname``.N)	r"   r3   r   ŚosŚremover¼   r1   rµ   r6   r'   r4   r   r   r6   B  s    

zOldVersionTestCase.tearDownc                 C   s   | j  ” }|  |d” | j  ” }|  |d” | j  ” }|  |d| j ” | j  ” }|  |d” | j  d” | j  ” }|  |d” dS )z!Reading an old version file node.zThis is only
za test file
zfor FileNode version %d
Ś r   N)r"   r?   r   Ś
oldversionrC   ©r!   r   r   r   r   Śtest00_ReadL  s    




zOldVersionTestCase.test00_Readc                 C   s4   | j  d” | j  dd” | j  ” }|  |d” dS )z!Writing an old version file node.zfoobar
ił’’’ra   N)r"   rJ   rC   r?   r   rĆ   r   r   r   r|   a  s    
zOldVersionTestCase.test01_Writec                 C   sn   d| j j_|  t| j jdddd” d| j j_|  t| j jdddd” | j j`|  t| j jdddd” dS )z1Accessing attributes in an old version file node.r¤   r£   Nr„   r¦   r§   rØ   )r"   r”   r£   r   r    r'   r   r   r   Śtest02_Attributesk  s    
ž
žžz$OldVersionTestCase.test02_Attributes)
r,   r-   r.   r/   r2   r6   rÄ   r|   rÅ   rN   r   r   r4   r   rµ   #  s   

rµ   c                   @   s   e Zd ZdZdZdZdS )ŚVersion1TestCasez.Basic test for version 1 format compatibility.r   ztest_filenode_v1.h5N)r,   r-   r.   r/   rĀ   r½   r   r   r   r   rĘ   ~  s   rĘ   c                       sT   e Zd ZdZ fddZ fddZdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )ŚDirectReadWriteTestCaserT   c                    sv   t t|  ”  t| j| _t ” | _tjdd| _t	| jd}| 
” | _W d   n1 s^0    Y  t ” | _dS )aÆ  This method sets the following instance attributes:

        * ``h5fname``: the name of the temporary HDF5 file.
        * ``h5file``, the writable, temporary HDF5 file with a '/test' node
        * ``datafname``: the name of the data file to be stored in the
          temporary HDF5 file.
        * ``data``: the contents of the file ``datafname``
        * ``testfname``: the name of a temporary file to be written to.

        r¶   r·   rX   N)r1   rĒ   r2   r   rV   rŗ   r»   Ś	testfnameŚtesth5fnamerY   r=   rQ   ZmkdtempŚtestdir©r!   Śfdr4   r   r   r2     s    
(zDirectReadWriteTestCase.setUpc                    sV   t  | jt j”rt  | j” t  | jt j”r8t  | j” t | j” t	t
|  ”  dS rW   )ræ   ŚaccessrČ   ŚR_OKrĄ   rÉ   ŚshutilZrmtreerŹ   r1   rĒ   r6   r'   r4   r   r   r6     s    z DirectReadWriteTestCase.tearDownc                 C   sd  t  | j| jd” |  tt j| j| jd” t j| j| jddd t j| j| jddd t  | j| jd” t| jd"}|  	| 
” | j” W d    n1 s0    Y  t ” 2 t d” |  tt j| j| jd” W d    n1 sę0    Y  t j| j| jdddd	 t| jd"}|  	| 
” | j” W d    n1 s>0    Y  t | j” t | j” d S )
Nś/test1T©Ś	overwriter   Ztest2r   rX   r­   )r   rŅ   )r	   Śsave_to_filenoderÉ   rV   r%   rd   Śread_from_filenoderČ   rY   r   r=   rQ   r°   Ścatch_warningsŚsimplefilterræ   rĄ   rĖ   r   r   r   Śtest01_WriteToFilenameŖ  s2    ’’’0



’"’2z.DirectReadWriteTestCase.test01_WriteToFilenamec                 C   sŅ   t  | j| jd” |  tt j| j| jd” t j| j| jddd t  | j| jd” t| jd"}|  	| 
” | j” W d    n1 s0    Y  |  tt j| j| jd” |  	t| jtjd” |  	| jjd” d S )NrŠ   TrŃ   rX   rt   )r	   rÓ   r   rV   r%   rd   rŌ   rČ   rY   r   r=   rQ   Ś
isinstancer   ZFilern   rĖ   r   r   r   Śtest02_WriteToHDF5FileĖ  s    ’’0’z.DirectReadWriteTestCase.test02_WriteToHDF5Filec                 C   s°   t  | j| jd” tj | j”d }t j| j| jd| 	dd”d |  
t tj | j|”tj”d” ttj | j|”d"}|  
| ” | j” W d    n1 s¢0    Y  d S )Nr   r   Ś.Ś_r   TrX   )r	   rÓ   rÉ   rV   ræ   Śpathr   rŌ   rŹ   Śreplacer   rĶ   ŚjoinrĪ   rY   r=   rQ   ©r!   rV   rĢ   r   r   r   Śtest03_AutomaticNameGuessingą  s    
’’’z4DirectReadWriteTestCase.test03_AutomaticNameGuessingc                 C   sØ   t  | j| jd” tj | j”d }t j| j| jd|d |  	t 
tj | j|”tj”d” ttj | j|”d"}|  	| ” | j” W d    n1 s0    Y  d S )Nr   r   r   TrX   )r	   rÓ   rÉ   rV   ræ   rÜ   r   rŌ   rŹ   r   rĶ   rŽ   rĪ   rY   r=   rQ   rß   r   r   r   Ś1test04_AutomaticNameGuessingWithFilenameAttributeī  s    ’’’zIDirectReadWriteTestCase.test04_AutomaticNameGuessingWithFilenameAttributec                 C   s2   t  | j| jd” | jtt j| j| jddd d S )Nr   ZTHISNODEDOESNOTEXISTr   )r	   rÓ   rÉ   rV   r%   r   rŌ   rŹ   r'   r   r   r   Ś$test05_ReadFromNonexistingNodeRaisesü  s
    

žz<DirectReadWriteTestCase.test05_ReadFromNonexistingNodeRaises)r,   r-   r.   rV   r2   r6   r×   rŁ   rą   rį   rā   rN   r   r   r4   r   rĒ     s   !rĒ   c                  C   s   t  ” } |  t  t”” |  t  t”” |  t  t”” |  t  t”” |  t  t”” |  t  t	”” |  t  t
”” |  t  t”” |  t  t”” | S )zesuite() -> test suite

    Returns a test suite consisting of all the test cases in the module.

    )r
   Z	TestSuiteZaddTestZ	makeSuiter   r0   rS   rf   rv   r   r   r¬   rĒ   )ZtheSuiter   r   r   Śsuite  s    rć   Ś__main__)ZdefaultTest)rO   ))r/   Z
__future__r   ræ   rĻ   rŗ   r°   Zpkg_resourcesr   rĮ   r   r   r   Znodesr	   Ztests.commonr
   r   r   r   r   ZTestCaser   r   r0   rR   rS   rf   rv   r   r   r   r¬   rµ   rĘ   rĒ   rć   r,   ŚsysŚargvŚmainr   r   r   r   Ś<module>   s>   'X
^BP +Bf2[ 

