← Back
Editing: test_socket.cpython-38.pyc
U W[q$ � @ s d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl m Z ddlmZm Z ddlmZmZ dd lmZ dd lmZ G dd� de�ZG d d� de�ZG dd� de�ZG dd� de�Ze� �e�� � e� �e�� � e� �e�� � e� �e�� � dS )aD Tests for implementations of L{IReactorSocket}. Generally only tests for failure cases are found here. Success cases for this interface are tested elsewhere. For example, the success case for I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should behave exactly the same as L{IReactorTCP.listenTCP}. � N)�verify)�err)�IReactorSocket)�UnsupportedAddressFamily)�DatagramProtocol� ServerFactory)�ReactorBuilder�needsRunningReactor)�_PY3)�platformc @ s e Zd ZdZegZdd� ZdS )�&IReactorSocketVerificationTestsBuilderaO Builder for testing L{IReactorSocket} implementations for required methods and method signatures. L{ReactorBuilder} already runs L{IReactorSocket.providedBy} to ensure that these tests will only be run on reactor classes that claim to implement L{IReactorSocket}. These tests ensure that reactors which claim to provide the L{IReactorSocket} interface actually have all the required methods and that those methods have the expected number of arguments. These tests will be skipped for reactors which do not claim to provide L{IReactorSocket}. c C s | � � }| �t�t|�� dS )zf The reactor instance returned by C{buildReactor} provides L{IReactorSocket}. N)�buildReactorZ assertTruer ZverifyObjectr )�self�reactor� r �C/usr/lib/python3/dist-packages/twisted/internet/test/test_socket.py� test_provider/ s �z4IReactorSocketVerificationTestsBuilder.test_providerN)�__name__� __module__�__qualname__�__doc__r �requiredInterfacesr r r r r r s r c @ s. e Zd ZdZegZdd� Zdd� Zdd� ZdS ) �!AdoptStreamPortErrorsTestsBuilderas Builder for testing L{IReactorSocket.adoptStreamPort} implementations. Generally only tests for failure cases are found here. Success cases for this interface are tested elsewhere. For example, the success case for I{AF_INET} is in L{twisted.internet.test.test_tcp}, since that case should behave exactly the same as L{IReactorTCP.listenTCP}. c C st | � � }t�� }|�� }|�� | �tj|j|tjt� �}t � � r\tr\| �|j d tj� n| �|j d tj� dS )z� An implementation of L{IReactorSocket.adoptStreamPort} raises L{socket.error} if passed an integer which is not associated with a socket. r N)r �socket�fileno�close�assertRaises�error�adoptStreamPort�AF_INETr r � isWindowsr �assertEqual�args�errno�WSAENOTSOCK�EBADF�r r Zprober �excr r r �test_invalidDescriptorE s �z8AdoptStreamPortErrorsTestsBuilder.test_invalidDescriptorc C sR | � � }t�� }|�d� |�d� | �|j� d}| �t|j|� � |t � � dS )z� An implementation of L{IReactorSocket.adoptStreamPort} raises L{UnsupportedAddressFamily} if passed an address family it does not support. �z 127.0.0.1r � � N)r r �bind�listen� addCleanupr r r r r r �r r �port� arbitraryr r r �test_invalidAddressFamilyZ s �z;AdoptStreamPortErrorsTestsBuilder.test_invalidAddressFamilyc s� �� � �t�� ����j� ��d� ��d� ��d� ����� �j t � �}|�� � ��fdd�}� �|� � � td� t�� �fdd�� ��� d S ) a9 When the L{IListeningPort} returned by L{IReactorSocket.adoptStreamPort} is stopped using C{stopListening}, the underlying socket is closed but not shutdown. This allows another process which still has a reference to it to continue accepting connections over it. r) r* Fc sJ �� tj� j�}t�� r2tr2��|jd t j � n��|jd t j� d S )Nr )r r r Zacceptr r r r! r"