
j\c           @@  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	   Z d
 e e f d     YZ d e e f d     YZ d d  Z d e e f d     YZ d e e f d     YZ d e e f d     YZ d e e f d     YZ d e f d     YZ d e e f d     YZ d e e f d     YZ  d e f d     YZ! d  e! f d!     YZ" d" e e f d#     YZ# d$   Z$ e% d% k r*d d l& Z& e e& j'  e   e j( d& d'  n  d S((   s"   Unit test for the filenode module.i    (   t   absolute_importN(   t   resource_filenamei   (   t	   open_filet   filet   NoSuchNodeError(   t   filenode(   t   unittestt   TempFileMixint
   parse_argvt   print_versionst   PyTablesTestCasec         C@  s   t  d |   S(   Ns   tables.nodes.tests(   R   (   t   name(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt	   test_file   s    t   NewFileTestCasec           B@  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s<   Tests creating a new file node with the new_node() function.c         C@  so   y4 t  j |  j d d d d } |  j j d  } Wn t k
 rT |  j d  n X|  j | j | d  d S(	   s"   Creation of a brand new file node.t   wheret   /R   t   tests   /tests0   filenode.new_node() failed to create a new node.s6   filenode.new_node() created a node in the wrong place.N(   R   t   new_nodet   h5filet   get_nodet   LookupErrort   failt   assertEqualt   node(   t   selft   fnodeR   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_NewFile%   s    	c         C@  s   |  j  t t j |  j  d S(   s@   Creation of a new file node without arguments for node creation.N(   t   assertRaisest	   TypeErrorR   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_NewFileTooFewArgs2   s    c         C@  sK   y& t  j |  j d d d d d d Wn t k
 rF |  j d  n Xd S(	   s9   Creation of a new file node with 'expectedsize' argument.R   R   R   R   t   expectedsizei s=   filenode.new_node() failed to accept 'expectedsize' argument.N(   R   R   R   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_NewFileWithExpectedSize7   s
     c      
   C@  s/   |  j  t t j |  j d d d d d d d S(   sA   Creation of a new file node with illegal 'expectedrows' argument.R   R   R   R   t   expectedrowsi N(   R   R   R   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test03_NewFileWithExpectedRowsA   s    	(   t   __name__t
   __module__t   __doc__R   R   R   R!   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR   "   s
   			
t   ClosedFileTestCasec           B@  s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z d   Z d   Z RS(   s/   Tests calling several methods on a closed file.c         C@  sE   t  t |   j   t j |  j d d d d |  _ |  j j   d S(   s  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   R   N(   t   superR%   t   setUpR   R   R   R   t   close(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'   L   s    
!c         C@  s    d |  _ t t |   j   d S(   sI   tearDown() -> None

        Closes 'h5file'; removes 'h5fname'.

        N(   t   NoneR   R&   R%   t   tearDown(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*   Z   s    	c         C@  s6   y |  j  j   Wn t k
 r1 |  j d  n Xd S(   s   Closing a closed file.s'   Could not close an already closed file.N(   R   R(   t
   ValueErrorR   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_Closef   s    c         C@  s   |  j  t |  j j  d S(   s   Flushing a closed file.N(   R   R+   R   t   flush(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_Flushn   s    c         C@  s   |  j  t t |  j  d S(   s'   Getting the next line of a closed file.N(   R   R+   t   nextR   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_Nexts   s    c         C@  s   |  j  t |  j j  d S(   s   Reading a closed file.N(   R   R+   R   t   read(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test03_Readx   s    c         C@  s   |  j  t |  j j  d S(   s"   Reading a line from a closed file.N(   R   R+   R   t   readline(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test04_Readline}   s    c         C@  s   |  j  t |  j j  d S(   s!   Reading lines from a closed file.N(   R   R+   R   t	   readlines(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test05_Readlines   s    c         C@  s   |  j  t |  j j d  d S(   s   Seeking a closed file.i    N(   R   R+   R   t   seek(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test06_Seek   s    c         C@  s   |  j  t |  j j  d S(   s.   Getting the pointer position in a closed file.N(   R   R+   R   t   tell(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test07_Tell   s    c         C@  s   |  j  t |  j j  d S(   s   Truncating a closed file.N(   R   R+   R   t   truncate(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test08_Truncate   s    c         C@  s   |  j  t |  j j d  d S(   s   Writing a closed file.t   fooN(   R   R+   R   t   write(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test09_Write   s    c         C@  s    |  j  t |  j j d g  d S(   s   Writing lines to a closed file.s   foo
N(   R   R+   R   t
   writelines(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test10_Writelines   s    (   R"   R#   R$   R'   R*   R,   R.   R0   R2   R4   R6   R8   R:   R<   R?   RA   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR%   I   s   												i   c         C@  sH   |  j  |  } x2 t |  d k rC | j |  |  j  |  } q Wd S(   s   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).

    i    N(   R1   t   lenR>   (   t   srcfilet   dstfilet	   blocksizet   data(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   copyFileToFile   s    t   WriteFileTestCasec           B@  sA   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z RS(   s6   Tests writing, seeking and truncating a new file node.s   test_filenode.datc         C@  sJ   t  t |   j   t j |  j d d d d |  _ t |  j  |  _ d S(   s  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   R   N(	   R&   RH   R'   R   R   R   R   R   t	   datafname(   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'      s    
!c         C@  s-   |  j  j   d |  _  t t |   j   d S(   sU   tearDown() -> None

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

        N(   R   R(   R)   R&   RH   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*      s    	c         C@  s8   t  |  j d  } z t | |  j  Wd | j   Xd S(   s   Writing a whole file node.t   rbN(   t   openRI   RG   R   R(   (   R   t   datafile(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_WriteFile   s    c         C@  se  |  j  j d  |  j  j d  |  j  j d  |  j  j d  |  j  j d  } |  j | d d  |  j  j d  |  j  j d	  |  j  j d  |  j  j d
  } |  j | d	 d  |  j  j d d  |  j  j d
  } |  j | d	 d  |  j  j d d  |  j  j   } |  j  j d d  |  j  j d	  |  j  j   } |  j | | d d
 d  d S(   s   Seeking and writing file node.t   0123i   t   4567i   i   s   3    4s3   Gap caused by forward seek was not properly filled.i    R   i   s)   Data was overwritten instead of appended.ii   s   Written data was not appended.is*   Pointer was not correctly moved on append.N(   R   R>   R7   R1   R   t   assertNotEqualR9   (   R   RF   t	   oldendofft	   newendoff(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_SeekFile   s2    c         C@  s   |  j  j d  |  j  j d  |  j t |  j  j  |  j  j d  |  j  j   |  j  j d  |  j  j   } |  j | d d  |  j  j d  |  j  j d  |  j  j   } |  j | d d	  d
 S(   s   Truncating a file node.R   i   i   i    s   test  s)   File was not grown to the current offset.i   s   test    s'   File was not grown to an absolute size.N(   R   R>   R7   R   t   IOErrorR;   R1   R   (   R   RF   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_TruncateFile   s    (	   R"   R#   R$   RI   R'   R*   RM   RS   RU   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyRH      s   					!t   OpenFileTestCasec           B@  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s<   Tests opening an existing file node for reading and writing.c         C@  s?   t  t |   j   t j |  j d d d d } | j   d S(   s   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   R   N(   R&   RV   R'   R   R   R   R(   (   R   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'     s    	c         C@  s   |  j  j d  } t j |  } |  j | j | d  |  j | j d d t | j   |  j | j   d d  | j	   d S(   s*   Opening an existing file node for reading.s   /tests+   filenode.open_node() opened the wrong node.t   rs(   File was opened with an invalid mode %s.i    s7   Pointer is not positioned at the beginning of the file.N(
   R   R   R   t	   open_nodeR   R   t   modet   reprR9   R(   (   R   R   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_OpenFileRead  s    	c         C@  s   |  j  j d  } t j | d  } |  j | j | d  |  j | j d d t | j   |  j | j   d d  | j	   d S(   s8   Opening an existing file node for reading and appending.s   /tests   a+s+   filenode.open_node() opened the wrong node.s(   File was opened with an invalid mode %s.i    s7   Pointer is not positioned at the beginning of the file.N(
   R   R   R   RX   R   R   RY   RZ   R9   R(   (   R   R   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_OpenFileReadAppend,  s    	c         C@  s)   |  j  t t j |  j j d  d  d S(   s3   Opening an existing file node with an invalid mode.s   /testt   wN(   R   RT   R   RX   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_OpenFileInvalidMode<  s    (   R"   R#   R$   R'   R[   R\   R^   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyRV     s
   			t   ReadFileTestCasec           B@  sA   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z RS(   s)   Tests reading from an existing file node.s   test_filenode.xbmc         C@  s   t  |  j  |  _ t |  j d  |  _ t t |   j   t j |  j	 d d d d } t
 |  j |  | j   |  j j d  t j |  j	 j d   |  _ d S(	   sR  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

        RJ   R   R   R   R   i    s   /testN(   R   RI   RK   RL   R&   R_   R'   R   R   R   RG   R(   R7   RX   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'   T  s    
c         C@  sC   |  j  j   d |  _  |  j j   d |  _ t t |   j   d S(   sa   tearDown() -> None

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

        N(   R   R(   R)   RL   R&   R_   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*   k  s
    		c         C@  s   yL d d l  } | j |  j j    j   } | j |  j j    j   } WnY t k
 r d d l } | j |  j j    j   } | j |  j j    j   } n X|  j | | d  d S(   s(   Reading and comparing a whole file node.i    Ns?   Data read from file node differs from that in the file on disk.(	   t   hashlibt   md5RL   R1   t   digestR   t   ImportErrort   newR   (   R   R`   t   dfiledigestt   fnodedigestRa   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_CompareFilez  s    ""c         C@  s   |  j  t |  j j d  d S(   s   Writing on a read-only file.s   no wayN(   R   RT   R   R>   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_Write  s    c         C@  sY   y$ d d l  m } | j |  j  Wn. t k
 r7 n t k
 rT |  j d  n Xd S(   s.   Using a file node with Python Imaging Library.i    (   t   Images7   PIL was not able to create an image from the file node.N(   t   PILRi   RK   R   Rc   RT   R   (   R   Ri   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_UseAsImageFile  s    (	   R"   R#   R$   RI   R'   R*   Rg   Rh   Rk   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR_   O  s   				t   ReadlineTestCasec           B@  sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   s   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         C@  s   t  t |   j   |  j } t j |  j d d d d } | j |  d | j d  f d } | j	 d  } | j |  | j d d	 |  | j d
  | j
   t j |  j j d   |  _ d S(   s  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   R   s   short line%sshort line%s%st   asciii   s
   long line i   t   unterminateds   /testN(   R&   Rl   R'   t   line_separatorR   R   R   R>   t   decodet   encodeR(   RX   R   R   (   R   t   linesepR   RF   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'     s    		
c         C@  s-   |  j  j   d |  _  t t |   j   d S(   sU   tearDown() -> None

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

        N(   R   R(   R)   R&   Rl   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*     s    	c         C@  s  |  j  } |  j j   } |  j | |  |  j j   } |  j j   } |  j | d |  |  j j   } |  j | |  |  j j   } |  j | d d |  |  j j   } |  j | d  |  j j   } |  j | d  |  j j   } |  j | d  d S(   s   Reading individual lines.s
   short lines
   long line i   Rn   t    N(   Ro   R   R3   R   (   R   Rr   t   line(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_Readline  s     	c         C@  s   |  j  } t |  } |  j j   |  j j   |  j j | d d  |  j j   } |  j | d | d  |  j j | d d  |  j j   } |  j | | d d | d  d	 S(
   s4   Reading individual lines and seeking back and forth.i   i   Rt   s$   Seeking back yielded different data.i   i
   s
   long line s&   Seeking forth yielded unexpected data.N(   Ro   RB   R   R3   R7   R   (   R   Rr   t   lseplenRt   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_ReadlineSeek  s    	c         C@  s   |  j  } x |  j D] } q W|  j t t |  j  |  j j d  t |  j  } |  j | |  t |  j  } |  j | d |  d S(   s   Iterating over the lines.i    s
   short lineN(   Ro   R   R   t   StopIterationR/   R7   R   (   R   Rr   Rt   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_Iterate  s    	c         C@  sN   |  j  } |  j j   } |  j | | d | d | | d d | d g  d S(   s   Reading a list of lines.s
   short lines
   long line i   Rn   N(   Ro   R   R5   R   (   R   Rr   t   lines(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test03_Readlines  s
    		c         C@  s*  |  j  } t |  } |  j j   } |  j j | d  } |  j | d |  |  j j d  } |  j | d  |  j j | d  } |  j | d |  |  j j |  } |  j | |  |  j j d d  |  j j d  } |  j | d	  |  j j d d  |  j j d  } |  j | d	  d
 S(   s)   Reading individual lines of limited size.i   s
   short linei   t   shorts    lineii   i   t   atedN(   Ro   RB   R   R3   R   R7   (   R   Rr   Rv   Rt   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test04_ReadlineSize  s"    	c         C@  s   |  j  } d | j d  f d } | j d  } |  j j t |   } |  j t |  t | j d    |  j | d  | d | g  |  j | d j	 d   d S(	   s,   Reading a list of lines with a limited size.s   %sshort line%sshortRm   i   s   
is
   short lineR|   N(
   Ro   Rp   Rq   R   R5   RB   R   t   splitt
   assertTruet
   startswith(   R   Rr   RF   Rz   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test05_ReadlinesSize5  s    	%(   R"   R#   R$   R'   R*   Ru   Rw   Ry   R{   R~   R   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyRl     s   						
	t   MonoReadlineTestCasec           B@  s   e  Z d  Z d Z RS(   sK   Tests reading one-byte-separated text lines from an existing
    file node.s   
(   R"   R#   R$   Ro   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR   I  s   t   AttrsTestCasec           B@  s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s/   Tests setting and getting file node attributes.c         C@  s8   t  t |   j   t j |  j d d d d |  _ d S(   s  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   R   N(   R&   R   R'   R   R   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'     s    
c         C@  s-   |  j  j   d |  _  t t |   j   d S(   sU   tearDown() -> None

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

        N(   R   R(   R)   R&   R   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*     s    	c         C@  sc   t  |  j j d d  } |  j | t j d  t  |  j j d d  } |  j | t j k d  d S(   s,   Mangling the type attributes on a file node.t	   NODE_TYPEs6   File node does not have a valid 'NODE_TYPE' attribute.t   NODE_TYPE_VERSIONs>   File node does not have a valid 'NODE_TYPE_VERSION' attribute.N(	   t   getattrR   t   attrsR)   R   R   t   NodeTypeR   t   NodeTypeVersions(   R   t   nodeTypet   nodeTypeVersion(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_MangleTypeAttrs  s    	c         C@  s   |  j  t |  j j d d  d d  d |  j j _ |  j  t |  j j d d  d d  d |  j j _ |  j  t |  j j d d  d d  |  j j ` |  j  t |  j j d d  d d  d S(	   s(   Setting a user attribute on a file node.t   userAttrs4   Inexistent attribute has a value that is not 'None'.t   foobars%   User attribute was not correctly set.t   bazquuxs)   User attribute was not correctly changed.s   User attribute was not deleted.N(   R   R   R   R   R)   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_SetGetDelUserAttr  s    c         C@  s*   |  j  j   |  j t t |  j  d  d S(   s+   Accessing attributes on a closed file node.R   N(   R   R(   R   t   AttributeErrorR   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test03_AttrsOnClosedFile  s    (   R"   R#   R$   R'   R*   R   R   R   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR     s   			#	t   ClosedH5FileTestCasec           B@  s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s6   Tests accessing a file node in a closed PyTables file.c         C@  sE   t  t |   j   t j |  j d d d d |  _ |  j j   d S(   s  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   R   N(   R&   R   R'   R   R   R   R   R(   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'     s    
!c         C@  ss   t  j d d t z) y |  j j   Wn t k
 r: n XWd t  j d d t Xd |  _ t t |   j	   d S(   sH   tearDown() -> None

        Closes 'fnode'; removes 'h5fname'.

        t   ignoret   categoryNt   default(
   t   warningst   filterwarningst   UserWarningR   R(   R+   R)   R&   R   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*     s    
 	c         C@  s   |  j  t |  j j d  d S(   s1   Writing to a file node in a closed PyTables file.RF   N(   R   R+   R   R>   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_Write  s    c         C@  s   |  j  t t |  j d  d S(   sJ   Accessing the attributes of a file node in a closed
        PyTables file.R   N(   R   R+   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_Attrs  s    (   R"   R#   R$   R'   R*   R   R   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR     s
   			t   OldVersionTestCasec           B@  s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s   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         C@  s   t  t |   j   t j d d  |  _ t |  j  |  _ t |  j  } | j	 |  j  | j
   t |  j d d d |  _ t j |  j j j d  |  _ d S(   s  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``.

        t   suffixs   .h5s   r+t   titles,   Test for file node old version compatibilitys   a+N(   R&   R   R'   t   tempfilet   mktempt   h5fnameR   t
   oldh5fnameR   t	   copy_fileR(   R   R   RX   t   rootR   R   (   R   t   oldh5f(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'   ,  s    	
c         C@  sS   |  j  j   d |  _  |  j j   d |  _ t j |  j  t t |   j	   d S(   s5   Closes ``fnode`` and ``h5file``; removes ``h5fname``.N(
   R   R(   R)   R   t   ost   removeR   R&   R   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*   B  s    		c         C@  s   |  j  j   } |  j | d  |  j  j   } |  j | d  |  j  j   } |  j | d |  j  |  j  j   } |  j | d  |  j  j d  |  j  j   } |  j | d  d S(   s!   Reading an old version file node.s   This is only
s   a test file
s   for FileNode version %d
Rs   i    N(   R   R3   R   t
   oldversionR7   (   R   Rt   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test00_ReadL  s    c         C@  sF   |  j  j d  |  j  j d d  |  j  j   } |  j | d  d S(   s!   Writing an old version file node.s   foobar
ii   N(   R   R>   R7   R3   R   (   R   Rt   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyRh   a  s    c         C@  s   d |  j  j _ |  j t |  j  j d d  d d  d |  j  j _ |  j t |  j  j d d  d d  |  j  j ` |  j t |  j  j d d  d d  d S(   s1   Accessing attributes in an old version file node.R   R   s%   User attribute was not correctly set.R   s)   User attribute was not correctly changed.s   User attribute was not deleted.N(   R   R   R   R   R   R)   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_Attributesk  s    (   R"   R#   R$   R'   R*   R   Rh   R   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR   #  s   		
		
t   Version1TestCasec           B@  s   e  Z d  Z d Z d Z RS(   s.   Basic test for version 1 format compatibility.i   s   test_filenode_v1.h5(   R"   R#   R$   R   R   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR   ~  s   t   DirectReadWriteTestCasec           B@  sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   s   test_filenode.datc         C@  s   t  t |   j   t |  j  |  _ t j   |  _ t j d d  |  _ t	 |  j d   } | j
   |  _ Wd QXt j   |  _ d S(   s  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   s   .h5RJ   N(   R&   R   R'   R   RI   R   R   t	   testfnamet   testh5fnameRK   R1   RF   t   mkdtempt   testdir(   R   t   fd(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR'     s    c         C@  s}   t  j |  j t  j  r+ t  j |  j  n  t  j |  j t  j  rV t  j |  j  n  t j |  j  t	 t
 |   j   d S(   sU   tearDown() -> None

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

        N(   R   t   accessR   t   R_OKR   R   t   shutilt   rmtreeR   R&   R   R*   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR*     s    c      	   C@  se  t  j |  j |  j d  |  j t t  j |  j |  j d  t  j |  j |  j d d t t  j |  j |  j d d d t  j |  j |  j d  t	 |  j d    } |  j
 | j   |  j  Wd  QX|  j t t  j |  j |  j d  t  j |  j |  j d d d d t t	 |  j d    } |  j
 | j   |  j  Wd  QXt j |  j  t j |  j  d  S(   Ns   /test1t	   overwriteR   R   t   test2RJ   (   R   t   save_to_filenodeR   RI   R   RT   t   Truet   read_from_filenodeR   RK   R   R1   RF   R   R   (   R   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test01_WriteToFilename  s$    c         C@  s  t  j |  j |  j d  |  j t t  j |  j |  j d  t  j |  j |  j d d t t  j |  j |  j d  t	 |  j d    } |  j
 | j   |  j  Wd  QX|  j t t  j |  j |  j d  |  j
 t |  j t j  t  |  j
 |  j j d  d  S(   Ns   /test1R   RJ   R]   (   R   R   R   RI   R   RT   R   R   R   RK   R   R1   RF   t
   isinstanceR   t   FileRY   (   R   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test02_WriteToHDF5File  s    c         C@  s   t  j |  j |  j d  t j j |  j  d } t  j |  j |  j d d | j	 d d  |  j
 t j t j j |  j |  t j  t  t t j j |  j |  d    } |  j
 | j   |  j  Wd  QXd  S(   NR   i   R   t   .t   _RJ   (   R   R   R   RI   R   t   pathR   R   R   t   replaceR   R   t   joinR   R   RK   R1   RF   (   R   RI   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   test03_AutomaticNameGuessing  s    !$c         C@  s   t  j |  j |  j d  t j j |  j  d } t  j |  j |  j d d | |  j	 t j
 t j j |  j |  t j  t  t t j j |  j |  d    } |  j	 | j   |  j  Wd  QXd  S(   NR   i   R   RJ   (   R   R   R   RI   R   R   R   R   R   R   R   R   R   R   RK   R1   RF   (   R   RI   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt1   test04_AutomaticNameGuessingWithFilenameAttribute  s    !$c         C@  sE   t  j |  j |  j d  |  j t t  j |  j |  j d d d d  S(   NR   R   t   THISNODEDOESNOTEXIST(   R   R   R   RI   R   R   R   R   (   R   (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt$   test05_ReadFromNonexistingNodeRaises  s    (
   R"   R#   RI   R'   R*   R   R   R   R   R   (    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyR     s   						c          C@  s   t  j   }  |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t	   |  j t  j t
   |  j t  j t   |  j t  j t   |  S(   se   suite() -> test suite

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

    (   R   t	   TestSuitet   addTestt	   makeSuiteR   R%   RH   RV   R_   R   R   R   R   (   t   theSuite(    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   suite  s    t   __main__t   defaultTestR   ()   R$   t
   __future__R    R   R   R   R   t   pkg_resourcesR   Rs   R   R   R   t   nodesR   t   tests.commonR   R   R   R	   R
   t   TestCaseR   R   R%   RG   RH   RV   R_   Rl   R   R   R   R   R   R   R   R"   t   syst   argvt   main(    (    (    s?   lib/python2.7/site-packages/tables/nodes/tests/test_filenode.pyt   <module>   s:   (	'X^BPBf2[~	