当前位置: 首页>>代码示例>>Python>>正文


Python __builtin__.__name__方法代码示例

本文整理汇总了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'))] 
开发者ID:pantsbuild,项目名称:pex,代码行数:24,代码来源:test_util.py

示例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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:18,代码来源:test_class_jy.py

示例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 
开发者ID:ionelmc,项目名称:python-hunter,代码行数:7,代码来源:util.py

示例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__)) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:29,代码来源:test_class_jy.py

示例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__") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:12,代码来源:test_class_jy.py

示例6: setUp

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def setUp(self):
        global __name__
        self.name = __name__
        del __name__ 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:6,代码来源:test_class_jy.py

示例7: tearDown

# 需要导入模块: import __builtin__ [as 别名]
# 或者: from __builtin__ import __name__ [as 别名]
def tearDown(self):
        global __name__
        __name__ = self.name 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:5,代码来源:test_class_jy.py

示例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") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:8,代码来源:test_class_jy.py

示例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)) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:11,代码来源:test_class_jy.py

示例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) 
开发者ID:ionelmc,项目名称:python-hunter,代码行数:50,代码来源:util.py


注:本文中的__builtin__.__name__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。