當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。