o ¯b:ã@szdZddlmZddlmZddlmZGdd„dƒZdd„Z Gd d „d ƒZ Gd d „d ƒZ Gd d„dƒZ Gdd„dƒZ dS)a¼ I{Private} test utilities for use throughout Twisted's test suite. Unlike C{proto_helpers}, this is no exception to the don't-use-it-outside-Twisted-we-won't-maintain-compatibility rule! @note: Maintainers be aware: things in this module should be gradually promoted to more full-featured test helpers and exposed as public API as your maintenance time permits. In order to be public API though, they need their own test cases. é)ÚBytesIO)Úminidom)Ú FileWrapperc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚIOPumpzŠUtility to pump data between clients and servers for protocol testing. Perhaps this is a utility worthy of being in protocol.py? cCs||_||_||_||_dS)N)ÚclientÚserverÚclientIOÚserverIO)Úselfrrrr ©r ú8/usr/lib/python3/dist-packages/twisted/test/testutils.pyÚ__init__s zIOPump.__init__cCs| ¡r | ¡sdSdS)z,Pump until there is no more input or output.N)Úpump)r r r r Úflush!sÿz IOPump.flushcCs”|j d¡|j d¡|j ¡}|j ¡}|j d¡|j d¡|j ¡|j ¡|D]}|j |¡q.|D]}|j |¡q9|sF|rHdSdS)zOMove data back and forth. Returns whether any data was moved. ré)rÚseekr ÚreadÚtruncaterÚ dataReceivedr)r ÚcDataÚsDataÚbyter r r r&s        z IOPump.pumpN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrr r r r rs  rcCsJtƒ}tƒ}| t|ƒ¡| t|ƒ¡t||||ƒ}| ¡| ¡|S)z-Take two Protocol instances and connect them.)rÚmakeConnectionrrr)rrÚcioÚsiorr r r ÚreturnConnected=src@óeZdZdZdd„ZdS)ÚXMLAssertionMixinzŠ Test mixin defining a method for comparing serialized XML documents. Must be mixed in to a L{test case}. cCs$| t |¡ ¡t |¡ ¡¡dS)zï Verify that two strings represent the same XML document. @param first: An XML string. @type first: L{bytes} @param second: An XML string that should match C{first}. @type second: L{bytes} N)Ú assertEqualÚdomÚ parseStringÚtoxml)r ÚfirstÚsecondr r r ÚassertXMLEqualRs ÿz XMLAssertionMixin.assertXMLEqualN)rrrrr(r r r r r!Ks r!c@ó"eZdZdZdedefdd„ZdS)Ú_EqualzN A class the instances of which are equal to anything and everything. ÚotherÚreturncCódS)NTr ©r r+r r r Ú__eq__fóz _Equal.__eq__N©rrrrÚobjectÚboolr/r r r r r*aór*c@r))Ú _NotEqualz> A class the instances of which are equal to nothing. r+r,cCr-)NFr r.r r r r/or0z_NotEqual.__eq__Nr1r r r r r5jr4r5c@r )ÚComparisonTestsMixina¾ A mixin which defines a method for making assertions about the correctness of an implementation of C{==} and C{!=}. Use this to unit test objects which follow the common convention for C{==} and C{!=}: - The object compares equal to itself - The object cooperates with unrecognized types to allow them to implement the comparison - The object implements not-equal as the opposite of equal cCs˜| ||k¡| ||k¡| ||k¡| ||k¡| ||k¡| ||k¡| |tƒk¡| |tƒk¡| |tƒk¡| |tƒk¡dS)aU Assert that C{firstValueOne} is equal to C{secondValueOne} but not equal to C{valueOne} and that it defines equality cooperatively with other types it doesn't know about. @param firstValueOne: An object which is expected to compare as equal to C{secondValueOne} and not equal to C{valueTwo}. @param secondValueOne: A different object than C{firstValueOne} but which is expected to compare equal to that object. @param valueTwo: An object which is expected to compare as not equal to C{firstValueOne}. N)Ú assertTrueÚ assertFalser*r5)r Ú firstValueOneÚsecondValueOneÚvalueTwor r r Ú"assertNormalEqualityImplementationsz7ComparisonTestsMixin.assertNormalEqualityImplementationN)rrrrr<r r r r r6ss r6N)rÚiorÚxml.domrr#Útwisted.internet.protocolrrrr!r*r5r6r r r r Ús  (