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