;ò 2°öBc@sedZdkZdkZdkZdklZddd„Zddd„Zd„Zfd„Z dS( sd Helper functions for unit tests. $Id: helpers.py,v 1.1.1.1 2004/06/19 14:53:55 dreamcatcher Exp $ N(sdedentsexpected outputs actual outputcCs5diti|iƒ|iƒ||ddƒƒSdS(sÈDisplay a compact unified diff between old text and new text. Bugs: does not work when old or new is an empty string (this seems to be a bug/limitation of the Python 2.3 difflib module). s slinetermsN(sjoinsdifflibs unified_diffsolds splitlinessnewsoldlabelsnewlabel(soldsnewsoldlabelsnewlabel((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysunidiff3sc s:|iƒ}|iƒ}d|d|g‰‡d†}tid|d|ƒ}xÖ|i ƒD]È\} }}} }| djo*|d|||ƒ|d|| |ƒq]| d jo|d|||ƒq]| d jo|d|| |ƒq]| d jo|d |||ƒq]td | ƒ‚q]WdiˆƒSdS(s5Display a unified diff between old text and new text.s--- %ss+++ %scs3x,t||ƒD]}ˆi|||ƒqWdS(N(sxrangesloshisisdiffsappendstagsx(stagsxsloshisi(sdiff(s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysdumpDssasbsreplaces-s+sdeletesinsertsequals sunknown tag %rs N(solds splitlinessnewsoldlabelsnewlabelsdiffsdumpsdifflibsSequenceMatchersdiffers get_opcodesstagsalosahisblosbhisAssertionErrorsjoin( soldsnewsoldlabelsnewlabelsbhisalosdiffersdumpsahisblostagsdiff((sdiffs[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysdiff=s&        cCst|ƒ}|iƒ|SdS(N(slistslssort(sl((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pyssortedXs  c sdfd„ƒY‰dfd„ƒY‰dfd„ƒY‰df‡‡‡d†ƒY}x(|D] }|id |d |ƒ}q\Wyl|ƒ}t i |d d d ƒ} | i |t |ƒtƒ}|od ||fSnd i|iƒƒSWn t ij o}d|SnXdS(s‘Normalizes an XML document. The idea is that two semantically equivalent XML documents should be normalized into the same canonical representation. Therefore if two documents compare equal after normalization, they are semantically equivalent. The canonical representation used here has nothing to do with W3C Canonical XML. This function normalizes indentation, whitespace and newlines (except inside text nodes), element attribute order, expands character references, expands shorthand notation of empty XML elements ("
becomes "

"). If an element has an attribute test:sort="children", the attribute is removed and its immediate child nodes are sorted textually. If the attribute value is test:sort="recursively", the sorting happens at all levels (unless specifically prohibited with test:sort="not"). If recursively_sort is given, it is a sequence of tags that will have test:sort="recursively" automatically appended to their attribute lists in the text. Use it when you cannot or do not want to modify the XML document itself. Caveats: - normalize_xml does not deal well with text nodes - normalize_xml does not help when different prefixes are used for the same namespace - normalize_xml does not handle all XML features (CDATA sections, inline DTDs, processing instructions, comments) sDocumentcBstZd„Zdd„ZRS(NcCsg|_t|_dS(N(sselfschildrensFalsessort_recursively(sself((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys__init__‚s icCsAg}x'|iD]}|i|i|ƒƒqWdi|ƒSdS(Ns(sresultsselfschildrenschildsappendsrenderslevelsjoin(sselfslevelschildsresult((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysrender†s  (s__name__s __module__s__init__srender(((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysDocument€s sElementcBs)tZeed„Zd„Zd„ZRS(NcCs:||_||_||_g|_||_||_dS(N(sparentsselfstagsattrlistschildrenssortssort_recursively(sselfsparentstagsattrlistssortssort_recursively((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys__init__Žs      c CsOg}d|}d||if}xp|iD]e}t||ƒdjo||7}q-|i |ƒ|i dƒd|dt|iƒ|f}q-W|i oDdi gi }|i D]}||i|dƒƒq·~ƒ}nd}|o<|i d |ƒ|i |ƒ|i d ||ifƒn|i d |ƒdi |ƒSdS( Ns s%s<%siNs s%s %s%ss sis%s> s%s s%s/> (sresultslevelsindentsselfstagslinesattrlistsattrslensappendschildrensjoins_[1]schildsrenderss( sselfslevelsindentsattrs_[1]sssresultschildsline((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysrender—s&    $ D cCs7|io|iid„ƒn|idƒ|_dS(NcCst|i|iƒS(N(scmpsxskeysy(sxsy((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys°si(sselfssortschildrensrenderskey(sself((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysfinalize®s (s__name__s __module__sFalses__init__srendersfinalize(((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysElementŒs sTextcBstZd„Zd„ZRS(NcCs||_t|_dS(N(sdatasselfsNoneskey(sselfsdata((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys__init__µs cCsyti|iiƒƒ}|oRd|}digi}|i ƒD] }|d||iƒfƒqC~ƒSndSdS(Ns ss%s%s ( scgisescapesselfsdatasstripslevelsindentsjoinsappends_[1]s splitlinessline(sselfslevelsindents_[1]slinesdata((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysrender¹s  H(s__name__s __module__s__init__srender(((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysText³s sHandlercs>tZ‡d†Z‡d†Zd„Z‡d†Zd„ZRS(Ncs2d|_g|_ˆƒ|_|_t|_dS(Ni(sselfslevelsresultsDocumentsrootscursNones last_text(sself(sDocument(s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys__init__Äs  c s3|ii}}|oÌd|job|d}|d=|djo t}q†|djot}}q†|djot}}q†n|iƒ}|iƒgi }|D],\} } |d| ti| tƒfƒqª~}ng}ˆ|i||d|d|ƒ}|iii |ƒ||_t|_dS(Ns test:sortschildrens recursivelysnots %s="%s"ssortssort_recursively(sselfscurssort_recursivelyssortsattrssvaluesTruesFalsesitemssattrlistsappends_[1]sksvscgisescapesElementstagschildschildrensNones last_text( sselfstagsattrsssortsattrlistssort_recursivelyschildsvalues_[1]svsk(sElement(s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys startElementÊs(        G  cCs)|iiƒ|ii|_t|_dS(N(sselfscursfinalizesparentsNones last_text(sselfstag((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys endElementâs csO|itj o|ii|7_n&ˆ|ƒ|_|iii|iƒdS(N(sselfs last_textsNonesdatasTextscurschildrensappend(sselfsdata(sText(s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys charactersçscCs|iiƒSdS(N(sselfsrootsrender(sself((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysrenderîs(s__name__s __module__s__init__s startElements endElements characterssrender((sTextsElementsDocument(s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pysHandlerÂs     s<%ss<%s test:sort="recursively"sisPARSE ERROR: %r %ss ERROR: %sN(sDocumentsElementsTextsHandlersrecursively_sortstagsxmlsreplaceshandlerslibxml2screatePushParsersctxs parseChunkslensTruesretsjoinsrenders parserErrorse( sxmlsrecursively_sortseshandlersTextstagsretsElementsHandlersctxsDocument((sTextsElementsDocuments[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys normalize_xml^s$  '/  ( s__doc__sdifflibscgislibxml2sProducts.Calendaring.commonsdedentsunidiffsdiffssorteds normalize_xml(scgisdedentsunidiffslibxml2sdifflibs normalize_xmlssortedsdiff((s[/mnt/gmirror/ports/www/zope-calendaring/work/Calendaring-0.3.0/Calendaring/tests/helpers.pys?*s