<s> from twisted . trial import unittest <EOL> from . . eventsource import EventSourceParser <EOL> class FakeTransport : <EOL> disconnecting = False <EOL> def parse_events ( s ) : <EOL> fields = [ ] <EOL> p = EventSourceParser ( lambda name , data : fields . append ( ( name , data ) ) ) <EOL> p . makeConnection ( FakeTransport ( ) ) <EOL> p . dataReceived ( s ) <EOL> return fields <EOL> class EventSource ( unittest . TestCase ) : <EOL> def test_parse ( self ) : <EOL> fields = [ ] <EOL> p = EventSourceParser ( lambda name , data : fields . append ( ( name , data ) ) ) <EOL> p . makeConnection ( FakeTransport ( ) ) <EOL> self . failUnlessEqual ( fields , [ ] ) <EOL> p . dataReceived ( "<STR_LIT>" ) <EOL> self . failUnlessEqual ( fields , [ ] ) <EOL> p . dataReceived ( "<STR_LIT:\n>" ) <EOL> self . failUnlessEqual ( fields , [ ] ) <EOL> p . dataReceived ( "<STR_LIT:\n>" ) <EOL> self . failUnlessEqual ( fields , [ ( "<STR_LIT>" , "<STR_LIT>" ) ] ) <EOL> p . dataReceived ( "<STR_LIT>" ) <EOL> self . failUnlessEqual ( fields , [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:data>" , "<STR_LIT>" ) ] ) <EOL> p . dataReceived ( "<STR_LIT>" ) <EOL> self . failUnlessEqual ( fields , [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:data>" , "<STR_LIT>" ) ] ) <EOL> p . dataReceived ( "<STR_LIT>" ) <EOL> self . failUnlessEqual ( fields , [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:data>" , "<STR_LIT>" ) ] ) <EOL> p . dataReceived ( "<STR_LIT:\n>" ) <EOL> self . failUnlessEqual ( fields , [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:data>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT:data>" , "<STR_LIT>" ) , <EOL> ] ) </s>
