File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_factories.cpython-310.pyc
o
�b� � @ sV d Z ddlZddlmZmZ ddlmZ ddlmZ G dd� d�Z G dd � d e�Z
dS )
z&
Test code for basic Factory classes.
� N)�Protocol�ReconnectingClientFactory)�Clock)�TestCasec @ s e Zd ZdZdd� Zdd� ZdS )�
FakeConnectorzP
A fake connector class, to be used to mock connections failed or lost.
c C � d S �N� ��selfr r �=/usr/lib/python3/dist-packages/twisted/test/test_factories.py�stopConnecting � zFakeConnector.stopConnectingc C r r r r
r r r �connect r 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 sJ G dd� d�}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 � t d��)Nz%Shouldn't be called, we're connected.��RuntimeErrorr
r r r r
) � z`ReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.stopConnectingc S r )NzShouldn't be reconnecting.r r
r r r r , r zYReconnectingFactoryTests.test_stopTryingWhenConnected.<locals>.NoConnectConnector.connectN)r r r r
r r r r r �NoConnectConnector( s r N)r r �protocol�
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
A 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 H s
zcReconnectingFactoryTests.test_stopTryingDoesNotReconnect.<locals>.FactoryAwareFakeConnector.connectN)r r r r% r
r r r# r r �FactoryAwareFakeConnector>