function stringlengths 11 56k | repo_name stringlengths 5 60 | features list |
|---|---|---|
def testDeterminismParameters(self, message_module):
# This message is always deterministically serialized, even if determinism
# is disabled, so we can use it to verify that all the determinism
# parameters work correctly.
golden_data = (b'\xe2\x02\nOne string'
b'\xe2\x02\nTwo string... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testPickleNestedMessage(self, message_module):
golden_message = message_module.TestPickleNestedMessage.NestedMessage(bb=1)
pickled_message = pickle.dumps(golden_message)
unpickled_message = pickle.loads(pickled_message)
self.assertEqual(unpickled_message, golden_message) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testPositiveInfinity(self, message_module):
if message_module is unittest_pb2:
golden_data = (b'\x5D\x00\x00\x80\x7F'
b'\x61\x00\x00\x00\x00\x00\x00\xF0\x7F'
b'\xCD\x02\x00\x00\x80\x7F'
b'\xD1\x02\x00\x00\x00\x00\x00\x00\xF0\x7F')
else:
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testNotANumber(self, message_module):
golden_data = (b'\x5D\x00\x00\xC0\x7F'
b'\x61\x00\x00\x00\x00\x00\x00\xF8\x7F'
b'\xCD\x02\x00\x00\xC0\x7F'
b'\xD1\x02\x00\x00\x00\x00\x00\x00\xF8\x7F')
golden_message = message_module.TestAllTypes()
golden_mes... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testNegativeInfinityPacked(self, message_module):
golden_data = (b'\xA2\x06\x04\x00\x00\x80\xFF'
b'\xAA\x06\x08\x00\x00\x00\x00\x00\x00\xF0\xFF')
golden_message = message_module.TestPackedTypes()
golden_message.ParseFromString(golden_data)
self.assertTrue(IsNegInf(golden_message.p... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtremeFloatValues(self, message_module):
message = message_module.TestAllTypes()
# Most positive exponent, no significand bits set.
kMostPosExponentNoSigBits = math.pow(2, 127)
message.optional_float = kMostPosExponentNoSigBits
message.ParseFromString(message.SerializeToString())
self.... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testFloatPrinting(self, message_module):
message = message_module.TestAllTypes()
message.optional_float = 2.0
self.assertEqual(str(message), 'optional_float: 2.0\n') | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testHighPrecisionDoublePrinting(self, message_module):
msg = message_module.TestAllTypes()
msg.optional_double = 0.12345678912345678
if sys.version_info >= (3,):
self.assertEqual(str(msg), 'optional_double: 0.12345678912345678\n')
else:
self.assertEqual(str(msg), 'optional_double: 0.1234... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testAppendRepeatedCompositeField(self, message_module):
msg = message_module.TestAllTypes()
msg.repeated_nested_message.append(
message_module.TestAllTypes.NestedMessage(bb=1))
nested = message_module.TestAllTypes.NestedMessage(bb=2)
msg.repeated_nested_message.append(nested)
try:
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFromRepeatedField(self, message_module):
msg = message_module.TestAllTypes()
msg.repeated_int32.append(1)
msg.repeated_int32.append(3)
msg.repeated_nested_message.add(bb=1)
msg.repeated_nested_message.add(bb=2)
other_msg = message_module.TestAllTypes()
other_msg.repeated_nested_... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedContains(self, message_module):
msg = message_module.TestAllTypes()
msg.repeated_int32.extend([1, 2, 3])
self.assertIn(2, msg.repeated_int32)
self.assertNotIn(0, msg.repeated_int32)
msg.repeated_nested_message.add(bb=1)
sub_msg1 = msg.repeated_nested_message[0]
sub_msg2 = me... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedNestedFieldIteration(self, message_module):
msg = message_module.TestAllTypes()
msg.repeated_nested_message.add(bb=1)
msg.repeated_nested_message.add(bb=2)
msg.repeated_nested_message.add(bb=3)
msg.repeated_nested_message.add(bb=4)
self.assertEqual([1, 2, 3, 4],
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSortingRepeatedScalarFieldsCustomComparator(self, message_module):
"""Check some different types with custom comparator."""
message = message_module.TestAllTypes()
message.repeated_int32.append(-3)
message.repeated_int32.append(-2)
message.repeated_int32.append(-1)
message.repeated_int3... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSortingRepeatedCompositeFieldsStable(self, message_module):
"""Check passing a custom comparator to sort a repeated composite field."""
message = message_module.TestAllTypes()
message.repeated_nested_message.add().bb = 21
message.repeated_nested_message.add().bb = 20
message.repeated_nested... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedScalarFieldSortArguments(self, message_module):
"""Check sorting a scalar field using list.sort() arguments."""
message = message_module.TestAllTypes()
message.repeated_int32.append(-3)
message.repeated_int32.append(-2)
message.repeated_int32.append(-1)
message.repeated_int32.so... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedFieldsAreSequences(self, message_module):
m = message_module.TestAllTypes()
self.assertIsInstance(m.repeated_int32, collections_abc.MutableSequence)
self.assertIsInstance(m.repeated_nested_message,
collections_abc.MutableSequence) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedFieldInsideNestedMessage(self, message_module):
m = message_module.NestedTestAllTypes()
m.payload.repeated_int32.extend([])
self.assertTrue(m.HasField('payload')) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFromString(self, message_module):
m1 = message_module.TestAllTypes()
m2 = message_module.TestAllTypes()
# Cpp extension will lazily create a sub message which is immutable.
self.assertEqual(0, m1.optional_nested_message.bb)
m2.optional_nested_message.bb = 1
# Make sure cmessage poin... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFromStringUsingMemoryViewWorksInPy3(self, message_module):
m2 = message_module.TestAllTypes()
m2.optional_string = 'scalar string'
m2.repeated_string.append('repeated string')
m2.optional_bytes = b'scalar bytes'
m2.repeated_bytes.append(b'repeated bytes')
serialized = m2.SerializeT... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFromStringUsingMemoryViewIsPy2Error(self, message_module):
memview = memoryview(b'')
with self.assertRaises(TypeError):
message_module.TestAllTypes.FromString(memview) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def ensureNestedMessageExists(self, msg, attribute):
"""Make sure that a nested message object exists.
As soon as a nested message attribute is accessed, it will be present in the
_fields dict, without being marked as actually being set.
"""
getattr(msg, attribute)
self.assertFalse(msg.HasField... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofDefaultValues(self, message_module):
m = message_module.TestAllTypes()
self.assertIs(None, m.WhichOneof('oneof_field'))
self.assertFalse(m.HasField('oneof_field'))
self.assertFalse(m.HasField('oneof_uint32'))
# Oneof is set even when setting it to a default value.
m.oneof_uint32 = ... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofCompositeFieldReadAccess(self, message_module):
m = message_module.TestAllTypes()
m.oneof_uint32 = 11
self.ensureNestedMessageExists(m, 'oneof_nested_message')
self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field'))
self.assertEqual(11, m.oneof_uint32) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofClearField(self, message_module):
m = message_module.TestAllTypes()
m.oneof_uint32 = 11
m.ClearField('oneof_field')
if message_module is unittest_pb2:
self.assertFalse(m.HasField('oneof_field'))
self.assertFalse(m.HasField('oneof_uint32'))
self.assertIs(None, m.WhichOneof('one... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofClearUnsetField(self, message_module):
m = message_module.TestAllTypes()
m.oneof_uint32 = 11
self.ensureNestedMessageExists(m, 'oneof_nested_message')
m.ClearField('oneof_nested_message')
self.assertEqual(11, m.oneof_uint32)
if message_module is unittest_pb2:
self.assertTrue(m... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofCopyFrom(self, message_module):
m = message_module.TestAllTypes()
m.oneof_uint32 = 11
m2 = message_module.TestAllTypes()
m2.CopyFrom(m)
self.assertEqual('oneof_uint32', m2.WhichOneof('oneof_field')) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofMessageMergeFrom(self, message_module):
m = message_module.NestedTestAllTypes()
m.payload.oneof_nested_message.bb = 11
m.child.payload.oneof_nested_message.bb = 12
m2 = message_module.NestedTestAllTypes()
m2.payload.oneof_uint32 = 13
m2.MergeFrom(m)
self.assertEqual('oneof_neste... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testOneofClear(self, message_module):
m = message_module.TestAllTypes()
m.oneof_uint32 = 11
m.Clear()
self.assertIsNone(m.WhichOneof('oneof_field'))
m.oneof_bytes = b'bb'
self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testLongValuedSlice(self, message_module):
"""It should be possible to use long-valued indices in slices.
This didn't used to work in the v2 C++ implementation.
"""
m = message_module.TestAllTypes()
# Repeated scalar
m.repeated_int32.append(1)
sl = m.repeated_int32[long(0):long(len(m.r... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtendInt32WithNothing(self, message_module):
"""Test no-ops extending repeated int32 fields."""
m = message_module.TestAllTypes()
self.assertSequenceEqual([], m.repeated_int32)
# TODO(ptucker): Deprecate this behavior. b/18413862
for falsy_value in MessageTest.FALSY_VALUES:
m.repeate... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtendStringWithNothing(self, message_module):
"""Test no-ops extending repeated string fields."""
m = message_module.TestAllTypes()
self.assertSequenceEqual([], m.repeated_string)
# TODO(ptucker): Deprecate this behavior. b/18413862
for falsy_value in MessageTest.FALSY_VALUES:
m.repe... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtendFloatWithPythonList(self, message_module):
"""Test extending repeated float fields with python lists."""
m = message_module.TestAllTypes()
self.assertSequenceEqual([], m.repeated_float)
m.repeated_float.extend([0.0])
self.assertSequenceEqual([0.0], m.repeated_float)
m.repeated_floa... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtendStringWithString(self, message_module):
"""Test extending repeated string fields with characters from a string."""
m = message_module.TestAllTypes()
self.assertSequenceEqual([], m.repeated_string)
m.repeated_string.extend('abc')
self.assertSequenceEqual(['a', 'b', 'c'], m.repeated_stri... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def __init__(self, values=None):
self._list = values or [] | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def __len__(self):
return len(self._list) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtendInt32WithIterable(self, message_module):
"""Test extending repeated int32 fields with iterable."""
m = message_module.TestAllTypes()
self.assertSequenceEqual([], m.repeated_int32)
m.repeated_int32.extend(MessageTest.TestIterable([]))
self.assertSequenceEqual([], m.repeated_int32)
m... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testExtendStringWithIterable(self, message_module):
"""Test extending repeated string fields with iterable."""
m = message_module.TestAllTypes()
self.assertSequenceEqual([], m.repeated_string)
m.repeated_string.extend(MessageTest.TestIterable([]))
self.assertSequenceEqual([], m.repeated_string)
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSortEmptyRepeatedCompositeContainer(self, message_module):
"""Exercise a scenario that has led to segfaults in the past.
"""
m = message_module.TestAllTypes()
m.repeated_nested_message.sort() | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedScalarFieldPop(self, message_module):
m = message_module.TestAllTypes()
with self.assertRaises(IndexError) as _:
m.repeated_int32.pop()
m.repeated_int32.extend(range(5))
self.assertEqual(4, m.repeated_int32.pop())
self.assertEqual(0, m.repeated_int32.pop(0))
self.assertEqua... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testRepeatedCompareWithSelf(self, message_module):
m = message_module.TestAllTypes()
for i in range(5):
m.repeated_int32.insert(i, i)
n = m.repeated_nested_message.add()
n.bb = i
self.assertSequenceEqual(m.repeated_int32, m.repeated_int32)
self.assertEqual(m.repeated_nested_message... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSetRepeatedComposite(self, message_module):
m = message_module.TestAllTypes()
with self.assertRaises(AttributeError):
m.repeated_int32 = []
m.repeated_int32.append(1)
with self.assertRaises(AttributeError):
m.repeated_int32 = [] | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testFieldPresence(self):
message = unittest_pb2.TestAllTypes()
self.assertFalse(message.HasField("optional_int32"))
self.assertFalse(message.HasField("optional_bool"))
self.assertFalse(message.HasField("optional_nested_message"))
with self.assertRaises(ValueError):
message.HasField("fiel... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testUnknownEnumMap(self):
m = map_proto2_unittest_pb2.TestEnumMap()
m.known_map_field[123] = 0
with self.assertRaises(ValueError):
m.unknown_map_field[1] = 123 | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFromExtensions(self):
msg1 = more_extensions_pb2.TopLevelMessage()
msg2 = more_extensions_pb2.TopLevelMessage()
# Cpp extension will lazily create a sub message which is immutable.
self.assertEqual(0, msg1.submessage.Extensions[
more_extensions_pb2.optional_int_extension])
self.... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testGoldenPackedExtensions(self):
golden_data = test_util.GoldenFileData('golden_packed_fields_message')
golden_message = unittest_pb2.TestPackedExtensions()
golden_message.ParseFromString(golden_data)
all_set = unittest_pb2.TestPackedExtensions()
test_util.SetAllPackedExtensions(all_set)
se... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testParsingMerge(self):
"""Check the merge behavior when a required or optional field appears
multiple times in the input."""
messages = [
unittest_pb2.TestAllTypes(),
unittest_pb2.TestAllTypes(),
unittest_pb2.TestAllTypes() ]
messages[0].optional_int32 = 1
messages[1].op... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testPythonicInitWithDict(self):
# Both string/unicode field name keys should work.
kwargs = {
'optional_int32': 100,
u'optional_fixed32': 200,
}
msg = unittest_pb2.TestAllTypes(**kwargs)
self.assertEqual(100, msg.optional_int32)
self.assertEqual(200, msg.optional_fixed32) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def assertMapIterEquals(self, map_iter, dict_value):
# Avoid mutating caller's copy.
dict_value = dict(dict_value)
for k, v in map_iter:
self.assertEqual(v, dict_value[k])
del dict_value[k]
self.assertEqual({}, dict_value) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testProto3ParserDropDefaultScalar(self):
message_proto2 = unittest_pb2.TestAllTypes()
message_proto2.optional_int32 = 0
message_proto2.optional_string = ''
message_proto2.optional_bytes = b''
self.assertEqual(len(message_proto2.ListFields()), 3)
message_proto3 = unittest_proto3_arena_pb2.Te... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testAssignUnknownEnum(self):
"""Assigning an unknown enum value is allowed and preserves the value."""
m = unittest_proto3_arena_pb2.TestAllTypes()
# Proto3 can assign unknown enums.
m.optional_nested_enum = 1234567
self.assertEqual(1234567, m.optional_nested_enum)
m.repeated_nested_enum.ap... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testScalarMapDefaults(self):
msg = map_unittest_pb2.TestMap()
# Scalars start out unset.
self.assertFalse(-123 in msg.map_int32_int32)
self.assertFalse(-2**33 in msg.map_int64_int64)
self.assertFalse(123 in msg.map_uint32_uint32)
self.assertFalse(2**33 in msg.map_uint64_uint64)
self.ass... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testScalarMap(self):
msg = map_unittest_pb2.TestMap()
self.assertEqual(0, len(msg.map_int32_int32))
self.assertFalse(5 in msg.map_int32_int32)
msg.map_int32_int32[-123] = -456
msg.map_int64_int64[-2**33] = -2**34
msg.map_uint32_uint32[123] = 456
msg.map_uint64_uint64[2**33] = 2**34
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testStringUnicodeConversionInMap(self):
msg = map_unittest_pb2.TestMap()
unicode_obj = u'\u1234'
bytes_obj = unicode_obj.encode('utf8')
msg.map_string_string[bytes_obj] = bytes_obj
(key, value) = list(msg.map_string_string.items())[0]
self.assertEqual(key, unicode_obj)
self.assertEqu... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testNestedMessageMapItemDelete(self):
msg = map_unittest_pb2.TestMap()
msg.map_int32_all_types[1].optional_nested_message.bb = 1
del msg.map_int32_all_types[1]
msg.map_int32_all_types[2].optional_nested_message.bb = 2
self.assertEqual(1, len(msg.map_int32_all_types))
msg.map_int32_all_types[... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFrom(self):
msg = map_unittest_pb2.TestMap()
msg.map_int32_int32[12] = 34
msg.map_int32_int32[56] = 78
msg.map_int64_int64[22] = 33
msg.map_int32_foreign_message[111].c = 5
msg.map_int32_foreign_message[222].c = 10
msg2 = map_unittest_pb2.TestMap()
msg2.map_int32_int32[12] ... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMergeFromBadType(self):
msg = map_unittest_pb2.TestMap()
with self.assertRaisesRegexp(
TypeError,
r'Parameter to MergeFrom\(\) must be instance of same class: expected '
r'.*TestMap got int\.'):
msg.MergeFrom(1) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testIntegerMapWithLongs(self):
msg = map_unittest_pb2.TestMap()
msg.map_int32_int32[long(-123)] = long(-456)
msg.map_int64_int64[long(-2**33)] = long(-2**34)
msg.map_uint32_uint32[long(123)] = long(456)
msg.map_uint64_uint64[long(2**33)] = long(2**34)
serialized = msg.SerializeToString()
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapAssignmentCausesPresenceForSubmessages(self):
msg = map_unittest_pb2.TestMapSubmessage()
msg.test_map.map_int32_foreign_message[123].c = 5
serialized = msg.SerializeToString()
msg2 = map_unittest_pb2.TestMapSubmessage()
msg2.ParseFromString(serialized)
self.assertEqual(msg, msg2)
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSubmessageMap(self):
msg = map_unittest_pb2.TestMap()
submsg = msg.map_int32_foreign_message[111]
self.assertIs(submsg, msg.map_int32_foreign_message[111])
self.assertIsInstance(submsg, unittest_pb2.ForeignMessage)
submsg.c = 5
serialized = msg.SerializeToString()
msg2 = map_unitt... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testPython2Map(self):
if sys.version_info < (3,):
msg = map_unittest_pb2.TestMap()
msg.map_int32_int32[2] = 4
msg.map_int32_int32[3] = 6
msg.map_int32_int32[4] = 8
msg.map_int32_int32[5] = 10
map_int32 = msg.map_int32_int32
self.assertEqual(4, len(map_int32))
msg2... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapDeterministicSerialization(self):
golden_data = (b'r\x0c\n\x07init_op\x12\x01d'
b'r\n\n\x05item1\x12\x01e'
b'r\n\n\x05item2\x12\x01f'
b'r\n\n\x05item3\x12\x01g'
b'r\x0b\n\x05item4\x12\x02QQ'
b'r\x12\n\rlocal_in... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapConstruction(self):
msg = map_unittest_pb2.TestMap(map_int32_int32={1: 2, 3: 4})
self.assertEqual(2, msg.map_int32_int32[1])
self.assertEqual(4, msg.map_int32_int32[3])
msg = map_unittest_pb2.TestMap(
map_int32_foreign_message={3: unittest_pb2.ForeignMessage(c=5)})
self.assertEqu... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapMessageFieldConstruction(self):
msg1 = map_unittest_pb2.TestMap()
msg1.map_string_foreign_message['test'].c = 42
msg2 = map_unittest_pb2.TestMap(
map_string_foreign_message=msg1.map_string_foreign_message)
self.assertEqual(42, msg2.map_string_foreign_message['test'].c) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapValidAfterFieldCleared(self):
# Map needs to work even if field is cleared.
# For the C++ implementation this tests the correctness of
# MapContainer::Release()
msg = map_unittest_pb2.TestMap()
int32_map = msg.map_int32_int32
int32_map[2] = 4
int32_map[3] = 6
int32_map[4] = 8... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMessageMapItemValidAfterTopMessageCleared(self):
# Message map item needs to work even if it is cleared.
# For the C++ implementation this tests the correctness of
# MapContainer::Release()
msg = map_unittest_pb2.TestMap()
msg.map_int32_all_types[2].optional_string = 'bar'
if api_implem... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapDelete(self):
msg = map_unittest_pb2.TestMap()
self.assertEqual(0, len(msg.map_int32_int32))
msg.map_int32_int32[4] = 6
self.assertEqual(1, len(msg.map_int32_int32))
with self.assertRaises(KeyError):
del msg.map_int32_int32[88]
del msg.map_int32_int32[4]
self.assertEqual... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testMapsCompare(self):
msg = map_unittest_pb2.TestMap()
msg.map_int32_int32[-123] = -456
self.assertEqual(msg.map_int32_int32, msg.map_int32_int32)
self.assertEqual(msg.map_int32_foreign_message,
msg.map_int32_foreign_message)
self.assertNotEqual(msg.map_int32_int32, 0) | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testStrictUtf8Check(self):
# Test u'\ud801' is rejected at parser in both python2 and python3.
serialized = (b'r\x03\xed\xa0\x81')
msg = unittest_proto3_arena_pb2.TestAllTypes()
with self.assertRaises(Exception) as context:
msg.MergeFromString(serialized)
if api_implementation.Type() == 'p... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSurrogatesInPython3(self):
# Surrogates like U+D83D is an invalid unicode character, it is
# supported by Python2 only because in some builds, unicode strings
# use 2-bytes code units. Since Python 3.3, we don't have this problem.
#
# Surrogates are utf16 code units, in a unicode string they... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testSurrogatesInPython2(self):
# Test optional_string=u'\ud801\udc01'.
# surrogate pair is acceptable in python2.
msg = unittest_proto3_arena_pb2.TestAllTypes(
optional_string=u'\ud801\udc01')
# TODO(jieluo): Change pure python to have same behavior with c extension.
# Some build in pyth... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def assertImportFromName(self, msg, base_name):
# Parse <type 'module.class_name'> to extra 'some.name' as a string.
tp_name = str(type(msg)).split("'")[1]
valid_names = ('Repeated%sContainer' % base_name,
'Repeated%sFieldContainer' % base_name)
self.assertTrue(any(tp_name.endswith(v)... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def setMessage(self, message):
message.repeated_int32.append(1)
message.repeated_int64.append(1)
message.repeated_uint32.append(1)
message.repeated_uint64.append(1)
message.repeated_sint32.append(1)
message.repeated_sint64.append(1)
message.repeated_fixed32.append(1)
message.repeated_fix... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testUnpackedFields(self):
message = packed_field_test_pb2.TestUnpackedTypes()
self.setMessage(message)
golden_data = (b'\x08\x01'
b'\x10\x01'
b'\x18\x01'
b'\x20\x01'
b'\x28\x02'
b'\x30\x02'
... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def setUpClass(cls):
# At the moment, reference cycles between DescriptorPool and Message classes
# are not detected and these objects are never freed.
# To avoid errors with ReferenceLeakChecker, we create the class only once.
file_desc = """
name: "f/f.msg2"
package: "f"
message_type... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def testAssertOversizeProto(self):
from google.protobuf.pyext._message import SetAllowOversizeProtos
SetAllowOversizeProtos(False)
q = self.proto_cls()
try:
q.ParseFromString(self.p_serialized)
except message.DecodeError as e:
self.assertEqual(str(e), 'Error parsing message') | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def main():
url = '%s/%s/%s/%s' % (SERVER, PATH, REVISION, FILENAME)
sysroot = os.path.join(SCRIPT_DIR, os.pardir, 'third_party', 'linux',
'sysroot')
stamp = os.path.join(sysroot, '.stamp')
if os.path.exists(stamp):
with open(stamp) as s:
if s.read() == u... | nwjs/chromium.src | [
136,
133,
136,
45,
1453904223
] |
def encode(c):
retval = c
i = ord(c)
for low, high in escape_range:
if i < low:
break
if i >= low and i <= high:
retval = "".join(["%%%2X" % o for o in c.encode("utf-8")])
break
return retval | endlessm/chromium-browser | [
21,
16,
21,
3,
1435959644
] |
def test_uris(self):
"""Test that URIs are invariant under the transformation."""
invariant = [
"ftp://ftp.is.co.za/rfc/rfc1808.txt",
"http://www.ietf.org/rfc/rfc2396.txt",
"ldap://[2001:db8::7]/c=GB?objectClass?one",
"mailto:John.D... | endlessm/chromium-browser | [
21,
16,
21,
3,
1435959644
] |
def LocalFileToURL(localFileName):
"Convert a filename to an XPCOM nsIFileURL object."
# Create an nsILocalFile
localFile = components.classes["@mozilla.org/file/local;1"] \
.createInstance(components.interfaces.nsILocalFile)
localFile.initWithPath(localFileName)
# Use the IO Service to c... | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def __init__(self, name_thingy = None, mode="r"):
self.lockob = threading.Lock()
self.inputStream = self.outputStream = None
if name_thingy is not None:
self.init(name_thingy, mode) | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def _lock(self):
self.lockob.acquire() | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def read(self, n = -1):
assert self.inputStream is not None, "Not setup for read!"
self._lock()
try:
return str(self.inputStream.read(n))
finally:
self._release() | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def write(self, data):
assert self.outputStream is not None, "Not setup for write!"
self._lock()
try:
self.outputStream.write(data, len(data))
finally:
self._release() | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def flush(self):
self._lock()
try:
if self.outputStream is not None: self.outputStream.flush()
finally:
self._release() | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def init(self, url, mode="r"):
self.close()
if mode != "r":
raise ValueError, "only 'r' mode supported'"
io_service = components.classes["@mozilla.org/network/io-service;1"] \
.getService(components.interfaces.nsIIOService)
if hasattr(url, "queryInterf... | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def __init__(self, *args):
self.fileIO = None
_File.__init__(self, *args) | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def close(self):
if self.fileIO is not None:
self.fileIO.close()
self.fileIO = None
_File.close(self) | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def _DoTestRead(file, expected):
# read in a couple of chunks, just to test that our various arg combinations work.
got = file.read(3)
got = got + file.read(300)
got = got + file.read(0)
got = got + file.read()
if got != expected:
raise RuntimeError, "Reading '%s' failed - got %d bytes, ... | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def _TestLocalFile():
import tempfile, os
fname = tempfile.mktemp()
data = "Hello from Python"
test_file = LocalFile(fname, "w")
try:
test_file.write(data)
test_file.close()
# Make sure Python can read it OK.
f = open(fname, "r")
assert f.read() == data, "Eeek... | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def _TestURI(url):
test_file = URIFile(url)
print "Opened file is", test_file
got = test_file.read()
print "Read %d bytes of data from %r" % (len(got), url)
test_file.close() | ruibarreira/linuxtrail | [
2,
2,
2,
1,
1434186057
] |
def sample_request(request):
polyline = GPolyline('LINESTRING(101 26, 112 26, 102 31)')
event = GEvent('click',
'function() { location.href = "http://www.google.com"}')
polyline.add_event(event)
return render_to_response('mytemplate.html',
{'google' : Google... | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def __init__(self, event, action):
"""
Initializes a GEvent object.
Parameters:
event:
string for the event, such as 'click'. The event must be a valid
event for the object in the Google Maps API.
There is no validation of the event type within Django.
... | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def __init__(self):
self.events = [] | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def add_event(self, event):
"Attaches a GEvent to the overlay object."
self.events.append(event) | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def __init__(self, poly,
stroke_color='#0000ff', stroke_weight=2, stroke_opacity=1,
fill_color='#0000ff', fill_opacity=0.4):
"""
The GPolygon object initializes on a GEOS Polygon or a parameter that
may be instantiated into GEOS Polygon. Please note that this w... | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def js_params(self):
return '%s, "%s", %s, %s, "%s", %s' % (self.points, self.stroke_color, self.stroke_weight, self.stroke_opacity,
self.fill_color, self.fill_opacity) | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def __init__(self, geom, color='#0000ff', weight=2, opacity=1):
"""
The GPolyline object may be initialized on GEOS LineStirng, LinearRing,
and Polygon objects (internal rings not supported) or a parameter that
may instantiated into one of the above geometries.
Keyword Options:
... | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def js_params(self):
return '%s, "%s", %s, %s' % (self.latlngs, self.color, self.weight, self.opacity) | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def __init__(self, varname, image=None, iconsize=None,
shadow=None, shadowsize=None, iconanchor=None,
infowindowanchor=None):
self.varname = varname
self.image = image
self.iconsize = iconsize
self.shadow = shadow
self.shadowsize = shadowsize
... | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
def __lt__(self, other):
return self.varname < other.varname | Vvucinic/Wander | [
1,
1,
1,
11,
1449375044
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.