add py.builtin.callable

--HG--
branch : trunk
This commit is contained in:
Benjamin Peterson 2009-08-29 15:46:50 -05:00
parent 1781347999
commit e63abd631f
3 changed files with 14 additions and 0 deletions

View File

@ -151,6 +151,7 @@ initpkg(__name__,
'builtin._totext' : ('./builtin/builtin31.py', '_totext'),
'builtin.builtins' : ('./builtin/builtin31.py', 'builtins'),
'builtin.execfile' : ('./builtin/builtin31.py', 'execfile'),
'builtin.callable' : ('./builtin/builtin31.py', 'callable'),
# gateways into remote contexts
'execnet.__doc__' : ('./execnet/__init__.py', '__doc__'),

View File

@ -26,10 +26,14 @@ if sys.version_info >= (3, 0):
fp.close()
exec_(source, globs, locs)
def callable(obj):
return hasattr(obj, "__call__")
else:
_totext = unicode
_basestring = basestring
execfile = execfile
callable = callable
import __builtin__ as builtins
def print_(*args, **kwargs):

View File

@ -96,6 +96,15 @@ def test_execfile(tmpdir):
py.builtin.execfile(str(test_file))
assert A.x == 3
def test_callable():
class A: pass
assert py.builtin.callable(test_callable)
assert py.builtin.callable(A)
assert py.builtin.callable(list)
assert py.builtin.callable(id)
assert not py.builtin.callable(4)
assert not py.builtin.callable("hi")
def test_totext():
py.builtin._totext("hello", "UTF-8")