
    ꢩe                     V   d 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 Z G d	 d
ee          Z G d dee          Zd'dZ G d dee          Z G d dee          Z G d dee          Z G d dee          Z G d de          Z G d dee          Z G d dee          Z G d de          Z G d d e          Z  G d! d"ee          Z!d# Z"e#d$k    r1ddl$Z$ ee$j%                    e              ej&        d%&           dS dS )(z"Unit test for the filenode module.    N)Path   )	open_filefileNoSuchNodeError)filenode)unittestTempFileMixin
parse_argvprint_versionsPyTablesTestCasec                 >    ddl m} |                    d          | z  S )Nr   )	resourcesztables.nodes.tests)	importlibr   files)namer   s     @lib/python3.11/site-packages/tables/nodes/tests/test_filenode.py	test_filer      s,    ######??/00477    c                   *    e Zd ZdZd Zd Zd Zd ZdS )NewFileTestCasez<Tests creating a new file node with the new_node() function.c                     	 t          j        | j        dd          }| j                            d          }|                     |j        |d           dS # t          $ r |                     d           Y dS w xY w)z"Creation of a brand new file node./testwherer   /testz6filenode.new_node() created a node in the wrong place.z0filenode.new_node() failed to create a new node.N)r   new_nodeh5fileget_nodeassertEqualnodeLookupErrorfail)selffnoder"   s      r   test00_NewFilezNewFileTestCase.test00_NewFile   s    	J%dk6JJJE;''00D 
DHJ J J J J  	J 	J 	JIIHIIIIII	Js   6A A98A9c                 \    |                      t          t          j        | j                   dS )z@Creation of a new file node without arguments for node creation.NassertRaises	TypeErrorr   r   r   r%   s    r   test01_NewFileTooFewArgsz(NewFileTestCase.test01_NewFileTooFewArgs%   s'     	)X%6DDDDDr   c                     	 t          j        | j        ddd           dS # t          $ r |                     d           Y dS w xY w)z9Creation of a new file node with 'expectedsize' argument.r   r   順 )r   r   expectedsizez=filenode.new_node() failed to accept 'expectedsize' argument.N)r   r   r   r+   r$   r,   s    r   test02_NewFileWithExpectedSizez.NewFileTestCase.test02_NewFileWithExpectedSize*   s    	$3V'K K K K K K 	$ 	$ 	$II # $ $ $ $ $ $	$s   ! AAc                 d    |                      t          t          j        | j        ddd           dS )zACreation of a new file node with illegal 'expectedrows' argument.r   r   r/   )r   r   expectedrowsNr)   r,   s    r   test03_NewFileWithExpectedRowsz.NewFileTestCase.test03_NewFileWithExpectedRows4   sC     	x(Ksg 	 	G 	G 	G 	G 	Gr   N)__name__
__module____qualname____doc__r'   r-   r1   r4    r   r   r   r      sa        FFJ J JE E E
$ $ $G G G G Gr   r   c                   n     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Z xZS )ClosedFileTestCasez/Tests calling several methods on a closed file.c                     t                                                       t          j        | j        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supersetUpr   r   r   r&   closer%   	__class__s    r   r?   zClosedFileTestCase.setUp?   sK     	&t{#FKKK

r   c                 V    d| _         t                                                       dS )zItearDown() -> None

        Closes 'h5file'; removes 'h5fname'.

        N)r&   r>   tearDownrA   s    r   rD   zClosedFileTestCase.tearDownM   s(     
r   c                     	 | j                                          dS # t          $ r |                     d           Y dS w xY w)zClosing a closed file.z'Could not close an already closed file.N)r&   r@   
ValueErrorr$   r,   s    r   test00_ClosezClosedFileTestCase.test00_CloseY   s]    	AJ 	A 	A 	AII?@@@@@@	As    A A c                 P    |                      t          | j        j                   dS )zFlushing a closed file.N)r*   rF   r&   flushr,   s    r   test01_FlushzClosedFileTestCase.test01_Flusha   s%     	*dj&677777r   c                 R    |                      t          t          | j                   dS )z'Getting the next line of a closed file.N)r*   rF   nextr&   r,   s    r   test02_NextzClosedFileTestCase.test02_Nextf   s$     	*dDJ77777r   c                 P    |                      t          | j        j                   dS )zReading a closed file.N)r*   rF   r&   readr,   s    r   test03_ReadzClosedFileTestCase.test03_Readk   $     	*djo66666r   c                 P    |                      t          | j        j                   dS )z"Reading a line from a closed file.N)r*   rF   r&   readliner,   s    r   test04_Readlinez"ClosedFileTestCase.test04_Readlinep   %     	*dj&9:::::r   c                 P    |                      t          | j        j                   dS )z!Reading lines from a closed file.N)r*   rF   r&   	readlinesr,   s    r   test05_Readlinesz#ClosedFileTestCase.test05_Readlinesu   s%     	*dj&:;;;;;r   c                 R    |                      t          | j        j        d           dS )zSeeking a closed file.r   N)r*   rF   r&   seekr,   s    r   test06_SeekzClosedFileTestCase.test06_Seekz   s&     	*djoq99999r   c                 P    |                      t          | j        j                   dS )z.Getting the pointer position in a closed file.N)r*   rF   r&   tellr,   s    r   test07_TellzClosedFileTestCase.test07_Tell   rQ   r   c                 P    |                      t          | j        j                   dS )zTruncating a closed file.N)r*   rF   r&   truncater,   s    r   test08_Truncatez"ClosedFileTestCase.test08_Truncate   rU   r   c                 R    |                      t          | j        j        d           dS )zWriting a closed file.s   fooNr*   rF   r&   writer,   s    r   test09_WritezClosedFileTestCase.test09_Write   '     	*dj&6?????r   c                 T    |                      t          | j        j        dg           dS )zWriting lines to a closed file.s   foo
N)r*   rF   r&   
writelinesr,   s    r   test10_Writelinesz$ClosedFileTestCase.test10_Writelines   s)     	*dj&;hZHHHHHr   )r5   r6   r7   r8   r?   rD   rG   rJ   rM   rP   rT   rX   r[   r^   ra   re   ri   __classcell__rB   s   @r   r;   r;   <   s	       99        A A A8 8 8
8 8 8
7 7 7
; ; ;
< < <
: : :
7 7 7
; ; ;
@ @ @
I I I I I I Ir   r;      c                     |                      |          }t          |          dk    r?|                    |           |                      |          }t          |          dk    =dS dS )zcopyFileToFile(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)rO   lenrd   )srcfiledstfile	blocksizedatas       r   copyFileToFilers      s`     <<	""D
d))a--d||I&& d))a------r   c                   B     e Zd ZdZdZ fdZ fdZd Zd Zd Z	 xZ
S )WriteFileTestCasez6Tests writing, seeking and truncating a new file node.test_filenode.datc                     t                                                       t          j        | j        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)r>   r?   r   r   r   r&   r   	datafnamerA   s    r   r?   zWriteFileTestCase.setUp   sF     	&t{#FKKK
"4>22r   c                     | j                                          d| _         t                                                       dS zUtearDown() -> None

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

        Nr&   r@   r>   rD   rA   s    r   rD   zWriteFileTestCase.tearDown   <     	

r   c                     t          | j        d          }	 t          || j                   |                                 dS # |                                 w xY w)zWriting a whole file node.rbN)openry   rs   r&   r@   )r%   datafiles     r   test00_WriteFilez"WriteFileTestCase.test00_WriteFile   sX     --	8TZ000NNHNNs   A Ac                    | 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z
  d
z   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&   rd   rZ   rO   r!   assertNotEqualr]   )r%   rr   	oldendoff	newendoffs       r   test01_SeekFilez!WriteFileTestCase.test01_SeekFile   s    	
!!!

!!!
zq!!"A	C 	C 	C 	

!!!
zq!!'F	H 	H 	H 	
Azq!!w(HIII
1JOO%%	
A
!!!JOO%%	y1}q(8	: 	: 	: 	: 	:r   c                 z   | 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   r   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&   rd   rZ   r*   IOErrorr`   rO   r!   )r%   rr   s     r   test02_TruncateFilez%WriteFileTestCase.test02_TruncateFile   s%    	
!!!
'4:#6777


z  +J	L 	L 	L 	
A
z  /#L	N 	N 	N 	N 	Nr   )r5   r6   r7   r8   ry   r?   rD   r   r   r   rj   rk   s   @r   ru   ru      s        @@#I3 3 3 3 3	 	 	 	 	  : : :BN N N N N N Nr   ru   c                   4     e Zd ZdZ fdZd Zd Zd Z xZS )OpenFileTestCasez<Tests opening an existing file node for reading and writing.c                     t                                                       t          j        | j        dd          }|                                 dS )zsetUp() -> 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)r>   r?   r   r   r   r@   r%   r&   rB   s     r   r?   zOpenFileTestCase.setUp  s@     	!$+SvFFFr   c                 v   | j                             d          }t          j        |          }|                     |j        |d           |                     |j        ddt          |j                  z             |                     |                                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reprr]   r@   r%   r"   r&   s      r   test00_OpenFileReadz$OpenFileTestCase.test00_OpenFileRead  s     {##G,,"4((JK	M 	M 	MJ6ej9I9II	K 	K 	K 	JJLL!E	G 	G 	G 	r   c                 x   | j                             d          }t          j        |d          }|                     |j        |d           |                     |j        ddt          |j                  z             |                     |                                dd           |	                                 dS )z8Opening an existing file node for reading and appending.r   a+r   r   r   r   Nr   r   s      r   test01_OpenFileReadAppendz*OpenFileTestCase.test01_OpenFileReadAppend  s     {##G,,"4..JK	M 	M 	MJ6ej9I9II	K 	K 	K 	JJLL!E	G 	G 	G 	r   c                     |                      t          t          j        | j                            d          d           dS )z3Opening an existing file node with an invalid mode.r   wN)r*   r   r   r   r   r    r,   s    r   test02_OpenFileInvalidModez+OpenFileTestCase.test02_OpenFileInvalidMode/  sG     	X')=)=g)F)F	M 	M 	M 	M 	Mr   )	r5   r6   r7   r8   r?   r   r   r   rj   rk   s   @r   r   r      sr        FF         M M M M M M Mr   r   c                   H     e Zd ZdZdZ fdZ fdZd Zd Zd Z	d Z
 xZS )	ReadFileTestCasez)Tests reading from an existing file node.ztest_filenode.xbmc                    t          | j                  | _        t          | j        d          | _        t	                                                       t          j        | j        dd          }t          | j        |           |
                                 | j                            d           t          j        | 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

        r   r   r   r   r   r   N)r   ry   r   r   r>   r?   r   r   r   rs   r@   rZ   r   r    r&   r   s     r   r?   zReadFileTestCase.setUpF  s     #4>22T^T22!$+SvFFFt}e,,,1'(<(<W(E(EFF


r   c                     | j                                          d| _         | j                                         d| _        t                                                       dS )zatearDown() -> None

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

        N)r&   r@   r   r>   rD   rA   s    r   rD   zReadFileTestCase.tearDown]  sW     	

r   c                 4   ddl }|                    | j                                                                                  }|                    | j                                                                                  }|                     ||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md5r   rO   digestr&   r!   )r%   r   dfiledigestfnodedigests       r   test00_CompareFilez#ReadFileTestCase.test00_CompareFilel  s     	kk$-"4"4"6"677>>@@kk$*//"3"344;;==M	O 	O 	O 	O 	Or   c                 R    |                      t          | j        j        d           dS )zWriting on a read-only file.zno wayN)r*   r   r&   rd   r,   s    r   test01_WritezReadFileTestCase.test01_Writew  s'     	'4:#3X>>>>>r   c                     	 ddl m} |                    | j                   dS # t          $ r Y dS t
          $ r |                     d           Y dS w xY w)z.Using a file node with Python Imaging Library.r   )Imagez7PIL was not able to create an image from the file node.N)PILr   r   r&   ImportErrorOSErrorr$   )r%   r   s     r   test02_UseAsImageFilez&ReadFileTestCase.test02_UseAsImageFile|  s    		K!!!!!!JJtz""""" 	 	 	DD 	K 	K 	KIIIK K K K K K	Ks    $ 
AAAc                 `    |                      | j                                        d            d S )N)assertIsNotr&   filenor,   s    r   test_filenozReadFileTestCase.test_fileno  s,    **,,d33333r   )r5   r6   r7   r8   ry   r?   rD   r   r   r   r   rj   rk   s   @r   r   r   A  s        33#IG G G G G.    	O 	O 	O? ? ?
K K K4 4 4 4 4 4 4r   r   c                   P     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
d	 Z xZS )
ReadlineTestCasezBase 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                 (   t                                                       | j        }t          j        | j        dd          }|                    |           d|                    d          fdz  z  }|                    d          }|                    |           |                    d|z              |                    d           |	                                 t          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``, 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)r>   r?   line_separatorr   r   r   rd   decodeencoder@   r   r    r&   )r%   linesepr&   rr   rB   s       r   r?   zReadlineTestCase.setUp  s     	% !$+SvFFFG+w0G0G/IA/MN{{7##D&0111O$$$ '(<(<W(E(EFF


r   c                     | j                                          d| _         t                                                       dS r{   r|   rA   s    r   rD   zReadlineTestCase.tearDown  r}   r   c                    | j         }| j                                        }|                     ||           | j                                        }| j                                        }|                     |d|z              | j                                        }|                     ||           | j                                        }|                     |d|z              | j                                        }|                     |d           | j                                        }|                     |d           | j                                        }|                     |d           dS )zReading individual lines.
   short liner   r   r   N)r   r&   rS   r!   r%   r   lines      r   test00_Readlinez ReadlineTestCase.test00_Readline  sO    %z""$$w'''z""$$z""$$}w6777z""$$w'''z""$$1G;<<<z""$$///z""$$s###z""$$s#####r   c                    | j         }t          |          }| j                                         | j                                         | j                            |dz    d           | j                                        }|                     |d|z   d           | j                            |dz   d           | j                                        }|                     ||dz    d         d|z   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   rn   r&   rS   rZ   r!   r%   r   lseplenr   s       r   test01_ReadlineSeekz$ReadlineTestCase.test01_ReadlineSeek  s    %g,,


'A+***z""$$w0?	A 	A 	A 	
"a(((z""$$7R<!!"MG$;4	6 	6 	6 	6 	6r   c                 V   | j         }| j        D ]}|                     t          t          | j                   | j                            d           t	          | j                  }|                     ||           t	          | j                  }|                     |d|z              dS )zIterating over the lines.r   r   N)r   r&   r*   StopIterationrL   rZ   r!   r   s      r   test02_IteratezReadlineTestCase.test02_Iterate  s     % J 	 	D-tz:::
DJw'''DJ}w677777r   c           	          | j         }| j                                        }|                     ||d|z   d|z   |d|z   dg           dS )zReading a list of lines.r   r   r   N)r   r&   rW   r!   )r%   r   liness      r   test03_Readlinesz!ReadlineTestCase.test03_Readlines  sl     %
$$&&]W,mg.E''1?!D 	E 	E 	E 	E 	Er   c                 (   | j         }t          |          }| j                                        }| j                            |dz             }|                     |d|z              | j                            d          }|                     |d           | j                            |dz             }|                     |d|z              | 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   r   r   s   atedN)r   rn   r&   rS   r!   rZ   r   s       r   test04_ReadlineSizez$ReadlineTestCase.test04_ReadlineSize  sp    %g,,z""$$z""7R<00}w6777z""1%%x(((z""7R<00x'1222z""7++w'''
Az""1%%w'''
Az""2&&w'''''r   c                    | j         }d|                    d          fdz  z  }|                    d          }| j                            t          |                    }|                     t          |          t          |                    d                               |                     |dd         |d|z   g           |                     |d         	                    d                     dS )	z,Reading a list of lines with a limited size.z%sshort line%sshortr   r      
Nr   r   )
r   r   r   r&   rW   rn   r!   split
assertTrue
startswith)r%   r   rr   r   s       r   test05_ReadlinesSizez%ReadlineTestCase.test05_ReadlinesSize$  s     %$)@)@(BQ(FG{{7##
$$SYY// 	USE):):%;%;<<<ssg}w/F%GHHHb	,,X6677777r   )r5   r6   r7   r8   r?   rD   r   r   r   r   r   r   rj   rk   s   @r   r   r     s         G G G G G8	 	 	 	 	$ $ $46 6 6(8 8 8&E E E( ( (88 8 8 8 8 8 8r   r   c                       e Zd ZdZdZdS )MonoReadlineTestCasezKTests reading one-byte-separated text lines from an existing
    file node.r   N)r5   r6   r7   r8   r   r9   r   r   r   r   8  s          NNNr   r   c                   >     e Zd ZdZ fdZ fdZd Zd Zd Z xZ	S )AttrsTestCasez/Tests setting and getting file node attributes.c                     t                                                       t          j        | j        dd          | _        dS rx   )r>   r?   r   r   r   r&   rA   s    r   r?   zAttrsTestCase.setUp}  s5     	&t{#FKKK


r   c                     | j                                          d| _         t                                                       dS r{   r|   rA   s    r   rD   zAttrsTestCase.tearDown  r}   r   c                     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.	NODE_TYPENz6File node does not have a valid 'NODE_TYPE' attribute.NODE_TYPE_VERSIONz>File node does not have a valid 'NODE_TYPE_VERSION' attribute.)getattrr&   attrsr!   r   NodeTyper   NodeTypeVersions)r%   nodeTypenodeTypeVersions      r   test00_MangleTypeAttrsz$AttrsTestCase.test00_MangleTypeAttrs  s     4:+[$??h'D	F 	F 	F "$*"24GNNx88L	N 	N 	N 	N 	Nr   c                    |                      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,   s    r   test02_SetGetDelUserAttrz&AttrsTestCase.test02_SetGetDelUserAttr  s     	DJ$j$77B	D 	D 	D %-
!DJ$j$773	5 	5 	5 %.
!DJ$j$777	9 	9 	9 J%DJ$j$77-	/ 	/ 	/ 	/ 	/r   c                     | j                                          |                     t          t          | j         d           dS )z+Accessing attributes on a closed file node.r   N)r&   r@   r*   AttributeErrorr   r,   s    r   test03_AttrsOnClosedFilez&AttrsTestCase.test03_AttrsOnClosedFile  s:     	
.'4:wGGGGGr   )
r5   r6   r7   r8   r?   rD   r   r   r   rj   rk   s   @r   r   r   z  s        99L L L L L	 	 	 	 	&N N NF/ / /2H H H H H H Hr   r   c                   8     e Zd ZdZ fdZ fdZd Zd Z xZS )ClosedH5FileTestCasez6Tests accessing a file node in a closed PyTables file.c                     t                                                       t          j        | j        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   Nr=   rA   s    r   r?   zClosedH5FileTestCase.setUp  sK     	&t{#FKKK
r   c                 Z   t          j        dt                     	 | j                                         n# t
          $ r Y nw xY wt          j        dt                     n # t          j        dt                     w xY wd| _        t                                                       dS )zHtearDown() -> None

        Closes 'fnode'; removes 'h5fname'.

        ignore)categorydefaultN)warningsfilterwarningsUserWarningr&   r@   rF   r>   rD   rA   s    r   rD   zClosedH5FileTestCase.tearDown  s     	;????	EJ 	 	 	D	 #IDDDDDH#IDDDDD
s&   8 A$ 
AA$ AA$ $Bc                 R    |                      t          | j        j        d           dS )z1Writing to a file node in a closed PyTables file.rr   Nrc   r,   s    r   test00_Writez!ClosedH5FileTestCase.test00_Write  rf   r   c                 T    |                      t          t          | j        d           dS )zJAccessing the attributes of a file node in a closed
        PyTables file.r   N)r*   rF   r   r&   r,   s    r   test01_Attrsz!ClosedH5FileTestCase.test01_Attrs  s&     	*gtz7CCCCCr   )	r5   r6   r7   r8   r?   rD   r  r  rj   rk   s   @r   r  r    s        @@        *@ @ @
D D D D D D Dr   r  c                   >     e Zd ZdZ fdZ fdZd Zd Zd Z xZ	S )OldVersionTestCasezBase 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                    t                                                       t          j        d          | _        t          | j                  | _        t          | j                  }|                    | j                   |	                                 t          | j        dd          | _
        t          j        | 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)titler   N)r>   r?   tempfilemktemph5fnamer   
oldh5fnamer   	copy_filer@   r   r   r   rootr   r&   )r%   oldh5frB   s     r   r?   zOldVersionTestCase.setUp  s     	e444#DO444?++&&&L$@B B B '(8(=tDD


r   c                    | j                                          d| _         | j                                         d| _        t          | j                                                   t                                                       dS )z5Closes ``fnode`` and ``h5file``; removes ``h5fname``.N)r&   r@   r   r   r  unlinkr>   rD   rA   s    r   rD   zOldVersionTestCase.tearDown1  ss     	

T\!!###r   c                     | j                                         }|                     |d           | j                                         }|                     |d           | j                                         }|                     |d| j        z             | 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&   rS   r!   
oldversionrZ   r%   r   s     r   test00_ReadzOldVersionTestCase.test00_Read;  s    
 z""$$/000z""$$///z""$$:T_LMMMz""$$r"""
z""$$/00000r   c                     | j                             d           | j                             dd           | j                                         }|                     |d           dS )z!Writing an old version file node.zfoobar
ir   N)r&   rd   rZ   rS   r!   r"  s     r   r   zOldVersionTestCase.test01_WriteP  s_    
 	
$$$
Az""$$z*****r   c                    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,   s    r   test02_Attributesz$OldVersionTestCase.test02_AttributesZ  s     %-
!DJ$j$773	5 	5 	5 %.
!DJ$j$777	9 	9 	9 J%DJ$j$77-	/ 	/ 	/ 	/ 	/r   )
r5   r6   r7   r8   r?   rD   r#  r   r&  rj   rk   s   @r   r  r    s         E E E E E,    1 1 1*+ + +/ / / / / / /r   r  c                       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)r5   r6   r7   r8   r!  r  r9   r   r   r(  r(  m  s        88J&JJJr   r(  c                   P     e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
d	 Z xZS )
DirectReadWriteTestCaserv   c                 d   t                                                       t          | j                  | _        t	          j                    | _        t	          j        d          | _        t          | j                  	                                | _
        t	          j                    | _        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  N)r>   r?   r   ry   r  r  	testfnametesth5fnamer   
read_bytesrr   mkdtemptestdirrA   s    r   r?   zDirectReadWriteTestCase.setUpx  s|     	"4>22!**#?%888((3355	'))r   c                    t          j        | j        t           j                  r&t	          | j                                                   t          j        | j        t           j                  r&t	          | j                                                   t          j        | j	                   t                                                       dS r{   )osaccessr,  R_OKr   r  r-  shutilrmtreer0  r>   rD   rA   s    r   rD   z DirectReadWriteTestCase.tearDown  s     9T^RW-- 	*  '')))9T%rw// 	,!""))+++dl###r   c                     t          | j                  }t          | j                  }t          j        ||d           d S )N/test1)r   r-  ry   r   save_to_filenode)r%   r-  ry   s      r   test01_WriteToPathlibPathz1DirectReadWriteTestCase.test01_WriteToPathlibPath  s<    4+,,((	!+y(CCCCCr   c                 .   t          j        | j        | j        d           |                     t
          t           j        | j        | j        d           t          j        | j        | j        dd           t          j        | j        | j        dd           t          j        | j        | j        d           |                     t          | j                  
                                | j                   t          j                    5  t          j        d           |                     t
          t           j        | j        | j        d           d d d            n# 1 swxY w Y   t          j        | j        | j        ddd           |                     t          | j                  
                                | j                   t          | j                                                   t          | j                                                   d S )	Nr8  T	overwriter   test2r   r  )r   r=  )r   r9  r-  ry   r*   r   read_from_filenoder,  r!   r   r.  rr   r  catch_warningssimplefilterr  r,   s    r   test01_WriteToFilenamez.DirectReadWriteTestCase.test01_WriteToFilename  s8   !$"2DNHMMM'8#<d>N.(	4 	4 	4 	!$"2DNH,0	2 	2 	2 	2 	!$"2DNC'.	0 	0 	0 	0 	#D$4dnhOOOdn--88::DIFFF$&& 	J 	J!(+++gx'B".J J J	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J
 	#D$4dnc)0D	B 	B 	B 	B 	dn--88::DIFFFT^##%%%T%%'''''s   	AEE #E c                    t          j        | j        | j        d           |                     t
          t           j        | j        | j        d           t          j        | j        | j        dd           t          j        | j        | j        d           |                     t          | j                  
                                | j                   |                     t
          t           j        | j        | j        d           |                     t          | j        t          j                  d           |                     | j        j        d           d S )Nr8  Tr<  r   )r   r9  r   ry   r*   r   r@  r,  r!   r   r.  rr   
isinstancer   Filer   r,   s    r   test02_WriteToHDF5Filez.DirectReadWriteTestCase.test02_WriteToHDF5File  s(   !$+t~xHHH'8#<dk.(	4 	4 	4 	!$+t~x,0	2 	2 	2 	2 	#DKJJJdn--88::DIFFF'8#>.(	4 	4 	4 	DK;;TBBB)3/////r   c           	         t          j        | j        | j        d           t	          | j                  j        }t          j        | j        | j        d|                    dd                     | 	                    t          j        t	          | j                  |z  t          j                  d           | 	                    t	          | j                  |z                                  | j                   d S )Nr   ._r?  T)r   r9  r-  ry   r   r   r@  r0  replacer!   r2  r3  r4  r.  rr   r%   ry   s     r   test03_AutomaticNameGuessingz4DirectReadWriteTestCase.test03_AutomaticNameGuessing  s    !$"2DNCHHH((-	#D$4dlC)2):):3)D)D	F 	F 	F 	F 	4#5#5	#A27KK	 	 	 	$t|,,y8DDFF	$ 	$ 	$ 	$ 	$r   c                    t          j        | j        | j        d           t	          | j                  j        }t          j        | j        | j        d|           |                     t          j
        t	          | j                  |z  t          j                  d           |                     t	          | j                  |z                                  | j                   d S )Nr   r?  T)r   r9  r-  ry   r   r   r@  r0  r!   r2  r3  r4  r.  rr   rL  s     r   1test04_AutomaticNameGuessingWithFilenameAttributezIDirectReadWriteTestCase.test04_AutomaticNameGuessingWithFilenameAttribute  s    !$"2DNCHHH((-	#D$4dlC)2	4 	4 	4 	4 	4#5#5	#A27KK	 	 	 	$t|,,y8DDFF	$ 	$ 	$ 	$ 	$r   c                     t          j        | j        | j        d           |                     t
          t           j        | j        | j        dd           d S )Nr   THISNODEDOESNOTEXISTr?  )r   r9  r-  ry   r*   r   r@  r0  r,   s    r   $test05_ReadFromNonexistingNodeRaisesz<DirectReadWriteTestCase.test05_ReadFromNonexistingNodeRaises  sY    !$"2DNCHHH/8+F*DL#5 	 	7 	7 	7 	7 	7r   )r5   r6   r7   ry   r?   rD   r:  rC  rG  rM  rO  rR  rj   rk   s   @r   r*  r*  t  s        #I* * * * *&    D D D
( ( (<0 0 0($ $ $$ $ $7 7 7 7 7 7 7r   r*  c                  D   t          j                    } |                     t          j        t                               |                     t          j        t
                               |                     t          j        t                               |                     t          j        t                               |                     t          j        t                               |                     t          j        t                               |                     t          j        t                               |                     t          j        t                               |                     t          j        t                               | S )zesuite() -> test suite

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

    )r	   	TestSuiteaddTest	makeSuiter   r;   ru   r   r   r   r   r  r*  )theSuites    r   suiterX    s7    !##HX'88999X'(:;;<<<X'(9::;;;X'(899:::X'(899:::X'(<==>>> X'66777X'(<==>>>X'(?@@AAAOr   __main__rX  )defaultTest)rl   )'r8   r2  r5  r  r  pathlibr   r   r   r   r   nodesr   tests.commonr	   r
   r   r   r   TestCaser   r   r;   rs   ru   r   r   r   r   r   r  r  r(  r*  rX  r5   sysargvmainr9   r   r   <module>rb     s   ( ( 				          0 0 0 0 0 0 0 0 0 0      " " " " " " " " " " " " " "
8 8 8
$G $G $G $G $GmX $G $G $GNUI UI UI UI UI UI UI UIp' ' ' '[N [N [N [N [Nx [N [N [N|3M 3M 3M 3M 3M}h 3M 3M 3MBJ4 J4 J4 J4 J4}h J4 J4 J4Zg8 g8 g8 g8 g8}h g8 g8 g8T    +   DcH cH cH cH cHM8 cH cH cHL/D /D /D /D /D=( /D /D /DdX/ X/ X/ X/ X/ X/ X/ X/v' ' ' ' ') ' ' '}7 }7 }7 }7 }7mX }7 }7 }7@  0 zJJJJsxNHMg&&&&&&	 r   