o !bSI@sddlZddlZddlZddlZddlZddlmZddlmZddl m Z Gdddej Z ddZ ed kr?ejdd dSdS) N)TEXT)TemplateLoader)MarkupTemplatec@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.S)/TemplateLoaderTestCasezTests for the template loader.cCstjdd|_dS)N markup_test)suffix)tempfilemkdtempdirnameselfr >/usr/lib/python3/dist-packages/genshi/template/tests/loader.pysetUpszTemplateLoaderTestCase.setUpcCst|jdSN)shutilrmtreer r r r rtearDownszTemplateLoaderTestCase.tearDowncCst}|g|jdSr)r assertEqual search_pathr loaderr r rtest_search_path_empty"sz-TemplateLoaderTestCase.test_search_path_emptycCs t|j}||jg|jdSr)rr rrrr r rtest_search_path_as_string&s z1TemplateLoaderTestCase.test_search_path_as_stringcCsttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wt|jg}|d}| d| j dddSN tmpl1.htmlw
Included
tmpl2.htmlt <
Included
encoding openospathjoinr writecloserloadrgeneraterenderr file1file2rtmplr r rtest_relative_include_samedir*s    z4TemplateLoaderTestCase.test_relative_include_samedircCsttj|jdttj|jddd}z |dW|n|wttj|jdd}z |dW|n|wt|jg}| d}| d| j dddS) Nsubrrrrzx r r!) r%mkdirr&r'r r$r(r)rr*rr+r,r-r r rtest_relative_include_subdir?s    z3TemplateLoaderTestCase.test_relative_include_subdircCsttj|jdd}z |dW|n|wttj|jdttj|jddd}z |dW|n|wt|jg}| d}| d| j dd dS) Nrrrr2rzw sub/tmpl2.htmlr r! r$r%r&r'r r(r)r3rr*rr+r,r-r r rtest_relative_include_parentdirUs    z6TemplateLoaderTestCase.test_relative_include_parentdircCsttj|jdd}z |dW|n|wttj|jdttj|jddd}z |dW|n|wttj|jddd}z |dW|n|wt|jg}| d}| d | j dd dS) Nrrz
Included tmpl1.html
r2z"
Included sub/tmpl1.html
rrr5zK
Included sub/tmpl1.html
r!r6r r.r/file3rr0r r r test_relative_include_samesubdirks$     z7TemplateLoaderTestCase.test_relative_include_samesubdircCsttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wt}|tj|jd}| d| j dddSrr#r-r r r)test_relative_include_without_search_paths  z@TemplateLoaderTestCase.test_relative_include_without_search_pathcCsttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wtdtj|jdd}|d| j dddSr r$r%r&r'r r(r)rrr+r,r r.r/r0r r r$test_relative_include_without_loaders  z;TemplateLoaderTestCase.test_relative_include_without_loadercCsttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wtdtj|jdd}|d| j dddS) Nrrrrr)filenamer r!r<r=r r r-test_relative_include_without_loader_relatives  zDTemplateLoaderTestCase.test_relative_include_without_loader_relativecCsttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wt}|tj|jd}| d| j dd dS) Nrrrrzr
tmpl3.htmlt zc
Included
r!r#r8r r r0test_relative_include_without_search_path_nesteds"   zGTemplateLoaderTestCase.test_relative_include_without_search_path_nestedcCsnttj|jdd}z |dW|n|wt|jg}tdd|d}| d| j dddS) Nrrrzo zsubdir/tmpl2.html)r?rz4
Included
r!) r$r%r&r'r r(r)rrrr+r,)r r.rtmpl2r r r,test_relative_include_from_inmemory_templates  zCTemplateLoaderTestCase.test_relative_include_from_inmemory_templatec Csttj|jdd}z |dW|n|wttj|jdttj|jddd}z |dW|n|wttj|jddd}z |dW|n|wt}| tj tj|jdd}| d| j dd dS) Nrrrr2
Included from sub
rrE
Included from sub
r!r$r%r&r'r r(r)r3rr*abspathrr+r,r8r r r)test_relative_absolute_template_preferreds(   z@TemplateLoaderTestCase.test_relative_absolute_template_preferredc Csttj|jdd}z |dW|n|wttj|jdttj|jddd}z|d|jW|n|wt}| tj tj|jdd}| d| j dddS) Nrrrr2rzw r r!rHr-r r rtest_absolute_includes$ z,TemplateLoaderTestCase.test_absolute_includecCstj|jd}t|ttj|dd}z |dW|n|wttj|dd}z |dW|n|wtj|jd}t|ttj|dd}z |dW|n|wt|}| tj|d}| d | j dd d|j vsJdS) NabsrrrBrz!
Included from abspath.
searchpathz$
Included from searchpath.
zM
Included from searchpath.
r!)r%r&r'r r3r$r(r)rr*rr+r,_cache)r rIr.r/rMr9rtmpl1r r rtest_abspath_caching+s,     z+TemplateLoaderTestCase.test_abspath_cachingcCspttj|jdd}z |dW|n|wttj|jdd}z |dW|n|wttj|jdttj|jddd}z |dW|n|wttj|jddd}z |dW|n|wt}| tj|jd}| d| j dd | tj|jdd}| d | j dd d|j vsJdS) NrrrBrrr2rFr r!rG)r$r%r&r'r r(r)r3rr*rr+r,rN)r r.r/r9file4rrOrDr r r0test_abspath_include_caching_without_search_pathKs6    zGTemplateLoaderTestCase.test_abspath_include_caching_without_search_pathcCs\ttj|jdd}z|ddW|n|wt|jgdd}| ddS)N tmpl.htmlwb
ö
iso-8859-1default_encoding r$r%r&r'r r(encoder)rr*r frr r rtest_load_with_default_encodingts z6TemplateLoaderTestCase.test_load_with_default_encodingcCs`ttj|jdd}z|ddW|n|wt|jgdd}|j ddddS)NrSrTrUrVzutf-8rWr!rYr[r r r test_load_with_explicit_encoding}s z7TemplateLoaderTestCase.test_load_with_explicit_encodingcCsttj|jdd}z |dW|n|wdd}t|jg|d}|d}| d| j dd|d}| d| j dddS) NrSrz5

Hello

cSsdd}|jd|dS)NcssD|D]\}}}|tur|rd||g}|||fVqdS)Nz, )rstripr'lower)streamctxtkinddataposr r r my_filters zZTemplateLoaderTestCase.test_load_with_callback..template_loaded..my_filterr)filtersinsert)templaterfr r rtemplate_loadedszGTemplateLoaderTestCase.test_load_with_callback..template_loaded)callbackz<

Hello, hello

r!r#)r fileobjrjrr0r r rtest_load_with_callbacks   z.TemplateLoaderTestCase.test_load_with_callbackc Cs0tj|jd}t|ttj|dd}z |dW|n|wtj|jdd}t|ttj|dd}z |dW|n|wtj|jdd}t|ttj|d d}z |d W|n|wt |t j ||d g}| d }| d | jdddS)a Test prefix delegation with the following layout: templates/foo.html sub1/templates/tmpl1.html sub2/templates/tmpl2.html Where sub1 and sub2 are prefixes, and both tmpl1.html and tmpl2.html incldue foo.html. templatesfoo.htmlr
Included foo
sub1rz from sub1 sub2r
tmpl2
rqrrsub1/tmpl1.htmlzJ
Included foo
from sub1 Nr!r%r&r'r r3r$r(r)makedirsrprefixedr*rr+r,) r dir1r.dir2r/dir3r9rr0r r r%test_prefix_delegation_to_directoriess4       z from sub1 from sub1 from sub1 rrsbarrAz
bar/tmpl3
rtruz
Included foo
from sub1
tmpl2
from sub1
bar/tmpl3
from sub1 Nr!rv) r ryr.rzr/r9r{rQrr0r r r2test_prefix_delegation_to_directories_with_subdirss<          zITemplateLoaderTestCase.test_prefix_delegation_to_directories_with_subdirsN)__name__ __module__ __qualname____doc__rrrrr1r4r7r:r;r>r@rCrErJrKrPrRr]r^rmr|r~r r r rrs0 )   .rcCs0t}|ttj|ttd|S)Ntest) unittest TestSuiteaddTestdoctest DocTestSuiterr makeSuiter)suiter r rr sr__main__) defaultTest)rr%rrr genshi.corergenshi.template.loaderrgenshi.template.markuprTestCaserrrmainr r r rs     t