o !bq@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl m Z ddl mZddlmZddlmZmZddlmZmZddlmZGd d d ejZd d Zed kriejd ddSdS)N)BytesIOStringIO)Markup) Translator)XML)BadDirectiveErrorTemplateSyntaxError)TemplateLoaderTemplateNotFoundMarkupTemplatec@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.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dBdCZ$dDdEZ%dFdGZ&dHdIZ'dJdKZ(dLdMZ)dNdOZ*dPdQZ+dRdSZ,dTdUZ-dVdWZ.dXdYZ/dZd[Z0d\d]Z1d^d_Z2d`daZ3dbdcZ4dddeZ5dfS)gMarkupTemplateTestCasez%Tests for markup template processing.cC,td}t|}|dt|jdddSNz ${var} $varz 42 42*var)rr assertEqualstrgenerate)selffileobjtmplr>/usr/lib/python3/dist-packages/genshi/template/tests/markup.pytest_parse_fileobj$z)MarkupTemplateTestCase.test_parse_fileobjcCrr)rr rrr)rstreamrrrrtest_parse_stream)rz(MarkupTemplateTestCase.test_parse_streamcCsTtd}t|}t}t||d|dt|}|dt|j dddS)Nz$varrz42rr) rr rpickledumpseekloadrrr)rrrbuf unpickledrrr test_pickle.s  z"MarkupTemplateTestCase.test_picklecC$td}|dt|jdddSrr rrrrrrrrtest_interpolate_mixed37z.MarkupTemplateTestCase.test_interpolate_mixed3cCr')Nz${ foo }zbarbarfoor(r)rrr'test_interpolate_leading_trailing_space;r+z>MarkupTemplateTestCase.test_interpolate_leading_trailing_spacecCr')Nz:${dict( bar = 'baz' )[foo]}zbazr,r-r(r)rrrtest_interpolate_multiline?sz1MarkupTemplateTestCase.test_interpolate_multilinecC td}|dt|dS)Nzzr(r)rrr!test_interpolate_non_string_attrsEz8MarkupTemplateTestCase.test_interpolate_non_string_attrscCr')Nz$foozbuzz)buzzr-r(r)rrrtest_interpolate_list_resultIr+z3MarkupTemplateTestCase.test_interpolate_list_resultcCs td}|dt|dS)Nr(r)rrrtest_empty_attrMr3z&MarkupTemplateTestCase.test_empty_attrcCr')Nzr6)attrr(r)rrrtest_empty_attr_interpolatedQr+z3MarkupTemplateTestCase.test_empty_attr_interpolatedc CsZd}z t|dd}WdSty,}z|d|j|d|jWYd}~dSd}~ww)Nz<

test.htmlfilename)r rrr=linenorxmlrerrrtest_bad_directive_errorUsz/MarkupTemplateTestCase.test_bad_directive_errorc Cshd}zt|dd}|dWdSty3}z|d|j|d|jWYd}~dSd}~ww)Nz9

r;r<Expected TemplateSyntaxErrorr>)r rfailrrr=r?r@rrr!test_directive_value_syntax_error]sz8MarkupTemplateTestCase.test_directive_value_syntax_errorc Cdd}zt|dd}|dWdSty1}z|d|j|d|jWYd}~dSd}~ww)Nz/

Foo ${bar"}

r;r<rDrr rErrr=r?r@rrrtest_expression_syntax_errorfs z3MarkupTemplateTestCase.test_expression_syntax_errorc CrG)Nz$

${bar"}

r;r<rDrHr@rrr'test_expression_syntax_error_multi_lineqs z>MarkupTemplateTestCase.test_expression_syntax_error_multi_linecCs(td}|dt|jtdddS)zi Verify that outputting context data that is a `Markup` instance is not escaped. L
$myvar
z)
foo
z foomyvarN)r rrrrr)rrrtest_markup_noescape~sz+MarkupTemplateTestCase.test_markup_noescapecC$td}|dt|jdddS)zb Verify that outputting context data in text nodes doesn't escape quotes. rLz$
"foo"
"foo"rMNr(r)rrrtest_text_noescape_quotessz0MarkupTemplateTestCase.test_text_noescape_quotescCrP)zR Verify that outputting context data in attribtes escapes quotes. z\
z<
rQrMNr(r)rrrtest_attr_escape_quotessz.MarkupTemplateTestCase.test_attr_escape_quotescCr')Nze
bar
z"
bar
rQrMr(r)rrrtest_directive_elementsz-MarkupTemplateTestCase.test_directive_elementcCr1)NzV
z/
r(r)rrrtest_normal_comments z*MarkupTemplateTestCase.test_normal_commentcCr1)Nzi
z
r(r)rrrtest_template_comments z,MarkupTemplateTestCase.test_template_commentcCr1)Nz
z7
r(r)rrr%test_parse_with_same_namespace_nesteds z
ö
iso-8859-1encodinguM
ö
r encodersix text_typerr)rrr test_latin1_encoded_with_xmldecls  z7MarkupTemplateTestCase.test_latin1_encoded_with_xmldeclcCrX)NuH
ö
rYrZu!
ö
r\r)rrr%test_latin1_encoded_explicit_encodings  z Nr )rrrrtest_exec_with_trailing_spaces z4MarkupTemplateTestCase.test_exec_with_trailing_spacecCr1)Nz
${timedelta(days=2)}
z.
2 days, 0:00:00
r(r)rrrtest_exec_imports z'MarkupTemplateTestCase.test_exec_importcCr1)Nz
${foo()}
z!
42
r(r)rrr test_exec_defs z$MarkupTemplateTestCase.test_exec_defcCs td}|dt|dS)z Verify that a namespace declaration on an element that is removed from the generated stream does not get pushed up to the next non-stripped element (see ticket #107). z Size zI Nr(r)rrrtest_namespace_on_removed_elems z5MarkupTemplateTestCase.test_namespace_on_removed_elemc Ctjdd}zVttj|dd}z |dW|n|wttj|dd}z |dW|n|wt|g}| d}| d|j d d j dd Wt |dSt |w) N genshi_testsuffix tmpl1.htmlw
Included $idx
tmpl2.htmlz p
Included 0
Included 1
Included 2
tmpl1namerZtempfilemkdtempopenospathjoinwritecloser r#rrrendershutilrmtreerdirnamefile1file2loaderrrrrtest_include_in_loop     z+MarkupTemplateTestCase.test_include_in_loopc Crf) Nrgrhrjrk
Included
rmz D
Included
rorprZrrr~rrrtest_dynamic_include_hrefrz0MarkupTemplateTestCase.test_dynamic_include_hrefc Ctjdd}zTttj|dd}z |dW|n|wttj|dd}z |dW|n|wt|g}| d}| d| j dd Wt |dSt |w) Nrgrhrjrkz
  • $item
  • rmac
      ${select('li')}
    zX
    • 1
    • 2
    • 3
    rZrrr~rrrtest_select_included_elements9     z4MarkupTemplateTestCase.test_select_included_elementsc Cr) Nrgrhrjrkrrm Missing rrZrrr~rrr test_fallback_when_include_foundVs     z7MarkupTemplateTestCase.test_fallback_when_include_foundc Cstjdd}z8ttj|dd}z |dW|n|wt|gdd}| d}| t | j Wt|dSt|w)Nrgrhrmrkz{ T auto_reload)rsrtrurvrwrxryrzr r# assertRaisesr rr{r|r}rrrrrrrr!test_error_when_include_not_foundps   z8MarkupTemplateTestCase.test_error_when_include_not_foundc Ctjdd}z9ttj|dd}z |dW|n|wt|g}| d}| d| j ddWt |dSt |w)Nrgrhrmrkz Missing z8 Missing rZrrrrrr$test_fallback_when_include_not_founds    z;MarkupTemplateTestCase.test_fallback_when_include_not_foundc Cstjdd}z;ttj|dd}z |dW|n|wt|gdd}| d}| d| j dd Wt |dSt |w) NrgrhrmrkrTrz: Missing rZrrrrrr#test_fallback_when_auto_reload_trues   z:MarkupTemplateTestCase.test_fallback_when_auto_reload_truec Cr) Nrgrhrjrkr tmpl3.htmls Missing zH
    Included
    rZrrr~rrrtest_include_in_fallbacks     z/MarkupTemplateTestCase.test_include_in_fallbackc Cr)Nrgrhrrkrz< Missing rZrrrrrrtest_nested_include_fallbacks    z3MarkupTemplateTestCase.test_nested_include_fallbackc Cr) Nrgrhrmrkrra rrZrrr~rrrtest_nested_include_in_fallbackrz6MarkupTemplateTestCase.test_nested_include_in_fallbackc Cstjdd}z;ttj|dd}z |dW|n|wt|g}| d}| d|j ddj dd Wt |dSt |w) Nrgrhrmrka6 tmpl1.html not found zG tmpl1.html not found T)debugrZrrrrrr$test_include_fallback_with_directives    z;MarkupTemplateTestCase.test_include_fallback_with_directivec Cstjdd}z_ttj|dd}z |dW|n|wttj|dd}z |dW|n|wt|gdd }| d}| d t |j | d | jdd Wt|dSt|w) Nrgrhrjrkrrmz FrrrZ)rsrtrurvrwrxryrzr r#rlenrrr{r|r}r~rrrtest_include_inlineds"    z+MarkupTemplateTestCase.test_include_inlinedc Cstjdd}zVttj|dd}z |dW|n|wttj|dd}z |dW|n|wt|gdd }| d}| d | j dd Wt |dSt |w) Nrgrhrjrkrlrmz FrrnrZrrr~rrrtest_include_inlined_in_loop0s    z3MarkupTemplateTestCase.test_include_inlined_in_loopc Cstjdd}zBttj|dd}z |dW|n|wt|gdd}| tj|d}| d|j d d j dd Wt |dSt |w) Nrgrhrjrkz
    $depth
    Frz$
    0
    1
    2
    r)depthrZrr)rrrrrrrrtest_include_inline_recursiveJs  z4MarkupTemplateTestCase.test_include_inline_recursivec CsJd}zt|ddd}|dWdSty$}zWYd}~dSd}~ww)N This is replaced. r;Fr= allow_execzExpected SyntaxError)r rErr@rrrtest_allow_exec_falsedsz,MarkupTemplateTestCase.test_allow_exec_falsecCsd}t|ddd}dS)Nrr;Trr rrArrrrtest_allow_exec_truetsz+MarkupTemplateTestCase.test_allow_exec_truecCs.d}t|ddd}|d|jdddS)Nz ${title}

    moot text

    r;TrzW wakka wakka wakka rZr rrr{rrrrtest_exec_in_matchs z)MarkupTemplateTestCase.test_exec_in_matchcC,d}t|dd}|d|jdddS)Nz

    ${select('text()')}

    ${select('.')}

    ${foo}

    r;r<zi

    bar

    bar

    rZrrrrrtest_with_in_matchs  z)MarkupTemplateTestCase.test_with_in_matchc Cstjdd}zottj|dd}z |dW|n|wttj|dd}z |dW|n|wttj|dd}z |d W|n|wt|g}| d}| d | j dd Wt |dSt |w) Nrgrhrjrkzl
    Some content.
    rmz

    Some full html document that includes file1.html

    ra 
    Some added stuff. ${select('*|text()')}
    z

    Some full html document that includes file1.html

    Some added stuff. Some content.
    rZrr)rrrrfile3rrrrrtest_nested_include_matchess(        z2MarkupTemplateTestCase.test_nested_include_matchescCr)Nak ${select('*|text')} And some other stuff... Foo Bar r;r<z Foo And some other stuff... rZrrrrr%test_nested_matches_without_bufferings  z This replaces the other text. This gets replaced. r;r<zi This replaces the other text. rZrrrrrtest_match_without_selects  z0MarkupTemplateTestCase.test_match_without_selectcCr)Nal ${select('.')} fish fish fish fish r;r<z fish fish fish fish rZrrrrrtest_match_tail_handlings  z/MarkupTemplateTestCase.test_match_tail_handlingcCs:td}tdd}|tj||dt|dS)Nz
    cSs|S)Nr)srrrszSMarkupTemplateTestCase.test_directive_single_line_with_translator..zR
    0 1
    )r radd_directives NAMESPACErrr)rr translatorrrr*test_directive_single_line_with_translators   zAMarkupTemplateTestCase.test_directive_single_line_with_translatorN)6__name__ __module__ __qualname____doc__rrr&r*r/r0r2r5r7r:rCrFrIrKrOrRrSrTrUrVrWr`rarbrcrdrerrrrrrrrrrrrrrrrrrrrrrrrrrrr !sh             6 r cCs0t}|ttj|ttd|S)Ntest) unittest TestSuiteaddTestdoctest DocTestSuiter r makeSuiter )suiterrrr"sr__main__) defaultTest)rrvr r|sysrsrr^ genshi.compatrr genshi.corergenshi.filters.i18nr genshi.inputrgenshi.template.baserrgenshi.template.loaderr r genshi.template.markupr TestCaser rrmainrrrrs4