<s> import time <EOL> import unittest <EOL> import zmqpy <EOL> from zmqpy . utils . strtypes import asbytes <EOL> from . __init__ import BaseZMQTestCase <EOL> class TestPubSub ( BaseZMQTestCase ) : <EOL> def test_basic ( self ) : <EOL> s1 , s2 = self . create_bound_pair ( zmqpy . PUSH , zmqpy . PULL ) <EOL> msg1 = asbytes ( '<STR_LIT:message>' ) <EOL> s1 . send ( msg1 ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> msg2 = s2 . recv ( ) <EOL> self . assertEquals ( msg1 , msg2 ) <EOL> def test_topic ( self ) : <EOL> s1 , s2 = self . create_bound_pair ( zmqpy . PUB , zmqpy . SUB ) <EOL> s2 . setsockopt ( zmqpy . SUBSCRIBE , asbytes ( '<STR_LIT:x>' ) ) <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> msg1 = asbytes ( '<STR_LIT:message>' ) <EOL> s1 . send ( msg1 ) <EOL> self . assertRaisesErrno ( zmqpy . EAGAIN , s2 . recv , zmqpy . NOBLOCK ) <EOL> msg1 = asbytes ( '<STR_LIT>' ) <EOL> s1 . send ( msg1 ) <EOL> msg2 = s2 . recv ( ) <EOL> self . assertEquals ( msg1 , msg2 ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
