<s> from irc3 . testing import BotTestCase <EOL> from irc3 . testing import MagicMock <EOL> from irc3 . testing import asyncio <EOL> import datetime <EOL> import tempfile <EOL> import shutil <EOL> import os <EOL> def hook ( entries ) : <EOL> return [ ] <EOL> class Hook : <EOL> def __init__ ( self , bot ) : <EOL> pass <EOL> def __call__ ( self , entries ) : <EOL> return [ ] <EOL> class Dispatcher : <EOL> def __init__ ( self , bot ) : <EOL> self . loop = bot . loop <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> self . future = asyncio . Future ( loop = self . loop ) <EOL> return self . future <EOL> def __call__ ( self , messages ) : <EOL> self . future . set_result ( list ( messages ) ) <EOL> class TestFeeds ( BotTestCase ) : <EOL> name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> wd = tempfile . mkdtemp ( ) <EOL> self . addCleanup ( shutil . rmtree , wd ) <EOL> self . wd = os . path . join ( wd , '<STR_LIT>' ) <EOL> dt = datetime . datetime . now ( ) . strftime ( '<STR_LIT>' ) <EOL> self . patch_requests ( <EOL> filename = '<STR_LIT>' , <EOL> DATE = dt , <EOL> ) <EOL> def callFTU ( self , ** kwargs ) : <EOL> loop = kwargs . pop ( '<STR_LIT>' , None ) <EOL> config = dict ( <EOL> directory = self . wd , <EOL> irc3 = '<STR_LIT>' , <EOL> dispatcher = '<STR_LIT>' , <EOL> channels = '<STR_LIT>' , ** kwargs <EOL> ) <EOL> config = { <EOL> '<STR_LIT>' : [ self . name ] , <EOL> self . name : config <EOL> } <EOL> if loop : <EOL> config . update ( loop = loop ) <EOL> return super ( TestFeeds , self ) . callFTU ( ** config ) <EOL> def test_connection_made ( self ) : <EOL> bot = self . callFTU ( ) <EOL> bot . loop . call_later = MagicMock ( ) <EOL> bot . notify ( '<STR_LIT>' ) <EOL> self . assertTrue ( bot . loop . call_later . called ) <EOL> def test_feed ( self ) : <EOL> bot = self . callFTU ( loop = asyncio . new_event_loop ( ) ) <EOL> future = bot . feeds . dispatcher . reset ( ) <EOL> bot . feeds . update ( ) <EOL> bot . loop . run_until_complete ( future ) <EOL> assert future . result ( ) == [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' ) ] <EOL> bot = self . callFTU ( loop = asyncio . new_event_loop ( ) ) <EOL> future = bot . feeds . dispatcher . reset ( ) <EOL> bot . feeds . update ( ) <EOL> bot . loop . run_until_complete ( future ) <EOL> assert future . result ( ) == [ ] <EOL> def test_hooked_feed ( self ) : <EOL> bot = self . callFTU ( hook = '<STR_LIT>' , <EOL> loop = asyncio . new_event_loop ( ) ) <EOL> future = bot . feeds . dispatcher . reset ( ) <EOL> bot . feeds . update ( ) <EOL> bot . loop . run_until_complete ( future ) <EOL> assert future . result ( ) == [ ] <EOL> def test_hooked_feed_with_class ( self ) : <EOL> bot = self . callFTU ( hook = '<STR_LIT>' , <EOL> loop = asyncio . new_event_loop ( ) ) <EOL> assert isinstance ( bot . feeds . hook , Hook ) <EOL> future = bot . feeds . dispatcher . reset ( ) <EOL> bot . feeds . update ( ) <EOL> bot . loop . run_until_complete ( future ) <EOL> assert future . result ( ) == [ ] </s>
