<s> from __future__ import unicode_literals <EOL> import unittest <EOL> import sys <EOL> def to_unicode ( data ) : <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> return str ( data ) <EOL> return unicode ( data ) <EOL> from sse import Sse <EOL> class ServerSentEventsProtocolTests ( unittest . TestCase ) : <EOL> def test_constructor ( self ) : <EOL> self . assertEqual ( list ( Sse ( ) ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( Sse ( default_retry = <NUM_LIT:1000> ) ) , [ '<STR_LIT>' ] ) <EOL> def test_add_message__simple_text ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_message ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> sse . add_message ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> self . assertEqual ( to_unicode ( sse ) , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( list ( sse ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' <EOL> ] ) <EOL> def test_add_message__simple_text_split ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_message ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> sse . add_message ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> self . assertEqual ( list ( sse ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' <EOL> ] ) <EOL> def test_add_message__list ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_message ( "<STR_LIT:foo>" , [ "<STR_LIT>" ] ) <EOL> sse . add_message ( "<STR_LIT:bar>" , [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( list ( sse ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' <EOL> ] ) <EOL> def test_add_message__list_split ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_message ( "<STR_LIT:foo>" , [ "<STR_LIT>" ] ) <EOL> sse . add_message ( "<STR_LIT:bar>" , [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( list ( sse ) , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:\n>' <EOL> ] ) <EOL> def test_dinamic_methods ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_event_foo ( text = "<STR_LIT:bar>" ) <EOL> self . assertEqual ( list ( sse ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:\n>' ] ) <EOL> def test_flush ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_message ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> sse . flush ( ) <EOL> self . assertEqual ( len ( sse . _buffer ) , <NUM_LIT:0> ) <EOL> def test_flush_on_iter ( self ) : <EOL> sse = Sse ( ) <EOL> sse . add_message ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> self . assertEqual ( list ( sse ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:\n>' ] ) <EOL> self . assertEqual ( list ( sse ) , [ ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
