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


Python UserList.UserList方法代码示例

本文整理汇总了Python中UserList.UserList方法的典型用法代码示例。如果您正苦于以下问题:Python UserList.UserList方法的具体用法?Python UserList.UserList怎么用?Python UserList.UserList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserList的用法示例。


在下文中一共展示了UserList.UserList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cmp

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_cmp(self):
        self.assertEqual(cmp(-1, 1), -1)
        self.assertEqual(cmp(1, -1), 1)
        self.assertEqual(cmp(1, 1), 0)
        # verify that circular objects are not handled
        a = []; a.append(a)
        b = []; b.append(b)
        from UserList import UserList
        c = UserList(); c.append(c)
        self.assertRaises(RuntimeError, cmp, a, b)
        self.assertRaises(RuntimeError, cmp, b, c)
        self.assertRaises(RuntimeError, cmp, c, a)
        self.assertRaises(RuntimeError, cmp, a, c)
       # okay, now break the cycles
        a.pop(); b.pop(); c.pop()
        self.assertRaises(TypeError, cmp) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:18,代码来源:test_builtins.py

示例2: __reduce_ex__

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def __reduce_ex__(self, *args, **kwargs):
        # The `list` reduce function returns an iterator as the fourth element
        # that is normally used for repopulating. Since we only inherit from
        # `list` for `isinstance` backward compatibility (Refs #17413) we
        # nullify this iterator as it would otherwise result in duplicate
        # entries. (Refs #23594)
        info = super(UserList, self).__reduce_ex__(*args, **kwargs)
        return info[:3] + (None, None)


# Utilities for time zone support in DateTimeField et al. 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:utils.py

示例3: test_writelines_userlist

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_writelines_userlist(self):
        l = UserList([b'ab', b'cd', b'ef'])
        writer = self.MockRawIO()
        bufio = self.tp(writer, 8)
        bufio.writelines(l)
        bufio.flush()
        self.assertEqual(b''.join(writer._write_stack), b'abcdef') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_io.py

示例4: test_precomputed

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_precomputed(self):
        for func, data, elem, expected in self.precomputedCases:
            self.assertEqual(func(data, elem), expected)
            self.assertEqual(func(UserList(data), elem), expected) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_bisect.py

示例5: test_vsBuiltinSort

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_vsBuiltinSort(self, n=500):
        from random import choice
        for insorted in (list(), UserList()):
            for i in xrange(n):
                digit = choice("0123456789")
                if digit in "02468":
                    f = self.module.insort_left
                else:
                    f = self.module.insort_right
                f(insorted, digit)
            self.assertEqual(sorted(insorted), insorted) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_bisect.py

示例6: test_recursion

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_recursion(self):
        # Check that comparison for recursive objects fails gracefully
        from UserList import UserList
        a = UserList()
        b = UserList()
        a.append(b)
        b.append(a)
        self.assertRaises(RuntimeError, operator.eq, a, b)
        self.assertRaises(RuntimeError, operator.ne, a, b)
        self.assertRaises(RuntimeError, operator.lt, a, b)
        self.assertRaises(RuntimeError, operator.le, a, b)
        self.assertRaises(RuntimeError, operator.gt, a, b)
        self.assertRaises(RuntimeError, operator.ge, a, b)

        b.append(17)
        # Even recursive lists of different lengths are different,
        # but they cannot be ordered
        self.assertTrue(not (a == b))
        self.assertTrue(a != b)
        self.assertRaises(RuntimeError, operator.lt, a, b)
        self.assertRaises(RuntimeError, operator.le, a, b)
        self.assertRaises(RuntimeError, operator.gt, a, b)
        self.assertRaises(RuntimeError, operator.ge, a, b)
        a.append(17)
        self.assertRaises(RuntimeError, operator.eq, a, b)
        self.assertRaises(RuntimeError, operator.ne, a, b)
        a.insert(0, 11)
        b.insert(0, 12)
        self.assertTrue(not (a == b))
        self.assertTrue(a != b)
        self.assertTrue(a < b) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:33,代码来源:test_richcmp.py

示例7: testWritelinesUserList

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def testWritelinesUserList(self):
        # verify writelines with instance sequence
        l = UserList(['1', '2'])
        self.f.writelines(l)
        self.f.close()
        self.f = open(TESTFN, 'rb')
        buf = self.f.read()
        self.assertEqual(buf, '12') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_file2k.py

示例8: testWritelinesIntegersUserList

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def testWritelinesIntegersUserList(self):
        # verify writelines with integers in UserList
        l = UserList([1,2,3])
        self.assertRaises(TypeError, self.f.writelines, l) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_file2k.py

示例9: testWritelinesUserList

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def testWritelinesUserList(self):
        # verify writelines with instance sequence
        l = UserList([b'1', b'2'])
        self.f.writelines(l)
        self.f.close()
        self.f = self.open(TESTFN, 'rb')
        buf = self.f.read()
        self.assertEqual(buf, b'12') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_file.py

示例10: test_basic_proxy

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_basic_proxy(self):
        o = C()
        self.check_proxy(o, weakref.proxy(o))

        L = UserList.UserList()
        p = weakref.proxy(L)
        self.assertFalse(p, "proxy for empty UserList should be false")
        p.append(12)
        self.assertEqual(len(L), 1)
        self.assertTrue(p, "proxy for non-empty UserList should be true")
        with test_support.check_py3k_warnings():
            p[:] = [2, 3]
        self.assertEqual(len(L), 2)
        self.assertEqual(len(p), 2)
        self.assertIn(3, p, "proxy didn't support __contains__() properly")
        p[1] = 5
        self.assertEqual(L[1], 5)
        self.assertEqual(p[1], 5)
        L2 = UserList.UserList(L)
        p2 = weakref.proxy(L2)
        self.assertEqual(p, p2)
        ## self.assertEqual(repr(L2), repr(p2))
        L3 = UserList.UserList(range(10))
        p3 = weakref.proxy(L3)
        with test_support.check_py3k_warnings():
            self.assertEqual(L3[:], p3[:])
            self.assertEqual(L3[5:], p3[5:])
            self.assertEqual(L3[:5], p3[:5])
            self.assertEqual(L3[2:5], p3[2:5]) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:31,代码来源:test_weakref.py

示例11: testWritelinesUserList

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def testWritelinesUserList(self):
        l = UserList([b'123', b'456'])
        self.f.writelines(l)
        self.f.close()
        self.f = _FileIO(TESTFN, 'rb')
        buf = self.f.read()
        self.assertEqual(buf, b'123456') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_fileio.py

示例12: test_plain

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_plain(self):
        f = self.makeCallable('a, b=1')
        self.assertEqualCallArgs(f, '2')
        self.assertEqualCallArgs(f, '2, 3')
        self.assertEqualCallArgs(f, 'a=2')
        self.assertEqualCallArgs(f, 'b=3, a=2')
        self.assertEqualCallArgs(f, '2, b=3')
        # expand *iterable / **mapping
        self.assertEqualCallArgs(f, '*(2,)')
        self.assertEqualCallArgs(f, '*[2]')
        self.assertEqualCallArgs(f, '*(2, 3)')
        self.assertEqualCallArgs(f, '*[2, 3]')
        self.assertEqualCallArgs(f, '**{"a":2}')
        self.assertEqualCallArgs(f, 'b=3, **{"a":2}')
        self.assertEqualCallArgs(f, '2, **{"b":3}')
        self.assertEqualCallArgs(f, '**{"b":3, "a":2}')
        # expand UserList / UserDict
        self.assertEqualCallArgs(f, '*UserList([2])')
        self.assertEqualCallArgs(f, '*UserList([2, 3])')
        self.assertEqualCallArgs(f, '**UserDict(a=2)')
        self.assertEqualCallArgs(f, '2, **UserDict(b=3)')
        self.assertEqualCallArgs(f, 'b=2, **UserDict(a=3)')
        # unicode keyword args
        self.assertEqualCallArgs(f, '**{u"a":2}')
        self.assertEqualCallArgs(f, 'b=3, **{u"a":2}')
        self.assertEqualCallArgs(f, '2, **{u"b":3}')
        self.assertEqualCallArgs(f, '**{u"b":3, u"a":2}') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:29,代码来源:test_inspect.py

示例13: test_varargs

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_varargs(self):
        f = self.makeCallable('a, b=1, *c')
        self.assertEqualCallArgs(f, '2')
        self.assertEqualCallArgs(f, '2, 3')
        self.assertEqualCallArgs(f, '2, 3, 4')
        self.assertEqualCallArgs(f, '*(2,3,4)')
        self.assertEqualCallArgs(f, '2, *[3,4]')
        self.assertEqualCallArgs(f, '2, 3, *UserList([4])') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_inspect.py

示例14: test_tupleargs

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_tupleargs(self):
        f = self.makeCallable('(b,c), (d,(e,f))=(0,[1,2])')
        self.assertEqualCallArgs(f, '(2,3)')
        self.assertEqualCallArgs(f, '[2,3]')
        self.assertEqualCallArgs(f, 'UserList([2,3])')
        self.assertEqualCallArgs(f, '(2,3), (4,(5,6))')
        self.assertEqualCallArgs(f, '(2,3), (4,[5,6])')
        self.assertEqualCallArgs(f, '(2,3), [4,UserList([5,6])]') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_inspect.py

示例15: test_multiple_features

# 需要导入模块: import UserList [as 别名]
# 或者: from UserList import UserList [as 别名]
def test_multiple_features(self):
        f = self.makeCallable('a, b=2, (c,(d,e))=(3,[4,5]), *f, **g')
        self.assertEqualCallArgs(f, '2, 3, (4,[5,6]), 7')
        self.assertEqualCallArgs(f, '2, 3, *[(4,[5,6]), 7], x=8')
        self.assertEqualCallArgs(f, '2, 3, x=8, *[(4,[5,6]), 7]')
        self.assertEqualCallArgs(f, '2, x=8, *[3, (4,[5,6]), 7], y=9')
        self.assertEqualCallArgs(f, 'x=8, *[2, 3, (4,[5,6])], y=9')
        self.assertEqualCallArgs(f, 'x=8, *UserList([2, 3, (4,[5,6])]), '
                                 '**{"y":9, "z":10}')
        self.assertEqualCallArgs(f, '2, x=8, *UserList([3, (4,[5,6])]), '
                                 '**UserDict(y=9, z=10)') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_inspect.py


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