~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/tests/test_chat.py

  • Committer: David Coles
  • Date: 2010-02-18 05:39:31 UTC
  • Revision ID: coles.david@gmail.com-20100218053931-9m3hdk24tdaawf4p
Set local inside handle function to prevent it breaking testcases when development enviroment is not en_US

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
17
 
18
18
import socket
19
 
import os
20
 
import random
21
19
 
 
20
from nose import with_setup
22
21
from nose.tools import assert_equal, raises
23
22
 
24
23
import ivle.chat
63
62
        assert_equal(ivle.chat.recv_netstring(self.s2), SIMPLESTRING)
64
63
 
65
64
    @raises(socket.timeout)
66
 
    def test_invalid_short_netstring(self):
 
65
    def test_short_netstring(self):
67
66
        self.s1.sendall("1234:not that long!,")
68
67
        assert ivle.chat.recv_netstring(self.s2) is None
69
68
 
70
69
    @raises(ivle.chat.ProtocolError)
71
 
    def test_invalid_long_netstring(self):
 
70
    def test_long_netstring(self):
72
71
        self.s1.sendall("5:not that short!,")
73
72
        assert ivle.chat.recv_netstring(self.s2) is None
74
73
 
75
 
    def test_long_netstring(self):
76
 
        # XXX: send() may block if this is too big
77
 
        msg = os.urandom(50000)
78
 
        ivle.chat.send_netstring(self.s1, msg)
79
 
        assert ivle.chat.recv_netstring(self.s2) == msg
80
 
 
81
 
    def test_multiple_netstrings(self):
82
 
        messages = []
83
 
        for i in range(10):
84
 
            message = os.urandom(random.randint(0,20))
85
 
            messages.append(message)
86
 
            ivle.chat.send_netstring(self.s1, message)
87
 
        for i in range(10):
88
 
            assert_equal(ivle.chat.recv_netstring(self.s2), messages[i])
89