Skip to content

Commit

Permalink
Add unit test for SSLTransport _write function (#251)
Browse files Browse the repository at this point in the history
Reference:
#249
  • Loading branch information
aojea authored and auvipy committed Jan 27, 2019
1 parent e45ea3e commit 40e0ef5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions t/unit/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,27 @@ def test_read_EOF(self):
match=r'.*Server unexpectedly closed connection.*'):
self.t._read(64)

def test_write_success(self):
self.t.sock = Mock(name='SSLSocket')
self.t.sock.write.return_value = 2
self.t._write('foo')
self.t.sock.write.assert_called()

def test_write_socket_closed(self):
self.t.sock = Mock(name='SSLSocket')
self.t.sock.write.return_value = ''
with pytest.raises(IOError,
match=r'.*Socket closed.*'):
self.t._write('foo')

def test_write_ValueError(self):
self.t.sock = Mock(name='SSLSocket')
self.t.sock.write.return_value = 2
self.t.sock.write.side_effect = ValueError("Some error")
with pytest.raises(IOError,
match=r'.*Socket closed.*'):
self.t._write('foo')


class test_TCPTransport:

Expand Down

0 comments on commit 40e0ef5

Please sign in to comment.