本文整理汇总了Python中celery.local.Proxy类的典型用法代码示例。如果您正苦于以下问题:Python Proxy类的具体用法?Python Proxy怎么用?Python Proxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Proxy类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reduce
def test_reduce(self):
class X(object):
def __reduce__(self):
return 123
x = Proxy(lambda: X())
self.assertEqual(x.__reduce__(), 123)
示例2: test_coerce
def test_coerce(self):
class O(object):
def __coerce__(self, other):
return self, other
o = Proxy(O)
self.assertTrue(o.__coerce__(3))
示例3: test_index
def test_index(self):
class O(object):
def __index__(self):
return 1
o = Proxy(O)
self.assertEqual(o.__index__(), 1)
示例4: test_complex_cast
def test_complex_cast(self):
class O(object):
def __complex__(self):
return complex(10.333)
o = Proxy(O)
self.assertEqual(o.__complex__(), complex(10.333))
示例5: test_reduce
def test_reduce(self):
class X(object):
def __reduce__(self):
return 123
x = Proxy(lambda: X())
assert x.__reduce__() == 123
示例6: test_index
def test_index(self):
class O(object):
def __index__(self):
return 1
o = Proxy(O)
assert o.__index__() == 1
示例7: test_complex_cast
def test_complex_cast(self):
class O(object):
def __complex__(self):
return complex(10.333)
o = Proxy(O)
assert o.__complex__() == complex(10.333)
示例8: test_listproxy
def test_listproxy(self):
v = []
x = Proxy(lambda: v)
x.append(1)
x.extend([2, 3, 4])
self.assertEqual(x[0], 1)
self.assertEqual(x[:-1], [1, 2, 3])
del(x[-1])
self.assertEqual(x[:-1], [1, 2])
x[0] = 10
self.assertEqual(x[0], 10)
self.assertIn(10, x)
self.assertEqual(len(x), 3)
self.assertTrue(iter(x))
示例9: test_listproxy
def test_listproxy(self):
v = []
x = Proxy(lambda: v)
x.append(1)
x.extend([2, 3, 4])
self.assertEqual(x[0], 1)
self.assertEqual(x[:-1], [1, 2, 3])
del(x[-1])
self.assertEqual(x[:-1], [1, 2])
x[0] = 10
self.assertEqual(x[0], 10)
self.assertIn(10, x)
self.assertEqual(len(x), 3)
self.assertTrue(iter(x))
x[0:2] = [1, 2]
del(x[0:2])
self.assertTrue(str(x))
if sys.version_info[0] < 3:
self.assertEqual(x.__cmp__(object()), -1)
示例10: test_listproxy
def test_listproxy(self):
v = []
x = Proxy(lambda: v)
x.append(1)
x.extend([2, 3, 4])
assert x[0] == 1
assert x[:-1] == [1, 2, 3]
del(x[-1])
assert x[:-1] == [1, 2]
x[0] = 10
assert x[0] == 10
assert 10 in x
assert len(x) == 3
assert iter(x)
x[0:2] = [1, 2]
del(x[0:2])
assert str(x)
if sys.version_info[0] < 3:
assert x.__cmp__(object()) == -1
示例11: test_int
def test_int(self):
self.assertEqual(Proxy(lambda: 10) + 1, Proxy(lambda: 11))
self.assertEqual(Proxy(lambda: 10) - 1, Proxy(lambda: 9))
self.assertEqual(Proxy(lambda: 10) * 2, Proxy(lambda: 20))
self.assertEqual(Proxy(lambda: 10) ** 2, Proxy(lambda: 100))
self.assertEqual(Proxy(lambda: 20) / 2, Proxy(lambda: 10))
self.assertEqual(Proxy(lambda: 20) // 2, Proxy(lambda: 10))
self.assertEqual(Proxy(lambda: 11) % 2, Proxy(lambda: 1))
self.assertEqual(Proxy(lambda: 10) << 2, Proxy(lambda: 40))
self.assertEqual(Proxy(lambda: 10) >> 2, Proxy(lambda: 2))
self.assertEqual(Proxy(lambda: 10) ^ 7, Proxy(lambda: 13))
self.assertEqual(Proxy(lambda: 10) | 40, Proxy(lambda: 42))
self.assertEqual(~Proxy(lambda: 10), Proxy(lambda: -11))
self.assertEqual(-Proxy(lambda: 10), Proxy(lambda: -10))
self.assertEqual(+Proxy(lambda: -10), Proxy(lambda: -10))
self.assertTrue(Proxy(lambda: 10) < Proxy(lambda: 20))
self.assertTrue(Proxy(lambda: 20) > Proxy(lambda: 10))
self.assertTrue(Proxy(lambda: 10) >= Proxy(lambda: 10))
self.assertTrue(Proxy(lambda: 10) <= Proxy(lambda: 10))
self.assertTrue(Proxy(lambda: 10) == Proxy(lambda: 10))
self.assertTrue(Proxy(lambda: 20) != Proxy(lambda: 10))
x = Proxy(lambda: 10)
x -= 1
self.assertEqual(x, 9)
x = Proxy(lambda: 9)
x += 1
self.assertEqual(x, 10)
x = Proxy(lambda: 10)
x *= 2
self.assertEqual(x, 20)
x = Proxy(lambda: 20)
x /= 2
self.assertEqual(x, 10)
x = Proxy(lambda: 10)
x %= 2
self.assertEqual(x, 0)
x = Proxy(lambda: 10)
x <<= 3
self.assertEqual(x, 80)
x = Proxy(lambda: 80)
x >>= 4
self.assertEqual(x, 5)
x = Proxy(lambda: 5)
x ^= 1
self.assertEqual(x, 4)
x = Proxy(lambda: 4)
x **= 4
self.assertEqual(x, 256)
x = Proxy(lambda: 256)
x //= 2
self.assertEqual(x, 128)
x = Proxy(lambda: 128)
x |= 2
self.assertEqual(x, 130)
x = Proxy(lambda: 130)
x &= 10
self.assertEqual(x, 2)
x = Proxy(lambda: 10)
self.assertEqual(type(x.__float__()), float)
self.assertEqual(type(x.__int__()), int)
self.assertEqual(type(x.__long__()), long)
self.assertTrue(hex(x))
self.assertTrue(oct(x))
示例12: test_get_current_local
def test_get_current_local(self):
x = Proxy(lambda: 10)
object.__setattr__(x, '_Proxy_local', Mock())
self.assertTrue(x._get_current_object())
示例13: test_int
def test_int(self):
assert Proxy(lambda: 10) + 1 == Proxy(lambda: 11)
assert Proxy(lambda: 10) - 1 == Proxy(lambda: 9)
assert Proxy(lambda: 10) * 2 == Proxy(lambda: 20)
assert Proxy(lambda: 10) ** 2 == Proxy(lambda: 100)
assert Proxy(lambda: 20) / 2 == Proxy(lambda: 10)
assert Proxy(lambda: 20) // 2 == Proxy(lambda: 10)
assert Proxy(lambda: 11) % 2 == Proxy(lambda: 1)
assert Proxy(lambda: 10) << 2 == Proxy(lambda: 40)
assert Proxy(lambda: 10) >> 2 == Proxy(lambda: 2)
assert Proxy(lambda: 10) ^ 7 == Proxy(lambda: 13)
assert Proxy(lambda: 10) | 40 == Proxy(lambda: 42)
assert Proxy(lambda: 10) != Proxy(lambda: -11)
assert Proxy(lambda: 10) != Proxy(lambda: -10)
assert Proxy(lambda: -10) == Proxy(lambda: -10)
assert Proxy(lambda: 10) < Proxy(lambda: 20)
assert Proxy(lambda: 20) > Proxy(lambda: 10)
assert Proxy(lambda: 10) >= Proxy(lambda: 10)
assert Proxy(lambda: 10) <= Proxy(lambda: 10)
assert Proxy(lambda: 10) == Proxy(lambda: 10)
assert Proxy(lambda: 20) != Proxy(lambda: 10)
assert Proxy(lambda: 100).__divmod__(30)
assert Proxy(lambda: 100).__truediv__(30)
assert abs(Proxy(lambda: -100))
x = Proxy(lambda: 10)
x -= 1
assert x == 9
x = Proxy(lambda: 9)
x += 1
assert x == 10
x = Proxy(lambda: 10)
x *= 2
assert x == 20
x = Proxy(lambda: 20)
x /= 2
assert x == 10
x = Proxy(lambda: 10)
x %= 2
assert x == 0
x = Proxy(lambda: 10)
x <<= 3
assert x == 80
x = Proxy(lambda: 80)
x >>= 4
assert x == 5
x = Proxy(lambda: 5)
x ^= 1
assert x == 4
x = Proxy(lambda: 4)
x **= 4
assert x == 256
x = Proxy(lambda: 256)
x //= 2
assert x == 128
x = Proxy(lambda: 128)
x |= 2
assert x == 130
x = Proxy(lambda: 130)
x &= 10
assert x == 2
x = Proxy(lambda: 10)
assert type(x.__float__()) == float
assert type(x.__int__()) == int
if not PY3:
assert type(x.__long__()) == long_t
assert hex(x)
assert oct(x)