本文整理汇总了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)