Fix string concatenation errors

Some error paths concatenate the output of "type" with a string,
which gives TypeError: cannot concatenate 'str' and 'type' objects,
rather than describing the actual error.

Closes #149 GH
Closes #150 GH

Conflicts:
	eventlet/hubs/twistedr.py
This commit is contained in:
Steven Hardy
2014-10-16 18:40:19 +01:00
committed by Jakub Stasiak
parent 197000511e
commit 34bcb6d150
2 changed files with 34 additions and 2 deletions

View File

@@ -17,12 +17,12 @@ def get_fileno(obj):
f = obj.fileno
except AttributeError:
if not isinstance(obj, six.integer_types):
raise TypeError("Expected int or long, got " + type(obj))
raise TypeError("Expected int or long, got %s" % type(obj))
return obj
else:
rv = f()
if not isinstance(rv, six.integer_types):
raise TypeError("Expected int or long, got " + type(rv))
raise TypeError("Expected int or long, got %s" % type(rv))
return rv

View File

@@ -613,6 +613,38 @@ class TestGreenSocket(LimitedTestCase):
assert select.select([], [s1], [], 0) == ([], [s1], [])
def test_get_fileno_of_a_socket_works():
class DummySocket(object):
def fileno(self):
return 123
assert select.get_fileno(DummySocket()) == 123
def test_get_fileno_of_an_int_works():
assert select.get_fileno(123) == 123
def test_get_fileno_of_wrong_type_fails():
try:
select.get_fileno('foo')
except TypeError as ex:
assert str(ex) == 'Expected int or long, got <type \'str\'>'
else:
assert False, 'Expected TypeError not raised'
def test_get_fileno_of_a_socket_with_fileno_returning_wrong_type_fails():
class DummySocket(object):
def fileno(self):
return 'foo'
try:
select.get_fileno(DummySocket())
except TypeError as ex:
assert str(ex) == 'Expected int or long, got <type \'str\'>'
else:
assert False, 'Expected TypeError not raised'
class TestGreenPipe(LimitedTestCase):
@skip_on_windows
def setUp(self):