o !bk@sddlZddlmZmZddlmZddlmZmZm Z m Z m Z m Z ddl mZGdddeZGdd d ejZd d Zed krIejd d dSdS)N)AttrsQName)XML)Path PathParserPathSyntaxErrorGenericStrategySingleStepStrategySimplePathStrategy) doctest_suitec@seZdZddZdddZdS)FakePathcCs ||_dSN)strategy)selfrr3/usr/lib/python3/dist-packages/genshi/tests/path.py__init__s zFakePath.__init__FcCs |j|Sr )rtest)rignore_contextrrrrs z FakePath.testN)F)__name__ __module__ __qualname__rrrrrrr sr c@s(eZdZeeegZddZddZddZ ddZ d d Z d d Z d dZ ddZddZddZddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Z d5d6Z!d7d8Z"d9d:Z#d;d<Z$d=d>Z%d?d@Z&dAdBZ'dCdDZ(dEdFZ)dGdHZ*dIdJZ+dKdLZ,dMdNZ-dOdPZ.dQdRZ/dSdTZ0dUdVZ1dWdXZ2dYdZZ3d[d\Z4d]d^Z5d_d`Z6dadbZ7dcddZ8dedfZ9dgdhZ:didjZ;dkdlZdqdrZ?dsdtZ@dudvZAdwdxZBdydzZCd{d|ZDd}d~ZE dddZF dddZGdS) PathTestCasecCs|ttddS)Nz/root assertRaisesrrrrrrtest_error_no_absolute_path"sz(PathTestCase.test_error_no_absolute_pathcCs |ttd|ttddS)Nz..z parent::marrrrrtest_error_unsupported_axis%sz(PathTestCase.test_error_unsupported_axiscCsftd}|jdd|dd|jdd|dd|jdd|dd|jdd|dd|jd d |dddS) Nelemzpathequivinputoutputz child::elemz//elemz!zdescendant::elemzr _test_evalrxmlrrr test_1step)s> zPathTestCase.test_1stepcCs0td}|jdd|dd|jdd|dddS)Nr.zr!z self::node()r&r(rrrtest_1step_selfJ zPathTestCase.test_1step_selfcCsTtd}|jdd|dd|jdd|dd|jdd|dd|jd d |dddS) Nr*zr r!zchild::*z child::node()z//*zr&r(rrrtest_1step_wildcardY2 z PathTestCase.test_1step_wildcardcCsF|jddtdddtd}|jdd|dd|jdd |dddS) Nz@foozzr!zbarz./@fooz$r'rr(rrrtest_1step_attributets& z!PathTestCase.test_1step_attributecCsTtd}|jdd|dd|jdd|dd|jdd |dd|jd d |dddS) NzHeytext()Heyr!./text()#//text()#z .//text()z>r&r(rrrtest_1step_textr1zPathTestCase.test_1step_textcCs<td}|jd|dd|jd|dd|jd|dddS) Nr.z r$r%r3bazr2r&r(rrr test_2stepszPathTestCase.test_2stepcCsttd}|jd|dd|jd|dd|jd|dd|jd|d dtd }|jd|d d|jd |d ddS)Nz4Hey Joez@*xr?z./@*z.//@*xjoez*/@*joez'r2zfoo/@*12r&r(rrrtest_2step_attributesz!PathTestCase.test_2step_attributecCstd}|jdd|dd|jdd|dd|jd d |ddtd }|jdd|d dtd }|jd|ddtd}|jd|dddS)Nzfoo/barzr@r!z./barz r2foo/*2z zp
1One
2Two
ztr/td[1]z12)r"r$r%z
  • item1
    • subitem11
  • item2
    • subitem21
zli[2]/ulz
  • subitem21
r&r(rrrtest_2step_complexsL zPathTestCase.test_2step_complexcCstd}|jdd|dd|jdd|dd|jdd |dd|jd d |d dtd }|jdd|ddtd}|jdd|dddS)NzFooz item/text()z"Foor!z*/text()zr;r<r9r:r2z-FooBarFooBarzEFooBarzitem/name/text()z.r&r(rrrtest_2step_textsN zPathTestCase.test_2step_textcCtd}|jdd|dddS)NrHrIrJr@r!r&r(rrr test_3step zPathTestCase.test_3stepcCs0|jddtddd|jddtdd ddS) Nz*/barzrHr@r!z//barz rKzr4rrrrtest_3step_complexs zPathTestCase.test_3step_complexcCs0td}|jdd|dd|jdd|dddS) NzMSome text in here.zitem/bar/text()z-z Some text r!zitem//bar/text()zHSome text in here.r&r(rrrtest_3step_complex_text'r-z$PathTestCase.test_3step_complex_textcCrP)Nzz comment()zzr!r&r(rrrtest_node_type_comment6rRz#PathTestCase.test_node_type_commentcCrP)N$Some text
in here.
r6r7rTr!r&r(rrrtest_node_type_text?rRz PathTestCase.test_node_type_textcCrP)NrWznode()r/zSome text
in here.r!r&r(rrrtest_node_type_nodeHrRz PathTestCase.test_node_type_nodecCsBtd}|jdd|dd|jdd|dd|jd d |dddS) Nz4z//processing-instruction()z5z'r!zprocessing-instruction()z(zzprocessing-instruction("php")z-r&r(rrr%test_node_type_processing_instructionQs& z2PathTestCase.test_node_type_processing_instructioncCrP)Nz"1
2
3
z*|text()zz1
2
3
r!r&r(rrrtest_simple_unionfrRzPathTestCase.test_simple_unioncCtd}|jd|dddS)Nr>z*[name()="foo"]r?r&r(rrrtest_predicate_nameoz PathTestCase.test_predicate_namecCr\)N$z*[local-name()="foo"]r?r&r(rrrtest_predicate_localnames z%PathTestCase.test_predicate_localnamecCr\)Nr`z*[namespace-uri()="NS"]rar?r&r(rrrtest_predicate_namespacexrcz%PathTestCase.test_predicate_namespacecCr\)Nr>z*[not(name()="foo")]r@r?r&r(rrrtest_predicate_not_name}rcz$PathTestCase.test_predicate_not_namecC,td}|jd|dd|jd|dddS)N,zitem[@important]r?item[@important="very"]r&r(rrrtest_predicate_attr z PathTestCase.test_predicate_attrcC,td}|jd|dd|jd|dddS)Nz-rir2r?zitem[@important!="very"]z r&r(rrrtest_predicate_attr_equality  z)PathTestCase.test_predicate_attr_equalitycCrl)N!zitem[@priority>3]r2r?zitem[@priority>2]r&r(rrr test_predicate_attr_greater_thanrnz-PathTestCase.test_predicate_attr_greater_thancCrl)Nrozitem[@priority<3]r2r?zitem[@priority<4]rpr&r(rrrtest_predicate_attr_less_thanrnz*PathTestCase.test_predicate_attr_less_thancCrl)Nrgz&item[@important and @important="very"]rhr?z'item[@important and @important="notso"]r2r&r(rrrtest_predicate_attr_ands z$PathTestCase.test_predicate_attr_andcCrl)Nrgzitem[@urgent or @important]rhr?zitem[@urgent or @notso]r2r&r(rrrtest_predicate_attr_ors z#PathTestCase.test_predicate_attr_orcCsltd}|jd|dd|jd|dd|jd|dd|jd|dd|jd |dd|jd |dddS) Nbarz*[boolean("")]r2r?z*[boolean("yo")]barz *[boolean(0)]z*[boolean(42)]z*[boolean(false())]z*[boolean(true())]r&r(rrrtest_predicate_boolean_functions z,PathTestCase.test_predicate_boolean_functioncCr\)Nruz*[ceiling("4.5")=5]rvr?r&r(rrrtest_predicate_ceil_functionrcz)PathTestCase.test_predicate_ceil_functioncCr\)Nruz*[name()=concat("f", "oo")]rvr?r&r(rrrtest_predicate_concat_functionrcz+PathTestCase.test_predicate_concat_functioncCr\)Nruz*[contains(name(), "oo")]rvr?r&r(rrr test_predicate_contains_functionrcz-PathTestCase.test_predicate_contains_functioncCr\)Nz)barfooz*[matches(name(), "foo|bar")]zbarfoor?r&r(rrrtest_predicate_matches_functionrcz,PathTestCase.test_predicate_matches_functioncCr\)Nruz *[false()]r2r?r&r(rrrtest_predicate_false_functionr_z*PathTestCase.test_predicate_false_functioncCr\)Nruz*[floor("4.5")=4]rvr?r&r(rrrtest_predicate_floor_functionrcz*PathTestCase.test_predicate_floor_functioncCr\)Nruz,*[normalize-space(" foo bar ")="foo bar"]rvr?r&r(rrr'test_predicate_normalize_space_function z4PathTestCase.test_predicate_normalize_space_functioncCs<td}|jd|dd|jd|dd|jd|dddS)Nruz*[number("3.0")=3]rvr?z*[number("3.0")=3.0]z*[number("0.1")=.1]r&r(rrrtest_predicate_number_functions z+PathTestCase.test_predicate_number_functioncCrf)Nruz*[round("4.4")=4]rvr?z*[round("4.6")=5]r&r(rrrtest_predicate_round_functionrkz*PathTestCase.test_predicate_round_functioncCrl)Nruz*[starts-with(name(), "f")]rvr?z*[starts-with(name(), "b")]r2r&r(rrr#test_predicate_starts_with_functionrkz0PathTestCase.test_predicate_starts_with_functioncCr\)Nruz*[string-length(name())=3]rvr?r&r(rrr%test_predicate_string_length_functionrcz2PathTestCase.test_predicate_string_length_functioncCrf)Nruz*[substring(name(), 1)="oo"]rvr?z*[substring(name(), 1, 1)="o"]r&r(rrr!test_predicate_substring_functionrkz.PathTestCase.test_predicate_substring_functioncCr\)Nruz$*[substring-after(name(), "f")="oo"]rvr?r&r(rrr'test_predicate_substring_after_functionrcz4PathTestCase.test_predicate_substring_after_functioncCr\)Nruz%*[substring-before(name(), "oo")="f"]rvr?r&r(rrr(test_predicate_substring_before_functionrz5PathTestCase.test_predicate_substring_before_functioncCr\)Nruz&*[translate(name(), "fo", "ba")="baa"]rvr?r&r(rrr!test_predicate_translate_functionrz.PathTestCase.test_predicate_translate_functioncCr\)Nruz *[true()]rvr?r&r(rrrtest_predicate_true_functionr_z)PathTestCase.test_predicate_true_functioncC"td}|jd|dddiddS)Nruz*[name()=$bar]rvr3foo)r"r$r% variablesr&r(rrrtest_predicate_variable s z$PathTestCase.test_predicate_variablecCr\)Nz7z*[2]r?r&r(rrrtest_predicate_positionr_z$PathTestCase.test_predicate_positioncCr\)N/z *[@id][2]rr?r&r(rrr test_predicate_attr_and_positionr_z-PathTestCase.test_predicate_attr_and_positioncCrl)Nrz *[1][@id]r2r?z *[2][@id]zr&r(rrr test_predicate_position_and_attrsz-PathTestCase.test_predicate_position_and_attrcCr\)Nz-z]descendant-or-self::*/descendant-or-self::*/descendant-or-self::*[2]/self::*/descendant::*[3]z r?r&r(rrr test_predicate_advanced_position"s  z-PathTestCase.test_predicate_advanced_positioncCrl)NzC12345z//a/b[2]z25r?z//a/b[3]z3r&r(rrrtest_predicate_child_position*sz*PathTestCase.test_predicate_child_positioncC$td}|jdd|dddiddS)N-barzf:foozbarfFOOr"r#r$r% namespacesr&r(rrrtest_name_with_namespace0 z%PathTestCase.test_name_with_namespacecCr)Nrzf:*zrrrrr&r(rrrtest_wildcard_with_namespace:rz)PathTestCase.test_wildcard_with_namespacecCs4td}|jd|ddtd}|jd|dddS)z Verify that a patch matching the self axis with a predicate doesn't cause an infinite loop. See . z&
  • a
  • b
z.[@flag="1"]/*z
  • a
  • b
  • r?z.[@flag="0"]/*r2Nr&r(rrrtest_predicate_terminationDs z'PathTestCase.test_predicate_terminationcCr)N-z foo[@f:bar]$rrr$r%rr&r(rrrtest_attrname_with_namespaceP  z)PathTestCase.test_attrname_with_namespacecCr)Nrz foo[@f:*]rrrrr&r(rrr test_attrwildcard_with_namespaceVrz-PathTestCase.test_attrwildcard_with_namespacecCsltd}|jd|dd|jd|dd|jd|dd|jd|dd|jd |dd|jd |dddS) Nzz self::rootr?z self::foor2zdescendant::rootzdescendant::foor]zdescendant-or-self::rootzdescendant-or-self::foor&r(rrrtest_self_and_descendant\sz%PathTestCase.test_self_and_descendantcCstd}|jd|dd|jd|dd|jd|dd|jd|dd|jd|dd|jd |dd|jd |d d|jd |dd|jd |d ddS)Nzb!z //a/b/a/b/a/cz!r?z //a/b/a/cz//a/cz//cza/b/descendant::a/cz#a/b/descendant::a/d/descendant::a/cza/b/descendant::a/d/a/cr2z;//d/descendant::b/descendant::b/descendant::b/descendant::czI//d/descendant::b/descendant::b/descendant::b/descendant::b/descendant::cr&r(rrrtest_long_simple_pathsfs" z#PathTestCase.test_long_simple_pathscCs>td}td}||}|t|ttddfggdS)Nz"zfoo/@barr3abcrrselect assertEquallistrrrr)r"resultrrrtest_attr_selectionzs    z PathTestCase.test_attr_selectioncCsFtd}td}|j|ddid}|t|ttddfggdS)NzEz foo/@ns1:barns1zhttp://example.com)rzhttp://example.com}barrrrrrr"test_attr_selection_with_namespaces  z/PathTestCase.test_attr_selection_with_namespacecCst|ddd}||S)Nr)rparsesupports)rstrategy_classtextr"rrr _test_supports zPathTestCase._test_supportcCs||td||td||td||td||td||td||td||td ||td  ||td  ||td  ||td  dS) Nza/bz self::a/bzdescendant::a/bzdescendant-or-self::a/bz//a/bza/@bza/text()za//bz node()/@az@azfoo:barz a/@foo:bar) assertTruerr rrrrtest_simple_strategy_supports z)PathTestCase.test_simple_strategy_supportNc Csr|jD]3}||s q||}t|j|||djdd}dt|} | d|7} | d|7} |||| qdS)NrrencodingzBad render using %s strategy Expected: %r Rendered: %r) strategiesrr rrenderstrr) rr$r"r%rrrsrenderedmsgrrr_test_strategiess      zPathTestCase._test_strategiesr2c Cst|}|dur||t||durdS|j|||djdd}d}|d|7}|d|7}||||t|jdkrM|j||jd|||ddSdS)NrrzBad output using whole pathrrr)rrreprrrlenpathsr) rr"r#r$r%rrrrrrrr's&   zPathTestCase._test_eval)NN)NNr2NN)Hrrrrr r rrrr*r,r0r5r=rBrGrLrOrQrSrUrVrXrYrZr[r^rbrdrerjrmrqrrrsrtrwrxryrzr{r|r}r~rrrrrrrrrrrrrrrrrrrrrrrrrrrr'rrrrrs ! 2)              rcCs.t}|ttj|ttd|S)Nr)unittest TestSuiteaddTestr rr makeSuiter)suiterrrrsr__main__) defaultTest)r genshi.corerr genshi.inputr genshi.pathrrrrr r genshi.tests.test_utilsr r TestCaserrrmainrrrrs     ,