From 7f7ccd3a1865e8e73f3d1813182d01c607d6e501 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 9 Apr 2015 00:57:37 +0200 Subject: [PATCH] 100% test coverage --- netlib/tcp.py | 2 +- test/test_tcp.py | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/netlib/tcp.py b/netlib/tcp.py index 45c60fd8c..20e7d45ff 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -302,7 +302,7 @@ class _Connection(object): self.connection.shutdown() except SSL.Error: pass - except KeyError as e: + except KeyError as e: # pragma: no cover # Workaround for https://github.com/pyca/pyopenssl/pull/183 if OpenSSL.__version__ != "0.14": raise e diff --git a/test/test_tcp.py b/test/test_tcp.py index b93b1e0aa..4dbdd7807 100644 --- a/test/test_tcp.py +++ b/test/test_tcp.py @@ -1,6 +1,7 @@ import cStringIO, Queue, time, socket, random import os from netlib import tcp, certutils, test, certffi +import threading import mock import tutils from OpenSSL import SSL @@ -39,6 +40,15 @@ class TestServer(test.ServerTestBase): c.wfile.flush() assert c.rfile.readline() == testval + def test_thread_start_error(self): + with mock.patch.object(threading.Thread, "start", side_effect=threading.ThreadError("nonewthread")) as m: + c = tcp.TCPClient(("127.0.0.1", self.port)) + c.connect() + assert not c.rfile.read(1) + assert m.called + assert "nonewthread" in self.q.get_nowait() + self.test_echo() + class TestServerBind(test.ServerTestBase): class handler(tcp.BaseHandler): @@ -72,7 +82,7 @@ class TestServerIPv6(test.ServerTestBase): assert c.rfile.readline() == testval -class TestDisconnect(test.ServerTestBase): +class TestEcho(test.ServerTestBase): handler = EchoHandler def test_echo(self): testval = "echo!\n" @@ -553,17 +563,6 @@ class TestAddress: assert repr(a) -class TestServer(test.ServerTestBase): - handler = EchoHandler - def test_echo(self): - testval = "echo!\n" - c = tcp.TCPClient(("127.0.0.1", self.port)) - c.connect() - c.wfile.write(testval) - c.wfile.flush() - assert c.rfile.readline() == testval - - class TestSSLKeyLogger(test.ServerTestBase): handler = EchoHandler ssl = dict(