Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python event emitter

#Method 1

def test_twisted_emit():
    """Test that event_emitters can handle wrapping coroutines when using
    twisted and ensureDeferred.
    """
    ee = EventEmitter(scheduler=ensureDeferred)

    should_call = Mock()

    @ee.on('event')
    async def event_handler():
        should_call(True)

    ee.emit('event')

    should_call.assert_called_once()
    
    
    #Method 2
    
    def test_twisted_error():
    """Test that event_emitters can handle wrapping coroutines when using
    twisted and ensureDeferred.
    """
    ee = EventEmitter(scheduler=ensureDeferred)

    should_call = Mock()

    @ee.on('event')
    async def event_handler():
        raise PyeeTestException()

    @ee.on('error')
    def handle_error(e):
        should_call(e)

    ee.emit('event')

    should_call.assert_called_once()
    
    #Source file: test_async.py
    
Comment

PREVIOUS NEXT
Code Example
Python :: Python batch file rename 
Python :: how to add start menu in python 
Python :: how to show type of a variable 
Python :: How to query one to many on same page 
Python :: Redirect to the same page and display a message if user insert wrong data 
Python :: Pull data from one couchdb doc via ids in another (Python) 
Python :: python tuple index access 
Python :: Express + Jade : Ensuring url paths are correct via controllers, orphaned links 
Python :: DD python ue5 set material interface 
Python :: Invenco Order Dict 
Python :: xchacha20 
Python :: ring For in Loop 
Python :: ring write the key and the IV directly using strings 
Python :: ring check if a Ring function is defined or not 
Python :: loop over dict python looking for match in list 
Python :: convert all date columns using pd.datetime 
Python :: cannot set `other` if drop=True 
Python :: how to download feature engine in spyder console 
Python :: downloading datasets from ml.org repository 
Python :: IPython default setup 
Python :: ConversionofDatatypes-I 
Python :: how to multiply integer value with float values in python 
Python :: "json" is not defined 
Python :: populate initial data for django simple history 
Python :: disable json dumps encode 
Python :: first rows of data frame (specify n by param) 
Python :: python socket set title 
Python :: run selenium webdriver without opening browser 
Python :: mongoclient python 
Python :: google popup not opening 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =