o
    b                     @   s   d Z ddlmZmZ ddlmZmZmZmZ	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ G d	d
 d
eZG dd deZdS )z1
Tests for L{twisted.protocols.haproxy._parser}.
    )TypeUnion)TCP4ServerEndpointTCP6ServerEndpointUNIXServerEndpoint_parse_WrapperServerEndpointserverFromString)MemoryReactor)SynchronousTestCase   )unparseEndpoint)HAProxyWrappingFactoryc                   @   s^   e Zd ZdZdeddfddZdddZdd	d
ZdddZdddZ	dddZ
dddZdS )UnparseEndpointTestszg
    Tests to ensure that un-parsing an endpoint string round trips through
    escaping properly.
    inputreturnNc                 C   s   |  tt| | dS )aA  
        Check that the input unparses into the output, raising an assertion
        error if it doesn't.

        @param input: an input in endpoint-string-description format.  (To
            ensure determinism, keyword arguments should be in alphabetical
            order.)
        @type input: native L{str}
        N)assertEqualr   parseEndpoint)selfr    r   L/usr/lib/python3/dist-packages/twisted/protocols/haproxy/test/test_parser.pycheck   s   
zUnparseEndpointTests.checkc                 C      |  d dS )z%
        An individual word.
        wordNr   r   r   r   r   test_basicUnparse)      z&UnparseEndpointTests.test_basicUnparsec                 C   r   )z%
        Multiple arguments.
        zone:twoNr   r   r   r   r   test_multipleArguments/   r   z+UnparseEndpointTests.test_multipleArgumentsc                 C   r   )z$
        Keyword arguments.
        zaleph=one:bet=twoNr   r   r   r   r   test_keywords5   r   z"UnparseEndpointTests.test_keywordsc                 C   r   )z
        Escaped ":".
        zhello\:colon\:worldNr   r   r   r   r   test_colonInArgument;   r   z)UnparseEndpointTests.test_colonInArgumentc                 C   r   )z/
        Escaped ":" in keyword value.
        zhello=\:Nr   r   r   r   r   test_colonInKeywordValueA   r   z-UnparseEndpointTests.test_colonInKeywordValuec                 C   r   )z.
        Escaped ":" in keyword name.
        z\:=helloNr   r   r   r   r   test_colonInKeywordNameG   r   z,UnparseEndpointTests.test_colonInKeywordNamer   N)__name__
__module____qualname____doc__strr   r   r   r   r    r!   r"   r   r   r   r   r      s    




r   c                   @   sZ   e Zd ZdZdedeee ee ee	 f de
fddZddd	Zdd
dZdddZdS )HAProxyServerParserTestsz@
    Tests that the parser generates the correct endpoints.
    descriptionexpectedClassr   c                 C   sJ   t  }t||}| |t t|tsJ | |j| | |jt |S )a%  
        Test the C{haproxy} enpdoint prefix against one sub-endpoint type.

        @param description: A string endpoint description beginning with
            C{haproxy}.
        @type description: native L{str}

        @param expectedClass: the expected sub-endpoint class given the
            description.
        @type expectedClass: L{type}

        @return: the parsed endpoint
        @rtype: L{IStreamServerEndpoint}

        @raise twisted.trial.unittest.Failtest: if the parsed endpoint doesn't
            match expectations.
        )	r
   r	   assertIsInstancer   
isinstance_wrappedEndpointassertIs_wrapperFactoryr   )r   r*   r+   reactorendpointr   r   r   	onePrefixS   s   
z"HAProxyServerParserTests.onePrefixNc                 C      |  dt dS )zG
        Test if the parser generates a wrapped TCP4 endpoint.
        zhaproxy:tcp:8080N)r3   r   r   r   r   r   	test_tcp4u      z"HAProxyServerParserTests.test_tcp4c                 C   r4   )zG
        Test if the parser generates a wrapped TCP6 endpoint.
        zhaproxy:tcp6:8080N)r3   r   r   r   r   r   	test_tcp6{   r6   z"HAProxyServerParserTests.test_tcp6c                 C   r4   )zG
        Test if the parser generates a wrapped UNIX endpoint.
        z haproxy:unix:address=/tmp/socketN)r3   r   r   r   r   r   	test_unix   r6   z"HAProxyServerParserTests.test_unixr#   )r$   r%   r&   r'   r(   r   r   r   r   r   r   r3   r5   r7   r8   r   r   r   r   r)   N   s"    

"
r)   N)r'   typingr   r   twisted.internet.endpointsr   r   r   r   r   r   r	   twisted.test.proto_helpersr
   twisted.trial.unittestr   TestCase_parserr   _wrapperr   r   r)   r   r   r   r   <module>   s    7