~ubuntu-branches/ubuntu/wily/pyzmq/wily

« back to all changes in this revision

Viewing changes to zmq/tests/test_reqrep.py

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-02-24 19:23:15 UTC
  • mfrom: (1.2.1) (9 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: package-import@ubuntu.com-20130224192315-qhmwp3m3ymk8r60d
Tags: 2.2.0.1-1
* New upstream release
* relicense debian packaging to LGPL-3
* update watch file to use github directly
  thanks to Bart Martens for the file
* add autopkgtests
* drop obsolete DM-Upload-Allowed
* bump standard to 3.9.4, no changes required

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
#    Copyright (c) 2010 Brian E. Granger
3
 
#
4
 
#    This file is part of pyzmq.
5
 
#
6
 
#    pyzmq is free software; you can redistribute it and/or modify it under
7
 
#    the terms of the Lesser GNU General Public License as published by
8
 
#    the Free Software Foundation; either version 3 of the License, or
9
 
#    (at your option) any later version.
10
 
#
11
 
#    pyzmq is distributed in the hope that it will be useful,
12
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
#    Lesser GNU General Public License for more details.
15
 
#
16
 
#    You should have received a copy of the Lesser GNU General Public License
17
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
#
 
1
#-----------------------------------------------------------------------------
 
2
#  Copyright (c) 2010-2012 Brian Granger, Min Ragan-Kelley
 
3
#
 
4
#  This file is part of pyzmq
 
5
#
 
6
#  Distributed under the terms of the New BSD License.  The full license is in
 
7
#  the file COPYING.BSD, distributed as part of this software.
 
8
#-----------------------------------------------------------------------------
19
9
 
20
10
#-----------------------------------------------------------------------------
21
11
# Imports
24
14
from unittest import TestCase
25
15
 
26
16
import zmq
27
 
from zmq.tests import BaseZMQTestCase
 
17
from zmq.tests import BaseZMQTestCase, have_gevent, GreenTest
28
18
 
29
19
#-----------------------------------------------------------------------------
30
20
# Tests
35
25
    def test_basic(self):
36
26
        s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
37
27
 
38
 
        msg1 = 'message 1'.encode()
 
28
        msg1 = b'message 1'
39
29
        msg2 = self.ping_pong(s1, s2, msg1)
40
30
        self.assertEquals(msg1, msg2)
41
31
 
43
33
        s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
44
34
 
45
35
        for i in range(10):
46
 
            msg1 = i*' '.encode()
 
36
            msg1 = i*b' '
47
37
            msg2 = self.ping_pong(s1, s2, msg1)
48
38
            self.assertEquals(msg1, msg2)
49
39
 
50
40
    def test_bad_send_recv(self):
51
41
        s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
52
 
        for copy in (True,False):
53
 
            self.assertRaisesErrno(zmq.EFSM, s1.recv, copy=copy)
54
 
            self.assertRaisesErrno(zmq.EFSM, s2.send, 'asdf'.encode(), copy=copy)
 
42
        
 
43
        if zmq.zmq_version() != '2.1.8':
 
44
            # this doesn't work on 2.1.8
 
45
            for copy in (True,False):
 
46
                self.assertRaisesErrno(zmq.EFSM, s1.recv, copy=copy)
 
47
                self.assertRaisesErrno(zmq.EFSM, s2.send, b'asdf', copy=copy)
55
48
 
56
49
        # I have to have this or we die on an Abort trap.
57
 
        msg1 = 'asdf'.encode()
 
50
        msg1 = b'asdf'
58
51
        msg2 = self.ping_pong(s1, s2, msg1)
59
52
        self.assertEquals(msg1, msg2)
60
53
 
70
63
 
71
64
    def test_large_msg(self):
72
65
        s1, s2 = self.create_bound_pair(zmq.REQ, zmq.REP)
73
 
        msg1 = 10000*'X'.encode()
 
66
        msg1 = 10000*b'X'
74
67
 
75
68
        for i in range(10):
76
69
            msg2 = self.ping_pong(s1, s2, msg1)
77
70
            self.assertEquals(msg1, msg2)
78
71
 
 
72
if have_gevent:
 
73
    class TestReqRepGreen(GreenTest, TestReqRep):
 
74
        pass