File manager - Edit - /usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/reactormixins.cpython-310.pyc
Back
o �b9 � @ s d Z g d�ZddlZddlZddlZddlmZmZmZm Z m Z ddlmZ ddl mZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZmZ ddlmZmZ zdd lmZ W n e!yg dZY nw e ZG dd� de"�Z#dd� Z$ddd�Z%G dd� d�Z&dS )a� Utilities for unit testing reactor implementations. The main feature of this module is L{ReactorBuilder}, a base class for use when writing interface/blackbox tests for reactor implementations. Test case classes for reactor features should subclass L{ReactorBuilder} instead of L{SynchronousTestCase}. All of the features of L{SynchronousTestCase} will be available. Additionally, the tests will automatically be applied to all available reactor implementations. )�TestTimeoutError�ReactorBuilder�needsRunningReactor� N)�Dict�Optional�Sequence�Type�Union)� Interface��log)�_fullyQualifiedName)�Failure)�namedAny)�platform)�SkipTest�SynchronousTestCase)�DEFAULT_TIMEOUT_DURATION�acquireAttribute)�processc @ s e Zd ZdZdS )r zm The reactor was still running after the timeout period elapsed in L{ReactorBuilder.runReactor}. N)�__name__� __module__�__qualname__�__doc__� r r �E/usr/lib/python3/dist-packages/twisted/internet/test/reactormixins.pyr * s r c C s | � |� dS )a* Various functions within these tests need an already-running reactor at some point. They need to stop the reactor when the test has completed, and that means calling reactor.stop(). However, reactor.stop() raises an exception if the reactor isn't already running, so if the L{Deferred} that a particular API under test returns fires synchronously (as especially an endpoint's C{connect()} method may do, if the connect is to a local interface address) then the test won't be able to stop the reactor being tested and finish. So this calls C{thunk} only once C{reactor} is running. (This is just an alias for L{twisted.internet.interfaces.IReactorCore.callWhenRunning} on the given reactor parameter, in order to centrally reference the above paragraph and repeating it everywhere as a comment.) @param reactor: the L{twisted.internet.interfaces.IReactorCore} under test @param thunk: a 0-argument callable, which eventually finishes the test in question, probably in a L{Deferred} callback. N)�callWhenRunning)�reactor�thunkr r r r 1 s r c sD |du r ddl m} dg�� �fdd�}|�|� | �|j|� dS )a� Stop the reactor as soon as any error is logged on the given publisher. This is beneficial for tests which will wait for a L{Deferred} to fire before completing (by passing or failing). Certain implementation bugs may prevent the L{Deferred} from firing with any result at all (consider a protocol's {dataReceived} method that raises an exception: this exception is logged but it won't ever cause a L{Deferred} to fire). In that case the test would have to complete by timing out which is a much less desirable outcome than completing as soon as the unexpected error is encountered. @param case: A L{SynchronousTestCase} to use to clean up the necessary log observer when the test is over. @param reactor: The reactor to stop. @param publisher: A L{LogPublisher} to watch for errors. If L{None}, the global log publisher will be watched. Nr r c s* �r| � d�r��� � �� d S d S d S )N�isError)�get�pop�stop)�event�r �runningr r �stopIfError_ s �z stopOnError.<locals>.stopIfError)�twisted.pythonr �addObserver� addCleanup�removeObserver)�caser � publisherr&