~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 06:35:14 UTC
  • Revision ID: coles.david@gmail.com-20100218063514-h4yfpd1is222aftp
A few more tests for chat. Testing the chat and start_server functions will likey require a little bit of refactoring.

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
19
21
 
20
 
from nose import with_setup
21
22
from nose.tools import assert_equal, raises
22
23
 
23
24
import ivle.chat
62
63
        assert_equal(ivle.chat.recv_netstring(self.s2), SIMPLESTRING)
63
64
 
64
65
    @raises(socket.timeout)
65
 
    def test_short_netstring(self):
 
66
    def test_invalid_short_netstring(self):
66
67
        self.s1.sendall("1234:not that long!,")
67
68
        assert ivle.chat.recv_netstring(self.s2) is None
68
69
 
69
70
    @raises(ivle.chat.ProtocolError)
 
71
    def test_invalid_long_netstring(self):
 
72
        self.s1.sendall("5:not that short!,")
 
73
        assert ivle.chat.recv_netstring(self.s2) is None
 
74
 
70
75
    def test_long_netstring(self):
71
 
        self.s1.sendall("5:not that short!,")
72
 
        assert ivle.chat.recv_netstring(self.s2) is None
 
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])
73
89