本文整理匯總了Python中krpc.types.Types.tuple_type方法的典型用法代碼示例。如果您正苦於以下問題:Python Types.tuple_type方法的具體用法?Python Types.tuple_type怎麽用?Python Types.tuple_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類krpc.types.Types
的用法示例。
在下文中一共展示了Types.tuple_type方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_coerce_to
# 需要導入模塊: from krpc.types import Types [as 別名]
# 或者: from krpc.types.Types import tuple_type [as 別名]
def test_coerce_to(self):
types = Types()
cases = [
(42.0, 42, types.double_type),
(42.0, 42, types.float_type),
(42, 42.0, types.sint32_type),
(42, 42L, types.sint32_type),
(42L, 42.0, types.sint64_type),
(42L, 42, types.sint64_type),
(42, 42.0, types.uint32_type),
(42, 42L, types.uint32_type),
(42L, 42.0, types.uint64_type),
(42L, 42, types.uint64_type),
(list(), tuple(), types.list_type(types.string_type)),
((0, 1, 2), [0, 1, 2],
types.tuple_type(types.sint32_type,
types.sint32_type,
types.sint32_type)),
([0, 1, 2], (0, 1, 2),
types.list_type(types.sint32_type)),
(['foo', 'bar'], ['foo', 'bar'],
types.list_type(types.string_type))
]
for expected, value, typ in cases:
coerced_value = types.coerce_to(value, typ)
self.assertEqual(expected, coerced_value)
self.assertEqual(type(expected), type(coerced_value))
strings = [
u'foo',
u'\xe2\x84\xa2',
u'Mystery Goo\xe2\x84\xa2 Containment Unit'
]
for string in strings:
self.assertEqual(
string, types.coerce_to(string, types.string_type))
self.assertRaises(ValueError, types.coerce_to,
None, types.float_type)
self.assertRaises(ValueError, types.coerce_to,
'', types.float_type)
self.assertRaises(ValueError, types.coerce_to,
True, types.float_type)
self.assertRaises(ValueError, types.coerce_to,
list(), types.tuple_type(types.uint32_type))
self.assertRaises(ValueError, types.coerce_to,
['foo', 2], types.tuple_type(types.string_type))
self.assertRaises(ValueError, types.coerce_to,
[1], types.tuple_type(types.string_type))
示例2: test_tuple_3_types
# 需要導入模塊: from krpc.types import Types [as 別名]
# 或者: from krpc.types.Types import tuple_type [as 別名]
def test_tuple_3_types(self):
types = Types()
typ = types.tuple_type(
types.float_type, types.uint64_type, types.string_type)
self.assertTrue(isinstance(typ, TupleType))
self.assertEqual(typ.python_type, tuple)
self.check_protobuf_type(
Type.TUPLE, '', '', 3, typ.protobuf_type)
self.check_protobuf_type(
Type.FLOAT, '', '', 0, typ.protobuf_type.types[0])
self.check_protobuf_type(
Type.UINT64, '', '', 0, typ.protobuf_type.types[1])
self.check_protobuf_type(
Type.STRING, '', '', 0, typ.protobuf_type.types[2])
self.assertEqual(3, len(typ.value_types))
self.assertTrue(isinstance(typ.value_types[0], ValueType))
self.assertTrue(isinstance(typ.value_types[1], ValueType))
self.assertTrue(isinstance(typ.value_types[2], ValueType))
self.assertEqual(float, typ.value_types[0].python_type)
self.assertEqual(long, typ.value_types[1].python_type)
self.assertEqual(str, typ.value_types[2].python_type)
self.check_protobuf_type(
Type.FLOAT, '', '', 0, typ.value_types[0].protobuf_type)
self.check_protobuf_type(
Type.UINT64, '', '', 0, typ.value_types[1].protobuf_type)
self.check_protobuf_type(
Type.STRING, '', '', 0, typ.value_types[2].protobuf_type)
示例3: test_tuple_1_types
# 需要導入模塊: from krpc.types import Types [as 別名]
# 或者: from krpc.types.Types import tuple_type [as 別名]
def test_tuple_1_types(self):
types = Types()
typ = types.tuple_type(types.bool_type)
self.assertTrue(isinstance(typ, TupleType))
self.assertEqual(typ.python_type, tuple)
self.check_protobuf_type(
Type.TUPLE, '', '', 1, typ.protobuf_type)
self.check_protobuf_type(
Type.BOOL, '', '', 0, typ.protobuf_type.types[0])
self.assertEqual(1, len(typ.value_types))
self.assertTrue(isinstance(typ.value_types[0], ValueType))
self.assertEqual(bool, typ.value_types[0].python_type)
self.check_protobuf_type(
Type.BOOL, '', '', 0, typ.value_types[0].protobuf_type)
示例4: test_tuple_2_types
# 需要導入模塊: from krpc.types import Types [as 別名]
# 或者: from krpc.types.Types import tuple_type [as 別名]
def test_tuple_2_types(self):
types = Types()
typ = types.tuple_type(types.uint32_type, types.string_type)
self.assertTrue(isinstance(typ, TupleType))
self.assertEqual(typ.python_type, tuple)
self.check_protobuf_type(
Type.TUPLE, '', '', 2, typ.protobuf_type)
self.check_protobuf_type(
Type.UINT32, '', '', 0, typ.protobuf_type.types[0])
self.check_protobuf_type(
Type.STRING, '', '', 0, typ.protobuf_type.types[1])
self.assertEqual(2, len(typ.value_types))
self.assertTrue(isinstance(typ.value_types[0], ValueType))
self.assertTrue(isinstance(typ.value_types[1], ValueType))
self.assertEqual(int, typ.value_types[0].python_type)
self.assertEqual(str, typ.value_types[1].python_type)
self.check_protobuf_type(
Type.UINT32, '', '', 0, typ.value_types[0].protobuf_type)
self.check_protobuf_type(
Type.STRING, '', '', 0, typ.value_types[1].protobuf_type)