Removed exit_unless_* methods, fixed the stuff that depended on them.
This commit is contained in:
@@ -25,13 +25,10 @@ import os
|
|||||||
import errno
|
import errno
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
def exit_unless_twisted():
|
|
||||||
|
def requires_twisted(func):
|
||||||
from eventlet.api import get_hub
|
from eventlet.api import get_hub
|
||||||
if 'Twisted' not in type(get_hub()).__name__:
|
if 'Twisted' not in type(get_hub()).__name__:
|
||||||
exit_disabled()
|
|
||||||
|
|
||||||
def requires_25(func):
|
|
||||||
if sys.version_info[:2]<(2, 5):
|
|
||||||
try:
|
try:
|
||||||
from nose.plugins.skip import SkipTest
|
from nose.plugins.skip import SkipTest
|
||||||
def skipme(*a, **k):
|
def skipme(*a, **k):
|
||||||
@@ -39,6 +36,7 @@ def requires_25(func):
|
|||||||
skipme.__name__ == func.__name__
|
skipme.__name__ == func.__name__
|
||||||
return skipme
|
return skipme
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
# no nose, we'll just skip the test ourselves
|
||||||
return lambda *a, **k: None
|
return lambda *a, **k: None
|
||||||
else:
|
else:
|
||||||
return func
|
return func
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import pysqlite2.dbapi2 as sqlite3
|
import pysqlite2.dbapi2 as sqlite3
|
||||||
import warnings
|
import warnings
|
||||||
from tests import disabled_marker
|
|
||||||
|
|
||||||
warnings.simplefilter('ignore')
|
warnings.simplefilter('ignore')
|
||||||
|
|
||||||
@@ -71,8 +70,6 @@ def main():
|
|||||||
if not debug:
|
if not debug:
|
||||||
if returncode==1:
|
if returncode==1:
|
||||||
pass
|
pass
|
||||||
elif returncode==8 and disabled_marker in stdout:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
record(changeset, argv, stdout, returncode)
|
record(changeset, argv, stdout, returncode)
|
||||||
os.unlink(output_name)
|
os.unlink(output_name)
|
||||||
|
|||||||
@@ -19,17 +19,19 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from tests import requires_twisted
|
||||||
from tests import exit_unless_twisted
|
|
||||||
exit_unless_twisted()
|
|
||||||
import unittest
|
import unittest
|
||||||
from twisted.internet.error import DNSLookupError
|
try:
|
||||||
from twisted.internet import defer
|
from twisted.internet import reactor
|
||||||
from twisted.python.failure import Failure
|
from twisted.internet.error import DNSLookupError
|
||||||
from eventlet.twistedutil import block_on
|
from twisted.internet import defer
|
||||||
|
from twisted.python.failure import Failure
|
||||||
|
from eventlet.twistedutil import block_on
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
class Test(unittest.TestCase):
|
class Test(unittest.TestCase):
|
||||||
|
@requires_twisted
|
||||||
def test_block_on_success(self):
|
def test_block_on_success(self):
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
d = reactor.resolver.getHostByName('www.google.com')
|
d = reactor.resolver.getHostByName('www.google.com')
|
||||||
@@ -38,16 +40,19 @@ class Test(unittest.TestCase):
|
|||||||
ip2 = block_on(d)
|
ip2 = block_on(d)
|
||||||
assert ip == ip2, (ip, ip2)
|
assert ip == ip2, (ip, ip2)
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_block_on_fail(self):
|
def test_block_on_fail(self):
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
d = reactor.resolver.getHostByName('xxx')
|
d = reactor.resolver.getHostByName('xxx')
|
||||||
self.assertRaises(DNSLookupError, block_on, d)
|
self.assertRaises(DNSLookupError, block_on, d)
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_block_on_already_succeed(self):
|
def test_block_on_already_succeed(self):
|
||||||
d = defer.succeed('hey corotwine')
|
d = defer.succeed('hey corotwine')
|
||||||
res = block_on(d)
|
res = block_on(d)
|
||||||
assert res == 'hey corotwine', `res`
|
assert res == 'hey corotwine', `res`
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_block_on_already_failed(self):
|
def test_block_on_already_failed(self):
|
||||||
d = defer.fail(Failure(ZeroDivisionError()))
|
d = defer.fail(Failure(ZeroDivisionError()))
|
||||||
self.assertRaises(ZeroDivisionError, block_on, d)
|
self.assertRaises(ZeroDivisionError, block_on, d)
|
||||||
|
|||||||
@@ -19,15 +19,25 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
from twisted.internet import reactor
|
from tests import requires_twisted
|
||||||
from tests import exit_unless_twisted
|
|
||||||
exit_unless_twisted()
|
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
from twisted.internet.error import ConnectionDone
|
try:
|
||||||
|
from twisted.internet import reactor
|
||||||
|
from twisted.internet.error import ConnectionDone
|
||||||
|
import eventlet.twistedutil.protocol as pr
|
||||||
|
from eventlet.twistedutil.protocols.basic import LineOnlyReceiverTransport
|
||||||
|
except ImportError:
|
||||||
|
# stub out some of the twisted dependencies so it at least imports
|
||||||
|
class dummy(object):
|
||||||
|
pass
|
||||||
|
pr = dummy()
|
||||||
|
pr.UnbufferedTransport = None
|
||||||
|
pr.GreenTransport = None
|
||||||
|
pr.GreenClientCreator = lambda *a, **k: None
|
||||||
|
class reactor(object):
|
||||||
|
pass
|
||||||
|
|
||||||
import eventlet.twistedutil.protocol as pr
|
|
||||||
from eventlet.twistedutil.protocols.basic import LineOnlyReceiverTransport
|
|
||||||
from eventlet.api import spawn, sleep, with_timeout, call_after
|
from eventlet.api import spawn, sleep, with_timeout, call_after
|
||||||
from eventlet.coros import event
|
from eventlet.coros import event
|
||||||
|
|
||||||
@@ -93,12 +103,14 @@ class TestUnbufferedTransport(TestCase):
|
|||||||
gtransportClass = pr.UnbufferedTransport
|
gtransportClass = pr.UnbufferedTransport
|
||||||
setup_server = setup_server_SpawnFactory
|
setup_server = setup_server_SpawnFactory
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_full_read(self):
|
def test_full_read(self):
|
||||||
self.conn.write('hello\r\n')
|
self.conn.write('hello\r\n')
|
||||||
self.assertEqual(self.conn.read(), 'you said hello. BYE')
|
self.assertEqual(self.conn.read(), 'you said hello. BYE')
|
||||||
self.assertEqual(self.conn.read(), '')
|
self.assertEqual(self.conn.read(), '')
|
||||||
self.assertEqual(self.conn.read(), '')
|
self.assertEqual(self.conn.read(), '')
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_iterator(self):
|
def test_iterator(self):
|
||||||
self.conn.write('iterator\r\n')
|
self.conn.write('iterator\r\n')
|
||||||
self.assertEqual('you said iterator. BYE', ''.join(self.conn))
|
self.assertEqual('you said iterator. BYE', ''.join(self.conn))
|
||||||
@@ -111,6 +123,7 @@ class TestGreenTransport(TestUnbufferedTransport):
|
|||||||
gtransportClass = pr.GreenTransport
|
gtransportClass = pr.GreenTransport
|
||||||
setup_server = setup_server_SpawnFactory
|
setup_server = setup_server_SpawnFactory
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_read(self):
|
def test_read(self):
|
||||||
self.conn.write('hello\r\n')
|
self.conn.write('hello\r\n')
|
||||||
self.assertEqual(self.conn.read(9), 'you said ')
|
self.assertEqual(self.conn.read(9), 'you said ')
|
||||||
@@ -120,30 +133,35 @@ class TestGreenTransport(TestUnbufferedTransport):
|
|||||||
self.assertEqual(self.conn.recv(9), '')
|
self.assertEqual(self.conn.recv(9), '')
|
||||||
self.assertEqual(self.conn.recv(1), '')
|
self.assertEqual(self.conn.recv(1), '')
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_read2(self):
|
def test_read2(self):
|
||||||
self.conn.write('world\r\n')
|
self.conn.write('world\r\n')
|
||||||
self.assertEqual(self.conn.read(), 'you said world. BYE')
|
self.assertEqual(self.conn.read(), 'you said world. BYE')
|
||||||
self.assertEqual(self.conn.read(), '')
|
self.assertEqual(self.conn.read(), '')
|
||||||
self.assertEqual(self.conn.recv(), '')
|
self.assertEqual(self.conn.recv(), '')
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_iterator(self):
|
def test_iterator(self):
|
||||||
self.conn.write('iterator\r\n')
|
self.conn.write('iterator\r\n')
|
||||||
self.assertEqual('you said iterator. BYE', ''.join(self.conn))
|
self.assertEqual('you said iterator. BYE', ''.join(self.conn))
|
||||||
|
|
||||||
_tests = [x for x in locals().keys() if x.startswith('test_')]
|
_tests = [x for x in locals().keys() if x.startswith('test_')]
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_resume_producing(self):
|
def test_resume_producing(self):
|
||||||
for test in self._tests:
|
for test in self._tests:
|
||||||
self.setUp()
|
self.setUp()
|
||||||
self.conn.resumeProducing()
|
self.conn.resumeProducing()
|
||||||
getattr(self, test)()
|
getattr(self, test)()
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_pause_producing(self):
|
def test_pause_producing(self):
|
||||||
self.conn.pauseProducing()
|
self.conn.pauseProducing()
|
||||||
self.conn.write('hi\r\n')
|
self.conn.write('hi\r\n')
|
||||||
result = with_timeout(DELAY*10, self.conn.read, timeout_value='timed out')
|
result = with_timeout(DELAY*10, self.conn.read, timeout_value='timed out')
|
||||||
self.assertEqual('timed out', result)
|
self.assertEqual('timed out', result)
|
||||||
|
|
||||||
|
@requires_twisted
|
||||||
def test_pauseresume_producing(self):
|
def test_pauseresume_producing(self):
|
||||||
self.conn.pauseProducing()
|
self.conn.pauseProducing()
|
||||||
call_after(DELAY*5, self.conn.resumeProducing)
|
call_after(DELAY*5, self.conn.resumeProducing)
|
||||||
@@ -206,7 +224,7 @@ if socket is not None:
|
|||||||
|
|
||||||
|
|
||||||
class TestTLSError(unittest.TestCase):
|
class TestTLSError(unittest.TestCase):
|
||||||
|
@requires_twisted
|
||||||
def test_server_connectionMade_never_called(self):
|
def test_server_connectionMade_never_called(self):
|
||||||
# trigger case when protocol instance is created,
|
# trigger case when protocol instance is created,
|
||||||
# but it's connectionMade is never called
|
# but it's connectionMade is never called
|
||||||
@@ -229,6 +247,9 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
del TestTLSError
|
del TestTLSError
|
||||||
|
|
||||||
if __name__=='__main__':
|
@requires_twisted
|
||||||
|
def main():
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
if __name__=='__main__':
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user