本文整理汇总了Python中__builtin__.__name__方法的典型用法代码示例。如果您正苦于以下问题:Python __builtin__.__name__方法的具体用法?Python __builtin__.__name__怎么用?Python __builtin__.__name__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类__builtin__
的用法示例。
在下文中一共展示了__builtin__.__name__方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_access_zipped_assets
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def test_access_zipped_assets(
mock_resource_string,
mock_resource_isdir,
mock_resource_listdir,
mock_safe_mkdir,
mock_safe_mkdtemp):
mock_open = mock.mock_open()
mock_safe_mkdtemp.side_effect = iter(['tmpJIMMEH', 'faketmpDir'])
mock_resource_listdir.side_effect = iter([['./__init__.py', './directory/'], ['file.py']])
mock_resource_isdir.side_effect = iter([False, True, False])
mock_resource_string.return_value = 'testing'
with mock.patch('%s.open' % python_builtins.__name__, mock_open, create=True):
temp_dir = DistributionHelper.access_zipped_assets('twitter.common', 'dirutil')
assert mock_resource_listdir.call_count == 2
assert mock_open.call_count == 2
file_handle = mock_open.return_value.__enter__.return_value
assert file_handle.write.call_count == 2
assert mock_safe_mkdtemp.mock_calls == [mock.call()]
assert temp_dir == 'tmpJIMMEH'
assert mock_safe_mkdir.mock_calls == [mock.call(os.path.join('tmpJIMMEH', 'directory'))]
示例2: test_builtin_attributes
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def test_builtin_attributes(self):
for attr, val in dict(__name__='foo', __module__='bar', __dict__={},
__flags__=1, __base__=object,
__bases__=(unicode, object),
__mro__=(unicode, object)).iteritems():
try:
setattr(str, attr, val)
except TypeError, te:
self.assertEqual(str(te), self.TE_MSG)
else:
self.assert_(False,
'setattr str.%s expected a TypeError' % attr)
try:
delattr(str, attr)
except TypeError, te:
self.assertEqual(str(te), self.TE_MSG)
示例3: __get__
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def __get__(self, obj, cls):
if obj is None:
return self
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value
示例4: test_dunder_module
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def test_dunder_module(self):
self.assertEqual(str.__module__, '__builtin__')
class Foo:
pass
Fu = types.ClassType('Fu', (), {})
for cls in Foo, Fu:
self.assert_('__module__' in cls.__dict__)
self.assertEqual(cls.__module__, __name__)
self.assertEqual(str(cls), '%s.%s' % (__name__, cls.__name__))
self.assert_(repr(cls).startswith('<class %s.%s at' %
(__name__, cls.__name__)))
obj = cls()
self.assert_(str(obj).startswith('<%s.%s instance at' %
(__name__, cls.__name__)))
class Bar(object):
pass
class Baz(Object):
pass
Bang = type('Bang', (), {})
for cls in Bar, Baz, Bang:
self.assert_('__module__' in cls.__dict__)
self.assertEqual(cls.__module__, __name__)
self.assertEqual(str(cls), "<class '%s.%s'>" % (__name__, cls.__name__))
self.assertEqual(repr(cls), "<class '%s.%s'>" % (__name__, cls.__name__))
self.assert_(str(Bar()).startswith('<%s.Bar object at' % __name__))
self.assert_(str(Baz()).startswith("org.python.proxies.%s$Baz" % __name__))
示例5: test_attributes
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def test_attributes(self):
class Foo(object):
pass
Foo.__name__ = 'Bar'
self.assertEqual(Foo.__name__, 'Bar')
try:
del Foo.__name__
except TypeError, te:
self.assertEqual(str(te), "can't delete Bar.__name__")
示例6: setUp
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def setUp(self):
global __name__
self.name = __name__
del __name__
示例7: tearDown
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def tearDown(self):
global __name__
__name__ = self.name
示例8: test_java_class_name
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def test_java_class_name(self):
# The __name__ and __module__ attributes of Java classes should
# be set according to the same convention that Python uses.
from java.lang import String
self.assertEqual(String.__name__, "String")
self.assertEqual(String.__module__, "java.lang")
示例9: test_repr_with_metaclass
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def test_repr_with_metaclass(self):
# http://bugs.jython.org/issue1131
class FooMetaclass(type):
def __new__(cls, name, bases, attrs):
return super(FooMetaclass, cls).__new__(cls, name, bases, attrs)
class Foo(object):
__metaclass__ = FooMetaclass
self.assertEqual("<class '%s.Foo'>" % __name__, repr(Foo))
示例10: safe_repr
# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def safe_repr(obj, maxdepth=5):
if not maxdepth:
return '...'
obj_type = type(obj)
obj_type_type = type(obj_type)
newdepth = maxdepth - 1
# only represent exact builtins
# (subclasses can have side-effects due to __class__ as a property, __instancecheck__, __subclasscheck__ etc)
if obj_type is dict:
return '{%s}' % ', '.join('%s: %s' % (
safe_repr(k, maxdepth),
safe_repr(v, newdepth)
) for k, v in obj.items())
elif obj_type is list:
return '[%s]' % ', '.join(safe_repr(i, newdepth) for i in obj)
elif obj_type is tuple:
return '(%s%s)' % (', '.join(safe_repr(i, newdepth) for i in obj), ',' if len(obj) == 1 else '')
elif obj_type is set:
return '{%s}' % ', '.join(safe_repr(i, newdepth) for i in obj)
elif obj_type is frozenset:
return '%s({%s})' % (obj_type.__name__, ', '.join(safe_repr(i, newdepth) for i in obj))
elif obj_type is deque:
return '%s([%s])' % (obj_type.__name__, ', '.join(safe_repr(i, newdepth) for i in obj))
elif obj_type in (Counter, OrderedDict, defaultdict):
return '%s({%s})' % (
obj_type.__name__,
', '.join('%s: %s' % (
safe_repr(k, maxdepth),
safe_repr(v, newdepth)
) for k, v in obj.items())
)
elif obj_type is types.MethodType: # noqa
self = obj.__self__
name = getattr(obj, '__qualname__', None)
if name is None:
name = obj.__name__
return '<%sbound method %s of %s>' % ('un' if self is None else '', name, safe_repr(self, newdepth))
elif obj_type_type is type and BaseException in obj_type.__mro__:
return '%s(%s)' % (obj_type.__name__, ', '.join(safe_repr(i, newdepth) for i in obj.args))
elif obj_type_type is type and obj_type is not InstanceType and obj_type.__module__ in (builtins.__name__, 'io', 'socket', '_socket'):
# hardcoded list of safe things. note that isinstance ain't used
# (we don't trust subclasses to do the right thing in __repr__)
return repr(obj)
else:
# if the object has a __dict__ then it's probably an instance of a pure python class, assume bad things
# with side-effects will be going on in __repr__ - use the default instead (object.__repr__)
return object.__repr__(obj)