docstr: Check sorting a scalar field using list.sort() arguments.
docstr_tok: ["Check","sorting","a","scalar","field","using","list.sort","(",")","arguments","."]
code: def testRepeatedScalarFieldSortArguments(self):
      """Check sorting a scalar field using list.sort() arguments."""
      message = unittest_pb2.TestAllTypes()
  
      abs_cmp = lambda a, b: cmp(abs(a), abs(b))
      message.repeated_int32.append(-3)
      message.repeated_int32.append(-2)
      message.repeated_int32.append(-1)
      message.repeated_int32.sort(key=abs)
      self.assertEqual(list(message.repeated_int32), [-1, -2, -3])
      message.repeated_int32.sort(key=abs, reverse=True)
      self.assertEqual(list(message.repeated_int32), [-3, -2, -1])
      message.repeated_int32.sort(sort_function=abs_cmp)
      self.assertEqual(list(message.repeated_int32), [-1, -2, -3])
      message.repeated_int32.sort(cmp=abs_cmp, reverse=True)
      self.assertEqual(list(message.repeated_int32), [-3, -2, -1])
  
      len_cmp = lambda a, b: cmp(len(a), len(b))
      message.repeated_string.append("aaa")
      message.repeated_string.append("bb")
      message.repeated_string.append("c")
      message.repeated_string.sort(key=len)
      self.assertEqual(
          list(message.repeated_string), ["c", "bb", "aaa"]
      )
      message.repeated_string.sort(key=len, reverse=True)
      self.assertEqual(
          list(message.repeated_string), ["aaa", "bb", "c"]
      )
      message.repeated_string.sort(sort_function=len_cmp)
      self.assertEqual(
          list(message.repeated_string), ["c", "bb", "aaa"]
      )
      message.repeated_string.sort(cmp=len_cmp, reverse=True)
      self.assertEqual(
          list(message.repeated_string), ["aaa", "bb", "c"]
      )
  
imports: import copy
  import math
  import operator
  import pickle
  import unittest
  from google.protobuf import unittest_import_pb2
  from google.protobuf import unittest_pb2
  from google.protobuf.internal import api_implementation
  from google.protobuf.internal import test_util
  from google.protobuf import message
label_desc: Use image node_id 19 for calling the MessageTest obj's underlying member method code with example usage: obj.testRepeatedScalarFieldSortArguments() without return types