File: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_factories.cpython-38.pyc
U
W[ � @ sh d Z ddlmZmZ ddlZddlmZ ddlmZ ddl m
Z
mZ G dd� de�Z
G d d
� d
e�ZdS )z&
Test code for basic Factory classes.
� )�division�absolute_importN)�TestCase)�Clock)�ReconnectingClientFactory�Protocolc @ s e Zd ZdZdd� Zdd� ZdS )�
FakeConnectorzP
A fake connector class, to be used to mock connections failed or lost.
c C s d S �N� ��selfr
r
�=/usr/lib/python3/dist-packages/twisted/test/test_factories.py�stopConnecting s zFakeConnector.stopConnectingc C s d S r r
r r
r
r
�connect s zFakeConnector.connectN)�__name__�
__module__�__qualname__�__doc__r r r
r
r
r
r s r c @ s@ e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
d� Zdd
� Z dS )�ReconnectingFactoryTestsz1
Tests for L{ReconnectingClientFactory}.
c C sL G dd� dt �}t� }t|_|�d� |�� |�|� d� | �|j� dS )z�
If a L{ReconnectingClientFactory} has C{stopTrying} called while it is
connected, it does not subsequently attempt to reconnect if the
connection is later lost.
c @ s e Zd Zdd� Zdd� ZdS )zQReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnectorc S s t d��d S )Nz%Shouldn't be called, we're connected.��RuntimeErrorr r
r
r
r , s z`ReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.stopConnectingc S s t d��d S )NzShouldn't be reconnecting.r r r
r
r
r . s zYReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.connectN)r r r r r r
r
r
r
�NoConnectConnector+ s r N) �objectr r ZprotocolZ
buildProtocol�
stopTrying�clientConnectionLost�assertFalse�continueTrying)r r �cr
r
r
�test_stopTryingWhenConnected% s
z5ReconnectingFactoryTests.test_stopTryingWhenConnectedc sT G � fdd�dt �}t� � t� � _|� � _� �� | �� jj� | �� j�� � dS )z
Calling stopTrying on a L{ReconnectingClientFactory} doesn't attempt a
retry on any active connector.
c s$ e Zd ZdZ� fdd�Zdd� ZdS )z[ReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnectorFc s � � | d� dS )z�
Behave as though an ongoing connection attempt has now
failed, and notify the factory of this.
N)�clientConnectionFailedr ��fr
r
r C s zjReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.stopConnectingc S s
d| _ dS )z|
Record an attempt to reconnect, since this is what we
are trying to avoid.
TN)�attemptedRetryr r
r
r
r J s zcReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.connectN)r r r r"