third_party/protobuf/python/google/protobuf/internal/message_test.py
def testSortingRepeatedScalarFieldsDefaultComparator(self, message_module):
    """Check some different types with the default comparator."""
    message = message_module.TestAllTypes()

    # TODO(mattp): would testing more scalar types strengthen test?
    message.repeated_int32.append(1)
    message.repeated_int32.append(3)
    message.repeated_int32.append(2)
    message.repeated_int32.sort()
    self.assertEqual(message.repeated_int32[0], 1)
    self.assertEqual(message.repeated_int32[1], 2)
    self.assertEqual(message.repeated_int32[2], 3)
    self.assertEqual(str(message.repeated_int32), str([1, 2, 3]))

    message.repeated_float.append(1.1)
    message.repeated_float.append(1.3)
    message.repeated_float.append(1.2)
    message.repeated_float.sort()
    self.assertAlmostEqual(message.repeated_float[0], 1.1)
    self.assertAlmostEqual(message.repeated_float[1], 1.2)
    self.assertAlmostEqual(message.repeated_float[2], 1.3)

    message.repeated_string.append('a')
    message.repeated_string.append('c')
    message.repeated_string.append('b')
    message.repeated_string.sort()
    self.assertEqual(message.repeated_string[0], 'a')
    self.assertEqual(message.repeated_string[1], 'b')
    self.assertEqual(message.repeated_string[2], 'c')
    self.assertEqual(str(message.repeated_string), str([u'a', u'b', u'c']))

    message.repeated_bytes.append(b'a')
    message.repeated_bytes.append(b'c')
    message.repeated_bytes.append(b'b')
    message.repeated_bytes.sort()
    self.assertEqual(message.repeated_bytes[0], b'a')
    self.assertEqual(message.repeated_bytes[1], b'b')
    self.assertEqual(message.repeated_bytes[2], b'c')
    self.assertEqual(str(message.repeated_bytes), str([b'a', b'b', b'c']))
Check some different types with the default comparator.
Check some different types with the default comparator.
Check some different types with the default comparator .
def testSortingRepeatedScalarFieldsDefaultComparator(self, message_module):
    message = message_module.TestAllTypes()
    message.repeated_int32.append(1)
    message.repeated_int32.append(3)
    message.repeated_int32.append(2)
    message.repeated_int32.sort()
    self.assertEqual(message.repeated_int32[0], 1)
    self.assertEqual(message.repeated_int32[1], 2)
    self.assertEqual(message.repeated_int32[2], 3)
    self.assertEqual(str(message.repeated_int32), str([1, 2, 3]))
    message.repeated_float.append(1.1)
    message.repeated_float.append(1.3)
    message.repeated_float.append(1.2)
    message.repeated_float.sort()
    self.assertAlmostEqual(message.repeated_float[0], 1.1)
    self.assertAlmostEqual(message.repeated_float[1], 1.2)
    self.assertAlmostEqual(message.repeated_float[2], 1.3)
    message.repeated_string.append('a')
    message.repeated_string.append('c')
    message.repeated_string.append('b')
    message.repeated_string.sort()
    self.assertEqual(message.repeated_string[0], 'a')
    self.assertEqual(message.repeated_string[1], 'b')
    self.assertEqual(message.repeated_string[2], 'c')
    self.assertEqual(str(message.repeated_string), str([u'a', u'b', u'c']))
    message.repeated_bytes.append(b'a')
    message.repeated_bytes.append(b'c')
    message.repeated_bytes.append(b'b')
    message.repeated_bytes.sort()
    self.assertEqual(message.repeated_bytes[0], b'a')
    self.assertEqual(message.repeated_bytes[1], b'b')
    self.assertEqual(message.repeated_bytes[2], b'c')
    self.assertEqual(str(message.repeated_bytes), str([b'a', b'b', b'c']))
def testSortingRepeatedScalarFieldsDefaultComparator ( self , message_module ) : message = message_module . TestAllTypes ( ) message . repeated_int32 . append ( 1 ) message . repeated_int32 . append ( 3 ) message . repeated_int32 . append ( 2 ) message . repeated_int32 . sort ( ) self . assertEqual ( message . repeated_int32 [ 0 ] , 1 ) self . assertEqual ( message . repeated_int32 [ 1 ] , 2 ) self . assertEqual ( message . repeated_int32 [ 2 ] , 3 ) self . assertEqual ( str ( message . repeated_int32 ) , str ( [ 1 , 2 , 3 ] ) ) message . repeated_float . append ( 1.1 ) message . repeated_float . append ( 1.3 ) message . repeated_float . append ( 1.2 ) message . repeated_float . sort ( ) self . assertAlmostEqual ( message . repeated_float [ 0 ] , 1.1 ) self . assertAlmostEqual ( message . repeated_float [ 1 ] , 1.2 ) self . assertAlmostEqual ( message . repeated_float [ 2 ] , 1.3 ) message . repeated_string . append ( 'a' ) message . repeated_string . append ( 'c' ) message . repeated_string . append ( 'b' ) message . repeated_string . sort ( ) self . assertEqual ( message . repeated_string [ 0 ] , 'a' ) self . assertEqual ( message . repeated_string [ 1 ] , 'b' ) self . assertEqual ( message . repeated_string [ 2 ] , 'c' ) self . assertEqual ( str ( message . repeated_string ) , str ( [ u'a' , u'b' , u'c' ] ) ) message . repeated_bytes . append ( b'a' ) message . repeated_bytes . append ( b'c' ) message . repeated_bytes . append ( b'b' ) message . repeated_bytes . sort ( ) self . assertEqual ( message . repeated_bytes [ 0 ] , b'a' ) self . assertEqual ( message . repeated_bytes [ 1 ] , b'b' ) self . assertEqual ( message . repeated_bytes [ 2 ] , b'c' ) self . assertEqual ( str ( message . repeated_bytes ) , str ( [ b'a' , b'b' , b'c' ] ) )
Check some different types with the default comparator.
Check some different types with the default comparator .
"""Check some different types with the default comparator.""" # TODO(mattp): would testing more scalar types strengthen test?
self
message_module