
    Ib                         d Z ddlZddlZddlZddlZddlmc mZ ej                  j                  ej                  j                  e            Z G d dej                        Zy)zTest the bundler tools.    Nc                   f    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d Zd Zy)TestBundlerToolsc                 6    t        j                         | _        y )N)tempfilemkdtemptmpselfs    K/usr/lib/python3/dist-packages/notebook/bundler/tests/test_bundler_tools.pysetUpzTestBundlerTools.setUp   s    ##%    c                 F    t        j                  | j                  d       y )NT)ignore_errors)shutilrmtreer   r	   s    r   tearDownzTestBundlerTools.tearDown   s    dhhd3r   c                 j    t        j                  ddd      }| j                  t        |      d       y)z4Should find no references in a regular HTML comment.z!<--
a
b
c
-->markdownsource	cell_typer   N)toolsget_cell_reference_patternsassertEquallenr
   no_referencess     r   test_get_no_cell_referencesz,TestBundlerTools.test_get_no_cell_references   s9    99 E 	;  !
 	]+Q/r   c                     ddd}t        j                  |      }| j                  d|v xr d|v t        |             | j	                  t        |      dt        |             y)zGShould find two references and ignore a comment within an HTML comment.r   z <!--associate:
a
b/
#comment
-->r   r   ab/   Nr   r   
assertTruestrr   r   r
   cell
referencess      r   2test_get_cell_reference_patterns_comment_multilinezCTestBundlerTools.test_get_cell_reference_patterns_comment_multiline   ^    & 2 
 66t<
z)@dj.@#j/RZ!S_=r   c                     ddd}t        j                  |      }| j                  d|v xr
 d|v xr d|v t        |             | j	                  t        |      dt        |             y)	z4Should find three references within an HTML comment.r   z!<!--associate:c
a
b/
#comment
-->r    r!   r"   c   Nr$   r'   s      r   :test_get_cell_reference_patterns_comment_trailing_filenamezKTestBundlerTools.test_get_cell_reference_patterns_comment_trailing_filename)   k    & 2 
 66t<
z)Vdj.@VSJEVX[\fXghZ!S_=r   c                     | j                  t        j                         t        j                  ddd      }| j                  t	        |      d       y)zBShould find no references in a fenced code block in a *code* cell.z```
foo
bar
baz
```
coder   r   N)r%   r   r   r   r   r   s     r   (test_get_cell_reference_patterns_precodez9TestBundlerTools.test_get_cell_reference_patterns_precode4   sK    99:99 E
 ;  	]+Q/r   c                     ddd}t        j                  |      }| j                  d|v xr d|v t        |             | j	                  t        |      dt        |             y)zGShould find two references and ignore a comment in a fenced code block.r   z```
a
b/
#comment
```r    r!   r"   r#   Nr$   r'   s      r   2test_get_cell_reference_patterns_precode_mdcommentzCTestBundlerTools.test_get_cell_reference_patterns_precode_mdcomment?   r+   r   c                     ddd}t        j                  |      }| j                  d|v xr
 d|v xr d|v t        |             | j	                  t        |      dt        |             y)	z4Should find three references in a fenced code block.r   z```c
a
b/
#comment
```r    r!   r"   r-   r.   Nr$   r'   s      r   2test_get_cell_reference_patterns_precode_backtickszCTestBundlerTools.test_get_cell_reference_patterns_precode_backticksJ   r0   r   c                     | j                  t        j                  j                  dd      t	        j
                  t        dg             y)z9Should expand to single file in the resources/ subfolder.	resourcesempty.ipynbzresources/empty.ipynbNassertInospathjoinr   expand_referencesHEREr	   s    r   test_glob_dirzTestBundlerTools.test_glob_dirU   s4    bggll;>##D+B*CD	Fr   c                     | j                  t        j                  j                  dd      t	        j
                  t        dg             y)z7Should expand to all files in the resources/ subfolder.r9   r:   z
resources/Nr;   r	   s    r   test_glob_subdirz!TestBundlerTools.test_glob_subdirZ   s1    bggll;>##D<.9	;r   c                     t        j                  t        dg      }| j                  d||       | j                  d||       y)z9Should expand to all contents under this test/ directory.*ztest_bundler_tools.pyr9   N)r   r@   rA   r<   r
   globss     r   test_glob_splatz TestBundlerTools.test_glob_splat_   s7    ''se4-ue<k5%0r   c                     t        j                  t        dg      }| j                  t        j
                  j                  ddd      ||       y)z?Should expand to test_file.txt deep under this test/ directory.zresources/**/test_file.txtr9   subdirtest_file.txtNr   r@   rA   r<   r=   r>   r?   rG   s     r   test_glob_splatsplat_in_middlez/TestBundlerTools.test_glob_splatsplat_in_middlee   s:    ''/K.LMbggll;/JESXYr   c                     t        j                  t        dg      }| j                  t        j
                  j                  dd      ||       | j                  t        j
                  j                  ddd      ||       y)z9Should expand to all descendants of this test/ directory.zresources/**r9   r:   rK   rL   NrM   rG   s     r   test_glob_splatsplat_trailingz.TestBundlerTools.test_glob_splatsplat_trailingj   sX    ''~.>?bggll;>uMbggll;/JESXYr   c                    t        j                  t        dg      }| j                  t        j
                  j                  ddd      ||       | j                  t        j
                  j                  ddd      ||       y)z.Should expand to test_file.txt under any path.**/test_file.txtr9   rK   rL   another_subdirNrM   rG   s     r   test_glob_splatsplat_leadingz-TestBundlerTools.test_glob_splatsplat_leadingp   s^    ''/A.BCbggll;/JESXYbggll;0@/RTY[`ar   c           
         t        j                  t        dg      }t        j                  t        | j                  |       | j                  t        j                  j                  t        j                  j                  | j                  ddd                   | j                  t        j                  j                  t        j                  j                  | j                  ddd                   | j                  t        j                  j                  t        j                  j                  | j                  dd                   y)z3Should copy select files from source to destinationrR   r9   rK   rL   rS   r:   N)r   r@   rA   copy_filelistr   r%   r=   r>   isfiler?   assertFalserG   s     r   test_copy_filelistz#TestBundlerTools.test_copy_filelistv   s    ''/A.BCD$((E2rww||DHHk8Ud'efgrww||DHHkK[]l'mnoTXX{M(Z[\r   N)__name__
__module____qualname__r   r   r   r*   r/   r3   r5   r7   rB   rD   rI   rN   rP   rT   rY    r   r   r   r      sR    &40	>	>	0	>	>F
;
1Z
Zb]r   r   )__doc__unittestr=   r   r   notebook.bundler.toolsbundlerr   r>   abspathdirname__file__rA   TestCaser   r]   r   r   <module>rf      sQ    
  	   & &	wwrwwx01n]x(( n]r   