o
    ~¨Êhçq  ã                   @   sH  d dl mZ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
 d dlmZmZ d dlmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZ d dlmZ d dlmZmZ d dlmZ d dl m!Z! d dl"m#Z$ d dl%m&Z& d dl'm(Z( ej)r‚d dlm*Z* nzd dl+m*Z* W n e,y™   d dl*m*Z* Y nw dd„ Z-dd„ Z.G dd„ de/ƒZ0G dd„ de0eƒZ1G dd„ de0eƒZ2G dd„ de0eƒZ3G dd „ d e0eƒZ4G d!d"„ d"e0eƒZ5G d#d$„ d$e0eƒZ6G d%d&„ d&e0eƒZ7G d'd(„ d(e0eƒZ8G d)d*„ d*e0eƒZ9G d+d,„ d,e0eƒZ:G d-d.„ d.e0eƒZ;G d/d0„ d0e0eƒZ<G d1d2„ d2e<ƒZ=G d3d4„ d4e0eƒZ>G d5d6„ d6e>ƒZ?G d7d8„ d8e>ƒZ@G d9d:„ d:e0eƒZAG d;d<„ d<e0eƒZBG d=d>„ d>e0eƒZCG d?d@„ d@e0eƒZDG dAdB„ dBe0eƒZEG dCdD„ dDe0eƒZFG dEdF„ dFe0eƒZGG dGdH„ dHe0eƒZHG dIdJ„ dJe0eƒZIeejJdKk dLƒG dMdN„ dNe0eƒƒZKG dOdP„ dPe0eƒZLdS )Qé    )Úwith_statementÚunicode_literalsN)Úimport_module)Úpatch)ÚSkipTestÚskipIf)Úcall_command)ÚCommandError)ÚTemplateÚContext)ÚTestCase)Úoverride_settings)Úsix)Úflush_offline_manifestÚget_offline_manifest)Úsettings)ÚOfflineGenerationError)ÚCommand)Údefault_storage)Úget_mod_func)ÚStringIOc                  c   s$   � t ddƒD ]	} dd|  iV  qd S )Né   é   ÚcontentzOK %d!)Úrange)Úi© r   úO/var/www/html/env/lib/python3.10/site-packages/compressor/tests/test_offline.pyÚoffline_context_generator$   s   €ÿr   c                   c   s   � dt jiV  d S )NÚ
STATIC_URL)r   r   r   r   r   r   Ústatic_url_context_generator)   s   €r    c                   @   s†   e Zd ZdZdZdZdZdZdZdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ Zdd„ Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS ) ÚOfflineTestCaseMixinútest_compressor_offline.htmlr   Ú )ÚdjangoÚjinja2Nc                    sŽ  t ƒ ˆ _t tj¡}tj |d d d ˆ j	¡}tj |d d d ˆ j	¡}|g|d d< |g|d d< |dddœ}dˆ j
v rG‡ fdd„|d	< ˆ jd urR| ˆ j¡ ˆ jdi |¤Žˆ _ˆ j ¡  d
ˆ j
v rŽtj |ˆ j¡ˆ _tjˆ jtjd��}t| ¡ ƒˆ _W d   ƒ n1 s‰w   Y  dˆ j
v rÅtj |ˆ j¡ˆ _|d	 ƒ }tjˆ jtjd��}| | ¡ ¡ˆ _W d   ƒ d S 1 s¾w   Y  d S d S )Nr   ÚDIRSr   T)Ú	TEMPLATESÚCOMPRESS_ENABLEDÚCOMPRESS_OFFLINEr%   c                      s   ˆ   ¡ S ©N)Ú_get_jinja2_envr   ©Úselfr   r   Ú<lambda>T   s    z,OfflineTestCaseMixin.setUp.<locals>.<lambda>ÚCOMPRESS_JINJA2_GET_ENVIRONMENTr$   ©Úencodingr   )r   ÚlogÚcopyÚdeepcopyr   r'   ÚosÚpathÚjoinÚtemplates_dirÚenginesÚadditional_test_settingsÚupdater   Ú	__enter__Útemplate_nameÚtemplate_pathÚioÚopenÚFILE_CHARSETr
   ÚreadÚtemplateÚtemplate_path_jinja2Úfrom_stringÚtemplate_jinja2)r-   r'   Údjango_template_dirÚjinja2_template_dirr   Úfile_Ú
jinja2_envr   r,   r   ÚsetUp7   sV   
ÿÿý

ÿ


ÿÿþ
ÿ
ÿ"þûzOfflineTestCaseMixin.setUpc                 C   s:   | j  d d d ¡ tj dd¡}t |¡rt |¡ d S d S )NÚCACHEúmanifest.json)r   Ú__exit__r5   r6   r7   r   ÚexistsÚdelete)r-   Úmanifest_pathr   r   r   ÚtearDownm   s
   
ÿzOfflineTestCaseMixin.tearDownc                 C   s@   t j}t|ttfƒs|g}|dkrdd„ |D ƒS |dkr|S d S )Nr$   c                 S   ó   g | ]}t |ƒ‘qS r   ©r   ©Ú.0Úcr   r   r   Ú
<listcomp>y   ó    z:OfflineTestCaseMixin._prepare_contexts.<locals>.<listcomp>r%   )r   ÚCOMPRESS_OFFLINE_CONTEXTÚ
isinstanceÚlistÚtuple©r-   ÚengineÚcontextsr   r   r   Ú_prepare_contextst   s   z&OfflineTestCaseMixin._prepare_contextsc                    sR   ˆ   |¡}|dkrd ‡ fdd„|D ƒ¡S |dkr'd ‡ fdd„|D ƒ¡d S d S )Nr$   r#   c                 3   ó   � | ]	}ˆ j  |¡V  qd S r*   )rC   ÚrenderrU   r,   r   r   Ú	<genexpr>�   s   € z8OfflineTestCaseMixin._render_template.<locals>.<genexpr>r%   Ú
c                 3   rb   r*   )rF   rc   rU   r,   r   r   rd   ƒ   s   € 
ÿ)ra   r7   r^   r   r,   r   Ú_render_template~   s   
ÿÿz%OfflineTestCaseMixin._render_templatec                 C   ó   d  tj|¡S )Nz?<script type="text/javascript" src="{}CACHE/js/{}.js"></script>©Úformatr   ÚCOMPRESS_URL_PLACEHOLDER©r-   Úhashr   r   r   Ú_render_script‡   ó
   ÿþz#OfflineTestCaseMixin._render_scriptc                 C   rg   )NzC<link rel="stylesheet" href="{}CACHE/css/{}.css" type="text/css" />rh   rk   r   r   r   Ú_render_link�   rn   z!OfflineTestCaseMixin._render_linkre   c                 C   s   |  |¡d  tjtj¡S ©Nre   )r7   Úreplacer   rj   ÚCOMPRESS_URL©r-   ÚresultÚ	separatorr   r   r   Ú_render_result—   s   ÿz#OfflineTestCaseMixin._render_resultc                    s~   ˆ j }t|ttfƒs|g}tƒ jˆ jˆ j|d�\}}ˆ  t	|ƒ|¡ ˆ  ‡ fdd„|D ƒ|¡ ˆ  
|¡}ˆ  |ˆ  |¡¡ d S )N©r2   Ú	verbosityr_   c                    s   g | ]}ˆ   |¡‘qS r   ©rm   )rV   Úhr,   r   r   rX   £   s    z6OfflineTestCaseMixin._test_offline.<locals>.<listcomp>)Úexpected_hashr[   r\   r]   ÚCompressCommandÚcompressr2   rx   ÚassertEqualÚlenrf   rv   )r-   r_   ÚhashesÚcountrt   Úrendered_templater   r,   r   Ú_test_offlineœ   s   

ÿ
z"OfflineTestCaseMixin._test_offlinec                 C   ó"   d| j vr	tdƒ‚| jdd� d S )Nr$   z/This test class does not support django engine.©r_   ©r9   r   rƒ   r,   r   r   r   Útest_offline_django§   ó   
z(OfflineTestCaseMixin.test_offline_djangoc                 C   r„   )Nr%   z/This test class does not support jinja2 engine.r…   r†   r,   r   r   r   Útest_offline_jinja2¬   rˆ   z(OfflineTestCaseMixin.test_offline_jinja2c                 C   sd   dd l }dd l}ddlm}m} ddlm} |||jj|jj	g}|  
¡ }|j||d�}||jd< |S )Nr   )Úurl_forÚSpacelessExtension)ÚCompressorExtension)Ú
extensionsÚloaderrŠ   )r%   Ú
jinja2.extÚcompressor.offline.jinja2rŠ   r‹   Úcompressor.contrib.jinja2extrŒ   ÚextÚwith_ÚdoÚ_get_jinja2_loaderÚEnvironmentÚglobals)r-   r%   rŠ   r‹   rŒ   r�   rŽ   Úenvr   r   r   r+   ±   s   ü
z$OfflineTestCaseMixin._get_jinja2_envc                 C   s&   dd l }|jtjd d tjd�}|S )Nr   r   r&   r0   )r%   ÚFileSystemLoaderr   r'   rA   )r-   r%   rŽ   r   r   r   r•   Ä   s
   ÿz'OfflineTestCaseMixin._get_jinja2_loader©re   )Ú__name__Ú
__module__Ú__qualname__r=   rx   r8   r{   r9   r:   rK   rR   ra   rf   rm   ro   rv   rƒ   r‡   r‰   r+   r•   r   r   r   r   r!   -   s&    6
	
r!   c                   @   s¤   e Zd ZdZdZe ed¡dd„ ƒZe ed¡dd„ ƒZ	e ed¡dd	„ ƒZ
e ed¡d
d„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zededƒd�dd„ ƒZdS )ÚOfflineCompressBasicTestCaseÚbasicÚa432b6ddb2c4r}   c                 C   s   t ƒ  ¡  |  |jd¡ d S )Nr   )r|   Úhandler~   Ú
call_count©r-   Úcompress_mockr   r   r   Útest_handle_no_argsÐ   s   
z0OfflineCompressBasicTestCase.test_handle_no_argsc              	   C   ór   | j dd��" |  t¡� tƒ  ¡  W d   ƒ n1 sw   Y  W d   ƒ n1 s+w   Y  |  |jd¡ d S )NF)r(   r   ©r   ÚassertRaisesr	   r|   r¡   r~   r¢   r£   r   r   r   Útest_handle_compress_disabledÕ   ó   ÿ€ÿz:OfflineCompressBasicTestCase.test_handle_compress_disabledc              	   C   r¦   )NF©r)   r   r§   r£   r   r   r   Ú%test_handle_compress_offline_disabledÜ   rª   zBOfflineCompressBasicTestCase.test_handle_compress_offline_disabledc                 C   sL   | j dd�� tƒ jdd� W d   ƒ n1 sw   Y  |  |jd¡ d S )NFr«   T)Úforcer   )r   r|   r¡   r~   r¢   r£   r   r   r   Ú+test_handle_compress_offline_disabled_forceã   s   ÿzHOfflineCompressBasicTestCase.test_handle_compress_offline_disabled_forcec                 C   s    t ƒ  |  t| jjti ƒ¡ d S r*   )r   r¨   r   rC   rc   r   r,   r   r   r   Ú0test_rendering_without_manifest_raises_exceptioné   s   ÿzMOfflineCompressBasicTestCase.test_rendering_without_manifest_raises_exceptionc                 C   s   t ƒ  |  t| jji ¡ d S r*   )r   r¨   r   rF   rc   r,   r   r   r   Ú7test_rendering_without_manifest_raises_exception_jinja2ï   s   ÿzTOfflineCompressBasicTestCase.test_rendering_without_manifest_raises_exception_jinja2c                 C   s„   t ƒ j| j| j|d�\}}tƒ  tj dd¡}t 	|¡r!t 
|¡ |  d|¡ |  |  | j¡g|¡ |  |¡}|  ||  |¡¡ d S )Nrw   rL   rM   r   )r|   r}   r2   rx   r   r5   r6   r7   r   rO   rP   r~   rm   r{   rf   rv   )r-   r_   r�   rt   rQ   r‚   r   r   r   Ú1_test_deleting_manifest_does_not_affect_renderingõ   s   

ÿ


zNOfflineCompressBasicTestCase._test_deleting_manifest_does_not_affect_renderingc                 C   s   | j D ]}|  |¡ qd S r*   )r9   r±   ©r-   r_   r   r   r   Ú0test_deleting_manifest_does_not_affect_rendering  s   
ÿzMOfflineCompressBasicTestCase.test_deleting_manifest_does_not_affect_renderingc                 C   s€   d}| j |d��. ddlm} ddlm} tƒ  ¡ }|  t|d |ƒ¡ |  t|d |ƒ¡ W d   ƒ d S 1 s9w   Y  d S )N©)z%django.template.loaders.cached.Loader)z)django.template.loaders.filesystem.Loaderz.django.template.loaders.app_directories.Loader)ÚTEMPLATE_LOADERSr   )ÚLoaderr   )r   Ú"django.template.loaders.filesystemr¶   Ú'django.template.loaders.app_directoriesr|   Úget_loadersÚ
assertTruer[   )r-   rµ   r™   ÚAppDirectoriesLoaderÚloadersr   r   r   Útest_get_loaders  s   
"ùz-OfflineCompressBasicTestCase.test_get_loadersz2compressor.offline.django.DjangoParser.render_nodes   non-ascii character here:Ã¤)Úside_effectc                 C   s:   |   t¡� tƒ  ¡  W d   ƒ d S 1 sw   Y  d S r*   )r¨   r	   r|   r¡   )r-   Úmockr   r   r   Ú!test_non_ascii_exception_messages  s   "ÿz>OfflineCompressBasicTestCase.test_non_ascii_exception_messagesN)r›   rœ   r�   r8   r{   r   Úobjectr|   r¥   r©   r¬   r®   r¯   r°   r±   r³   r½   Ú	ExceptionrÀ   r   r   r   r   rž   Ì   s(    







ÿrž   c                   @   ó   e Zd ZdZdZdd„ ZdS )Ú%OfflineCompressSkipDuplicatesTestCaseÚtest_duplicate©r$   c                 C   s`   t ƒ j| j| j|d�\}}|  d|¡ |  |  d¡g|¡ |  |¡}|  ||  |d d¡¡ d S )Nrw   r   r    é   r#   ©r|   r}   r2   rx   r~   rm   rf   rv   ©r-   r_   r�   rt   r‚   r   r   r   rƒ   "  s   

ÿ
ÿz3OfflineCompressSkipDuplicatesTestCase._test_offlineN©r›   rœ   r�   r8   r9   rƒ   r   r   r   r   rÄ     s    rÄ   c                   @   ó   e Zd ZdZdZdZdS )Ú!OfflineCompressBlockSuperTestCaseÚtest_block_superÚ68c645740177rÆ   N©r›   rœ   r�   r8   r{   r9   r   r   r   r   rÌ   /  s    rÌ   c                   @   rË   )Ú)OfflineCompressBlockSuperMultipleTestCaseÚtest_block_super_multipleÚf87403f4d8afrÆ   NrÏ   r   r   r   r   rÐ   6  s    rÐ   c                   @   s    e Zd ZdZdZdZddiZdS )Ú5OfflineCompressBlockSuperMultipleCachedLoaderTestCaseÚ test_block_super_multiple_cachedÚea860151aa21rÆ   rµ   r´   N)r›   rœ   r�   r8   r{   r9   r:   r   r   r   r   rÓ   >  s    ÿrÓ   c                   @   rÃ   )Ú1OfflineCompressBlockSuperTestCaseWithExtraContentÚtest_block_super_extrarÆ   c                 C   sd   t ƒ j| j| j|d�\}}|  d|¡ |  |  d¡|  d¡g|¡ |  |¡}|  ||  |d¡¡ d S )Nrw   rÇ   Ú9717f9c7e9ffrÎ   r#   rÈ   rÉ   r   r   r   rƒ   T  s   

ÿþý
z?OfflineCompressBlockSuperTestCaseWithExtraContent._test_offlineNrÊ   r   r   r   r   rÖ   N  s    rÖ   c                   @   ó    e Zd ZdZdZdddiiZdS )Ú OfflineCompressConditionTestCaseÚtest_conditionÚ58517669cb7crZ   Ú	conditionÚredN©r›   rœ   r�   r8   r{   r:   r   r   r   r   rÚ   `  ó    ÿÿrÚ   c                   @   ó   e Zd ZdZdZdS )Ú"OfflineCompressTemplateTagTestCaseÚtest_templatetagÚ16f8880b81abN©r›   rœ   r�   r8   r{   r   r   r   r   râ   j  ó    râ   c                   @   rá   )Ú(OfflineCompressStaticTemplateTagTestCaseÚtest_static_templatetagÚ2607a2085687Nrå   r   r   r   r   rç   o  ræ   rç   c                   @   rÙ   )Ú"OfflineCompressTestCaseWithContextÚtest_with_contextÚ045b3ad664c8rZ   r   úOK!Nrß   r   r   r   r   rê   t  rà   rê   c                   @   s$   e Zd ZdZdZdddiiZdZdS )Ú'OfflineCompressTestCaseWithContextSuperÚtest_with_context_superÚ9a8b47adfe17rZ   r   rí   rÆ   N©r›   rœ   r�   r8   r{   r:   r9   r   r   r   r   rî   ~  s    ÿÿrî   c                   @   s.   e Zd ZdZg d¢Zdeeƒ ƒiZdd„ ZdS )Ú&OfflineCompressTestCaseWithContextListrë   ©Ú3b6cd13d4bdeÚ5aef37564182Úc6d6c723a18brZ   c                 C   s*   |dkrdd„ t jD ƒS |dkrt jS d S )Nr$   c                 S   rS   r   rT   rU   r   r   r   rX   “  rY   zLOfflineCompressTestCaseWithContextList._prepare_contexts.<locals>.<listcomp>r%   )r   rZ   r²   r   r   r   ra   ‘  s
   z8OfflineCompressTestCaseWithContextList._prepare_contextsN)	r›   rœ   r�   r8   r{   r\   r   r:   ra   r   r   r   r   rò   Š  s    
ÿrò   c                   @   s*   e Zd ZdZg d¢Zdeeƒ ƒiZdZdS )Ú+OfflineCompressTestCaseWithContextListSuperrï   ©Údc68dd60aed4Úc2e50f475853Ú045b48455beerZ   rÆ   N)	r›   rœ   r�   r8   r{   r\   r   r:   r9   r   r   r   r   r÷   ™  s    
ÿr÷   c                   @   s(   e Zd ZdZg d¢ZddiZdd„ ZdS )Ú+OfflineCompressTestCaseWithContextGeneratorrë   ró   rZ   ú7compressor.tests.test_offline.offline_context_generatorc                 C   sD   t tjƒ\}}tt|ƒ|ƒƒ }|dkrdd„ |D ƒS |dkr |S d S )Nr$   c                 s   s   � | ]}t |ƒV  qd S r*   rT   rU   r   r   r   rd   ±  s   € zPOfflineCompressTestCaseWithContextGenerator._prepare_contexts.<locals>.<genexpr>r%   )r   r   rZ   Úgetattrr   )r-   r_   ÚmoduleÚfunctionr`   r   r   r   ra   ­  s   z=OfflineCompressTestCaseWithContextGenerator._prepare_contextsN)r›   rœ   r�   r8   r{   r:   ra   r   r   r   r   rü   ¤  s    ÿrü   c                   @   s$   e Zd ZdZg d¢ZddiZdZdS )Ú0OfflineCompressTestCaseWithContextGeneratorSuperrï   rø   rZ   rý   rÆ   Nrñ   r   r   r   r   r  ·  s    ÿr  c                   @   s*   e Zd ZdZdZdZdddœZdd„ Zd	S )
Ú,OfflineCompressStaticUrlIndependenceTestCasea  
    Test that the offline manifest is independent of STATIC_URL.
    I.e. users can use the manifest with any other STATIC_URL in the future.

    We use COMPRESS_OFFLINE_CONTEXT generator to make sure that
    STATIC_URL is not cached when rendering the template.
    Útest_static_url_independenceÚ5014de5edcbez/custom/static/url/z:compressor.tests.test_offline.static_url_context_generator)r   rZ   c                 C   sž   t ƒ j| j| j|d�\}}|  d|¡ |  |  | j¡g|¡ |  |  |¡|  |¡¡ | j	dd�� |  |  |¡|  |¡¡ W d   ƒ d S 1 sHw   Y  d S )Nrw   r   z/another/static/url/)r   )
r|   r}   r2   rx   r~   rm   r{   rf   rv   r   ©r-   r_   r�   rt   r   r   r   rƒ   Õ  s   

ÿÿÿ"ÿz:OfflineCompressStaticUrlIndependenceTestCase._test_offlineN)r›   rœ   r�   Ú__doc__r8   r{   r:   rƒ   r   r   r   r   r  Ã  s    ýr  c                       s2   e Zd ZdZdZdddiiZd	‡ fdd„	Z‡  ZS )
Ú5OfflineCompressTestCaseWithContextVariableInheritanceÚ&test_with_context_variable_inheritanceÚ0d88c897f64arZ   Úparent_templateú	base.htmlre   c                    s   dt t| ƒ ||¡ S rp   )Úsuperr  rv   rs   ©Ú	__class__r   r   rv   ï  s
   ÿþzDOfflineCompressTestCaseWithContextVariableInheritance._render_resultrš   )r›   rœ   r�   r8   r{   r:   rv   Ú__classcell__r   r   r  r   r  å  s    ÿÿr  c                   @   s0   e Zd ZdZdddiddigiZddgZdZd	S )
Ú:OfflineCompressTestCaseWithContextVariableInheritanceSuperÚ,test_with_context_variable_inheritance_superrZ   r
  z
base1.htmlú
base2.htmlÚ6a2f85c623c6Ú04b482ba2855rÆ   N)r›   rœ   r�   r8   r:   r{   r9   r   r   r   r   r  õ  s    ÿÿþÿr  c                   @   ó   e Zd ZdZdd„ ZdS )Ú6OfflineCompressTestCaseWithContextGeneratorImportErrorrë   c              	   C   sv  | j dd�� | jttƒ j|d� W d   ƒ n1 sw   Y  | j dd�� | jttƒ j|d� W d   ƒ n1 s;w   Y  | j dd�� | jttƒ j|d� W d   ƒ n1 s[w   Y  | j dd�� | jttƒ j|d� W d   ƒ n1 s{w   Y  d}| j |d��) z	tƒ j|d� W n ty    |  d¡ Y n	w W d   ƒ d S W d   ƒ d S 1 s´w   Y  d S )	Nzinvalid_mod.invalid_func)rZ   r…   Ú
compressorz!compressor.tests.invalid_functionzcompressor.tests.test_offlinerý   zCValid path to offline context generator must not raise ImportError.)r   r¨   ÚImportErrorr|   r}   Úfail)r-   r_   Ú
valid_pathr   r   r   rƒ     sJ   ÿ
ÿý
ÿþÿ
ÿýÿ
ÿýÿÿü"úzDOfflineCompressTestCaseWithContextGeneratorImportError._test_offlineN©r›   rœ   r�   r8   rƒ   r   r   r   r   r    s    r  c                   @   r  )ÚOfflineCompressTestCaseErrorsÚtest_error_handlingc                 C   s”   t ƒ j| j| j|d�\}}|dkr|  d|¡ n|  d|¡ |  |d¡ |  |  d¡|¡ |  |  d¡|¡ |  |  d¡|¡ |  |  d	¡|¡ d S )
Nrw   r$   rÇ   r   r%   Ú7ff52cb38987Ú2db2b4d36380Ú3910ce35946aÚ244f05154671)r|   r}   r2   rx   r~   ÚassertInro   rm   r  r   r   r   rƒ   2  s   

ÿz+OfflineCompressTestCaseErrors._test_offlineNr  r   r   r   r   r  /  s    r  c                   @   s    e Zd ZdZddiZdd„ ZdS )Ú OfflineCompressTestCaseWithErrorr  ÚCOMPRESS_PRECOMPILERS))ztext/coffeescriptznonexisting-binaryc                 C   s†   | j dd�� | jttƒ j|d� W d  ƒ n1 sw   Y  | j dd�� | jttƒ j|d� W d  ƒ dS 1 s<w   Y  dS )z°
        Test that a CommandError is raised with DEBUG being False as well as
        True, as otherwise errors in configuration will never show in
        production.
        T)ÚDEBUGr…   NF)r   r¨   r	   r|   r}   r²   r   r   r   rƒ   L  s   
ÿÿ
ÿ"ÿz.OfflineCompressTestCaseWithError._test_offlineN©r›   rœ   r�   r8   r:   rƒ   r   r   r   r   r#  F  s
    ÿr#  c                   @   s$   e Zd ZdZdZdZdZdd„ ZdS )ÚOfflineCompressEmptyTaga  
        In case of a compress template tag with no content, an entry
        will be added to the manifest with an empty string as value.
        This test makes sure there is no recompression happening when
        compressor encounters such an emptystring in the manifest.
    rŸ   r    rÆ   c                 C   sF   t ƒ j| j| j|d�\}}tƒ }d|t|ƒd < |  |  |¡d¡ d S )Nrw   r#   r   re   )r|   r}   r2   rx   r   r\   r~   rf   )r-   r_   r�   rt   Úmanifestr   r   r   rƒ   f  s   

ÿz%OfflineCompressEmptyTag._test_offlineN)r›   rœ   r�   r  r8   r{   r9   rƒ   r   r   r   r   r'  [  s    r'  c                       sL   e Zd Zg d¢ZdZg d¢Zg d¢ZdZ‡ fdd„Zdd	„ Z	d
d„ Z
‡  ZS )Ú'OfflineCompressBlockSuperBaseCompressed)r  r  r"   Ú test_block_super_base_compressed)Ú5a2fda9ac8e4Ú5b7c5e6473f8rÒ   )Ú028c3fc42232Ú2e9d3f5545a6rÒ   rÆ   c              	      sš   t t| ƒ ¡  g | _g | _| jD ]:}tj t	j
d d d |¡}| j |¡ tj|t	jd��}t| ¡ ƒ}W d   ƒ n1 s?w   Y  | j |¡ qd S )Nr   r&   r0   )r  r)  rK   Útemplate_pathsÚ	templatesÚtemplate_namesr5   r6   r7   r   r'   Úappendr?   r@   rA   r
   rB   )r-   r=   r>   rI   rC   r  r   r   rK   w  s    
ÿÿþùz-OfflineCompressBlockSuperBaseCompressed.setUpc                 C   s4   |dkr|  ttjƒ¡S |dkr|  tj¡d S d S )Nr$   r%   re   )rc   r   r   rZ   )r-   rC   r_   r   r   r   rf   …  s
   z8OfflineCompressBlockSuperBaseCompressed._render_templatec                 C   s~   t ƒ j| j| j|d�\}}|  t| jƒ|¡ t| j| j	ƒD ]\}}|  
|¡}|  ||¡ |  ||¡}|  ||  |g¡¡ qd S )Nrw   )r|   r}   r2   rx   r~   r   r{   ÚzipÚexpected_hash_offliner0  rm   r"  rf   rv   )r-   r_   r�   rt   r{   rC   Úexpectedr‚   r   r   r   rƒ   �  s   

ÿ
ÿüz5OfflineCompressBlockSuperBaseCompressed._test_offline)r›   rœ   r�   r1  r8   r4  r{   r9   rK   rf   rƒ   r  r   r   r  r   r)  n  s    r)  c                   @   s$   e Zd ZdZdddiiZdd„ ZdS )Ú%OfflineCompressInlineNonAsciiTestCaseÚtest_inline_non_asciirZ   Útest_non_ascii_valueu   â€”c                 C   s>   t ƒ j| j| j|d�\}}|  |¡}|  |d |¡d ¡ d S )Nrw   r#   re   )r|   r}   r2   rx   rf   r~   r7   rÉ   r   r   r   rƒ   ¡  s
   

ÿ
z3OfflineCompressInlineNonAsciiTestCase._test_offlineNr&  r   r   r   r   r6  ™  s    ÿÿr6  c                   @   s&   e Zd ZdZddddœiZdd„ ZdS )	ÚOfflineCompressComplexTestCaseÚtest_complexrZ   rí   )z	js/one.jszjs/nonasc.js)rÝ   Úmy_namesc                 C   sx   t ƒ j| j| j|d�\}}|  d|¡ |  |  d¡|  d¡|  d¡g|¡ |  |¡}|  ||  |d |d gd¡¡ d S )	Nrw   é   Ú2c1f0f85a90dÚ8b594c4f7264Úe0e424964c8cr   rÇ   r#   rÈ   rÉ   r   r   r   rƒ   ´  s   

ÿýü
ÿz,OfflineCompressComplexTestCase._test_offlineNr&  r   r   r   r   r9  ¨  s    ûÿ
r9  )r   é	   zANeeds Django >= 1.9, recursive templates were fixed in Django 1.9c                   @   s2   e Zd ZdZdZdZg d¢Zeed�dd„ ƒZdS )	Ú'OfflineCompressExtendsRecursionTestCasez�
    Test that templates extending templates with the same name
    (e.g. admin/index.html) don't cause an infinite test_extends_recursion
    Útest_extends_recursionrÆ   )zdjango.contrib.adminzdjango.contrib.authzdjango.contrib.contenttypeszdjango.contrib.staticfilesr  )ÚINSTALLED_APPSc                 C   s*   t ƒ j| j| j|d�\}}|  |d¡ d S )Nrw   r   )r|   r}   r2   rx   r~   r  r   r   r   rƒ   Ö  s   

ÿz5OfflineCompressExtendsRecursionTestCase._test_offlineN)	r›   rœ   r�   r  r8   r9   rC  r   rƒ   r   r   r   r   rA  Â  s    rA  c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚTestCompressCommandÚtest_compress_commandc                 C   s   t dƒ‚)NzNot utilized for this test case)r   r²   r   r   r   rƒ   à  s   z!TestCompressCommand._test_offlinec                    s   ‡ fdd„|  ¡ D ƒS )Nc                    s   i | ]
\}}|ˆ   |¡“qS r   ry   )rV   ÚkÚvr,   r   r   Ú
<dictcomp>ä  s    ÿz@TestCompressCommand._build_expected_manifest.<locals>.<dictcomp>)Úitems)r-   r5  r   r,   r   Ú_build_expected_manifestã  s   
ÿz,TestCompressCommand._build_expected_manifestc                 C   s²   ddt ƒ dœ}tdddgi|¤Ž tƒ }|  ddi¡}|  ||¡ tddd	gi|¤Ž tƒ }|  d
di¡}|  ||¡ tdddd	gi|¤Ž tƒ }|  dddœ¡}|  ||¡ d S )NTr   )r­   rx   r2   r}   r9   r$   Ú@0fed9c02607acba22316a328075a81a74e0983ae79470daa9d3707a337623dc3Ú023629c58235r%   Ú@077408d23d4a829b8f88db2eadcf902b29d71b14f94018d900f38a3f8ed24c94Úb6695d1aa847)rK  rM  )r}   )r   r   r   rJ  r~   )r-   ÚoptsÚmanifest_djangoÚmanifest_django_expectedÚmanifest_jinja2Úmanifest_jinja2_expectedÚmanifest_bothÚmanifest_both_expectedr   r   r   Útest_multiple_enginesè  s0   ýÿÿÿÿz)TestCompressCommand.test_multiple_enginesN)r›   rœ   r�   r8   rƒ   rJ  rV  r   r   r   r   rD  Ý  s
    rD  )MÚ
__future__r   r   r3   r$   r?   r5   Ú	importlibr   r¿   r   Úunittestr   r   Údjango.core.managementr   Údjango.core.management.baser	   Údjango.templater
   r   Údjango.testr   Údjango.test.utilsr   Údjango.utilsr   Úcompressor.cacher   r   Úcompressor.confr   Úcompressor.exceptionsr   Ú'compressor.management.commands.compressr   r|   Úcompressor.storager   Úcompressor.utilsr   ÚPY3r   Ú	cStringIOr  r   r    rÁ   r!   rž   rÄ   rÌ   rÐ   rÓ   rÖ   rÚ   râ   rç   rê   rî   rò   r÷   rü   r  r  r  r  r  r  r#  r'  r)  r6  r9  ÚVERSIONrA  rD  r   r   r   r   Ú<module>   s¤    ÿ  P
ÿ
ÿ
ÿ


ÿ
ÿ
ÿ
ÿ
"ÿ
ÿ
ÿ++þ