o
    ¯b  ã                   @   s¤   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
mZ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 G d	d
„ d
eƒZG dd„ deƒZdS )z$
Tests for L{twisted.names.common}.
é    )ÚverifyClass)Ú	IResolver)ÚResolverBase)ÚEFORMATÚENAMEÚENOTIMPÚEREFUSEDÚESERVERÚQuery)ÚDNSFormatErrorÚDNSNameErrorÚDNSNotImplementedErrorÚDNSQueryRefusedErrorÚDNSServerErrorÚDNSUnknownError)ÚFailure)ÚSynchronousTestCasec                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚExceptionForCodeTestsz5
    Tests for L{ResolverBase.exceptionForCode}.
    c                 C   s   t ƒ j| _d S ©N)r   ÚexceptionForCode©Úself© r   ú@/usr/lib/python3/dist-packages/twisted/names/test/test_common.pyÚsetUp   s   zExceptionForCodeTests.setUpc                 C   ó   |   |  t¡t¡ dS )zd
        L{ResolverBase.exceptionForCode} converts L{EFORMAT} to
        L{DNSFormatError}.
        N)ÚassertIsr   r   r   r   r   r   r   Útest_eformat"   ó   z"ExceptionForCodeTests.test_eformatc                 C   r   )zd
        L{ResolverBase.exceptionForCode} converts L{ESERVER} to
        L{DNSServerError}.
        N)r   r   r	   r   r   r   r   r   Útest_eserver)   r   z"ExceptionForCodeTests.test_eserverc                 C   r   )zX
        L{ResolverBase.exceptionForCode} converts L{ENAME} to L{DNSNameError}.
        N)r   r   r   r   r   r   r   r   Ú
test_ename0   s   z ExceptionForCodeTests.test_enamec                 C   r   )zl
        L{ResolverBase.exceptionForCode} converts L{ENOTIMP} to
        L{DNSNotImplementedError}.
        N)r   r   r   r   r   r   r   r   Útest_enotimp6   r   z"ExceptionForCodeTests.test_enotimpc                 C   r   )zk
        L{ResolverBase.exceptionForCode} converts L{EREFUSED} to
        L{DNSQueryRefusedError}.
        N)r   r   r   r   r   r   r   r   Útest_erefused=   r   z#ExceptionForCodeTests.test_erefusedc                 C   s   |   |  tƒ ¡t¡ dS )zr
        L{ResolverBase.exceptionForCode} converts any other response code to
        L{DNSUnknownError}.
        N)r   r   Úobjectr   r   r   r   r   Ú
test_otherD   s   z ExceptionForCodeTests.test_otherN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r!   r"   r$   r   r   r   r   r      s    r   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Ú
QueryTestsz*
    Tests for L{ResolverBase.query}.
    c                 C   s   t ttƒ dS )zF
        L{ResolverBase} provides the L{IResolver} interface.
        N)r   r   r   r   r   r   r   Ú"test_resolverBaseProvidesIResolverQ   s   z-QueryTests.test_resolverBaseProvidesIResolverc                    sF   g ‰ t ƒ }d‡ fdd„i|_tddd�}| |d¡ |  dgˆ ¡ dS )	zŸ
        L{ResolverBase.query} looks up a method to invoke using the type of the
        query passed to it and the C{typeToMethod} mapping on itself.
        é90  c                    s   ˆ   | |f¡S r   )Úappend©ÚqueryÚtimeout©Úresultsr   r   Ú<lambda>_   s    z6QueryTests.test_typeToMethodDispatch.<locals>.<lambda>ó   example.com©ÚnameÚtypeé{   )r3   r7   N)r   ÚtypeToMethodr
   r.   ÚassertEqual)r   Úresolverr.   r   r0   r   Útest_typeToMethodDispatchW   s   ÿz$QueryTests.test_typeToMethodDispatchc                    sZ   t ƒ ‰ tƒ }d‡ fdd„i|_tddd�}| |d¡}g }| |j¡ |  ˆ |d ¡ dS )	zÄ
        L{ResolverBase.query} returns a L{Deferred} which fires with the result
        of the method found in the C{typeToMethod} mapping for the type of the
        query passed to it.
        i1Ô  c                    s   ˆ S r   r   r-   ©Úexpectedr   r   r2   m   s    z4QueryTests.test_typeToMethodResult.<locals>.<lambda>r3   r4   r7   r   N)r#   r   r8   r
   r.   ÚaddBothr,   r9   ©r   r:   r.   ÚqueryDeferredÚresultr   r<   r   Útest_typeToMethodResulte   s   z"QueryTests.test_typeToMethodResultc                 C   sV   t ƒ }i |_tddd�}| |d¡}g }| |j¡ |  |d t¡ |d  t	¡ dS )zÇ
        L{ResolverBase.query} returns a L{Deferred} which fails with
        L{NotImplementedError} when called with a query of a type not present in
        its C{typeToMethod} dictionary.
        r3   r+   r4   r7   r   N)
r   r8   r
   r.   r>   r,   ÚassertIsInstancer   ÚtrapÚNotImplementedErrorr?   r   r   r   Útest_unknownQueryTypet   s   z QueryTests.test_unknownQueryTypeN)r%   r&   r'   r(   r*   r;   rB   rF   r   r   r   r   r)   L   s    r)   N)r(   Úzope.interface.verifyr   Útwisted.internet.interfacesr   Útwisted.names.commonr   Útwisted.names.dnsr   r   r   r   r	   r
   Útwisted.names.errorr   r   r   r   r   r   Útwisted.python.failurer   Útwisted.trial.unittestr   r   r)   r   r   r   r   Ú<module>   s     2