diff --git a/apitools/base/protorpclite/descriptor_test.py b/apitools/base/protorpclite/descriptor_test.py index 5fbed35f..5a4b22fd 100644 --- a/apitools/base/protorpclite/descriptor_test.py +++ b/apitools/base/protorpclite/descriptor_test.py @@ -49,7 +49,7 @@ class MyEnum(messages.Enum): described = descriptor.describe_enum_value(MyEnum.MY_NAME) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) class DescribeEnumTest(test_util.TestCase): @@ -63,7 +63,7 @@ class EmptyEnum(messages.Enum): described = descriptor.describe_enum(EmptyEnum) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testNestedEnum(self): class MyScope(messages.Message): @@ -76,7 +76,7 @@ class NestedEnum(messages.Enum): described = descriptor.describe_enum(MyScope.NestedEnum) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) @unittest.skipIf('PyPy' in platform.python_implementation(), 'todo: reenable this') @@ -105,7 +105,7 @@ class EnumWithItems(messages.Enum): described = descriptor.describe_enum(EnumWithItems) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) class DescribeFieldTest(test_util.TestCase): @@ -127,7 +127,7 @@ def testLabel(self): described = descriptor.describe_field(field) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testDefault(self): test_cases = ( @@ -154,7 +154,7 @@ def testDefault(self): described = descriptor.describe_field(field) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testDefault_EnumField(self): class MyEnum(messages.Enum): @@ -174,7 +174,7 @@ class MyEnum(messages.Enum): expected.default_value = '1' described = descriptor.describe_field(field) - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testMessageField(self): field = messages.MessageField(descriptor.FieldDescriptor, 10) @@ -190,7 +190,7 @@ def testMessageField(self): described = descriptor.describe_field(field) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testDateTimeField(self): field = message_types.DateTimeField(20) @@ -206,7 +206,7 @@ def testDateTimeField(self): described = descriptor.describe_field(field) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) class DescribeMessageTest(test_util.TestCase): @@ -220,7 +220,7 @@ class MyMessage(messages.Message): described = descriptor.describe_message(MyMessage) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testDefinitionWithFields(self): class MessageWithFields(messages.Message): @@ -242,7 +242,7 @@ class MessageWithFields(messages.Message): described = descriptor.describe_message(MessageWithFields) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testNestedEnum(self): class MessageWithEnum(messages.Message): @@ -265,7 +265,7 @@ class Music(messages.Enum): described = descriptor.describe_message(MessageWithEnum) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testNestedMessage(self): class MessageWithMessage(messages.Message): @@ -281,7 +281,7 @@ class Nesty(messages.Message): described = descriptor.describe_message(MessageWithMessage) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) class DescribeFileTest(test_util.TestCase): @@ -309,7 +309,7 @@ def testEmptyModule(self): described = descriptor.describe_file(module) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testNoPackageName(self): """Test describing a module with no module name.""" @@ -319,7 +319,7 @@ def testNoPackageName(self): described = descriptor.describe_file(module) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testPackageName(self): """Test using the 'package' module attribute.""" @@ -331,7 +331,7 @@ def testPackageName(self): described = descriptor.describe_file(module) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testMain(self): """Test using the 'package' module attribute.""" @@ -343,7 +343,7 @@ def testMain(self): described = descriptor.describe_file(module) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testMessages(self): """Test that messages are described.""" @@ -363,7 +363,7 @@ def testMessages(self): described = descriptor.describe_file(module) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) def testEnums(self): """Test that enums are described.""" @@ -383,7 +383,7 @@ def testEnums(self): described = descriptor.describe_file(module) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) class DescribeFileSetTest(test_util.TestCase): @@ -394,7 +394,7 @@ def testNoModules(self): described = descriptor.describe_file_set([]) described.check_initialized() # The described FileSet.files will be None. - self.assertEquals(descriptor.FileSet(), described) + self.assertEqual(descriptor.FileSet(), described) def testWithModules(self): """Test what happens when no modules provided.""" @@ -410,32 +410,32 @@ def testWithModules(self): described = descriptor.describe_file_set(modules) described.check_initialized() - self.assertEquals(expected, described) + self.assertEqual(expected, described) class DescribeTest(test_util.TestCase): def testModule(self): - self.assertEquals(descriptor.describe_file(test_util), + self.assertEqual(descriptor.describe_file(test_util), descriptor.describe(test_util)) def testField(self): - self.assertEquals( + self.assertEqual( descriptor.describe_field(test_util.NestedMessage.a_value), descriptor.describe(test_util.NestedMessage.a_value)) def testEnumValue(self): - self.assertEquals( + self.assertEqual( descriptor.describe_enum_value( test_util.OptionalMessage.SimpleEnum.VAL1), descriptor.describe(test_util.OptionalMessage.SimpleEnum.VAL1)) def testMessage(self): - self.assertEquals(descriptor.describe_message(test_util.NestedMessage), + self.assertEqual(descriptor.describe_message(test_util.NestedMessage), descriptor.describe(test_util.NestedMessage)) def testEnum(self): - self.assertEquals( + self.assertEqual( descriptor.describe_enum(test_util.OptionalMessage.SimpleEnum), descriptor.describe(test_util.OptionalMessage.SimpleEnum)) @@ -451,25 +451,25 @@ def fn(self): 'string', 1.2, None): - self.assertEquals(None, descriptor.describe(value)) + self.assertEqual(None, descriptor.describe(value)) class ModuleFinderTest(test_util.TestCase): def testFindMessage(self): - self.assertEquals( + self.assertEqual( descriptor.describe_message(descriptor.FileSet), descriptor.import_descriptor_loader( 'apitools.base.protorpclite.descriptor.FileSet')) def testFindField(self): - self.assertEquals( + self.assertEqual( descriptor.describe_field(descriptor.FileSet.files), descriptor.import_descriptor_loader( 'apitools.base.protorpclite.descriptor.FileSet.files')) def testFindEnumValue(self): - self.assertEquals( + self.assertEqual( descriptor.describe_enum_value( test_util.OptionalMessage.SimpleEnum.VAL1), descriptor.import_descriptor_loader( @@ -489,8 +489,8 @@ def setUp(self): }) def testLookupPackage(self): - self.assertEquals('csv', self.library.lookup_package('csv')) - self.assertEquals( + self.assertEqual('csv', self.library.lookup_package('csv')) + self.assertEqual( 'apitools.base.protorpclite', self.library.lookup_package('apitools.base.protorpclite')) @@ -508,7 +508,7 @@ def testNoPackage(self): 'Could not find definition for not.real', self.library.lookup_package, 'not.real.Packageless') - self.assertEquals(None, self.library.lookup_package('Packageless')) + self.assertEqual(None, self.library.lookup_package('Packageless')) if __name__ == '__main__': diff --git a/apitools/base/protorpclite/message_types.py b/apitools/base/protorpclite/message_types.py index 1bbac38f..2636f409 100644 --- a/apitools/base/protorpclite/message_types.py +++ b/apitools/base/protorpclite/message_types.py @@ -78,8 +78,8 @@ def value_from_message(self, message): """ message = super(DateTimeField, self).value_from_message(message) if message.time_zone_offset is None: - return datetime.datetime.utcfromtimestamp( - message.milliseconds / 1000.0) + return datetime.datetime.fromtimestamp( + message.milliseconds / 1000.0, tz=datetime.timezone.utc).replace(tzinfo=None) # Need to subtract the time zone offset, because when we call # datetime.fromtimestamp, it will add the time zone offset to the @@ -97,7 +97,7 @@ def value_to_message(self, value): # DateTimeMessage's milliseconds field. if value.tzinfo is None: time_zone_offset = 0 - local_epoch = datetime.datetime.utcfromtimestamp(0) + local_epoch = datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc).replace(tzinfo=None) else: time_zone_offset = util.total_seconds( value.tzinfo.utcoffset(value)) diff --git a/apitools/base/protorpclite/messages_test.py b/apitools/base/protorpclite/messages_test.py index 3ad75e41..d4c2d9e5 100644 --- a/apitools/base/protorpclite/messages_test.py +++ b/apitools/base/protorpclite/messages_test.py @@ -55,14 +55,14 @@ class ValidationErrorTest(test_util.TestCase): def testStr_NoFieldName(self): """Test string version of ValidationError when no name provided.""" - self.assertEquals('Validation error', + self.assertEqual('Validation error', str(messages.ValidationError('Validation error'))) def testStr_FieldName(self): """Test string version of ValidationError when no name provided.""" validation_error = messages.ValidationError('Validation error') validation_error.field_name = 'a_field' - self.assertEquals('Validation error', str(validation_error)) + self.assertEqual('Validation error', str(validation_error)) class EnumTest(test_util.TestCase): @@ -85,18 +85,18 @@ class Color(messages.Enum): def testNames(self): """Test that names iterates over enum names.""" - self.assertEquals( + self.assertEqual( set(['BLUE', 'GREEN', 'INDIGO', 'ORANGE', 'RED', 'VIOLET', 'YELLOW']), set(Color.names())) def testNumbers(self): """Tests that numbers iterates of enum numbers.""" - self.assertEquals(set([2, 4, 5, 20, 40, 50, 80]), set(Color.numbers())) + self.assertEqual(set([2, 4, 5, 20, 40, 50, 80]), set(Color.numbers())) def testIterate(self): """Test that __iter__ iterates over all enum values.""" - self.assertEquals(set(Color), + self.assertEqual(set(Color), set([Color.RED, Color.ORANGE, Color.YELLOW, @@ -107,7 +107,7 @@ def testIterate(self): def testNaturalOrder(self): """Test that natural order enumeration is in numeric order.""" - self.assertEquals([Color.ORANGE, + self.assertEqual([Color.ORANGE, Color.GREEN, Color.INDIGO, Color.RED, @@ -118,24 +118,24 @@ def testNaturalOrder(self): def testByName(self): """Test look-up by name.""" - self.assertEquals(Color.RED, Color.lookup_by_name('RED')) + self.assertEqual(Color.RED, Color.lookup_by_name('RED')) self.assertRaises(KeyError, Color.lookup_by_name, 20) self.assertRaises(KeyError, Color.lookup_by_name, Color.RED) def testByNumber(self): """Test look-up by number.""" self.assertRaises(KeyError, Color.lookup_by_number, 'RED') - self.assertEquals(Color.RED, Color.lookup_by_number(20)) + self.assertEqual(Color.RED, Color.lookup_by_number(20)) self.assertRaises(KeyError, Color.lookup_by_number, Color.RED) def testConstructor(self): """Test that constructor look-up by name or number.""" - self.assertEquals(Color.RED, Color('RED')) - self.assertEquals(Color.RED, Color(u'RED')) - self.assertEquals(Color.RED, Color(20)) + self.assertEqual(Color.RED, Color('RED')) + self.assertEqual(Color.RED, Color(u'RED')) + self.assertEqual(Color.RED, Color(20)) if six.PY2: - self.assertEquals(Color.RED, Color(long(20))) - self.assertEquals(Color.RED, Color(Color.RED)) + self.assertEqual(Color.RED, Color(long(20))) + self.assertEqual(Color.RED, Color(Color.RED)) self.assertRaises(TypeError, Color, 'Not exists') self.assertRaises(TypeError, Color, 'Red') self.assertRaises(TypeError, Color, 100) @@ -143,7 +143,7 @@ def testConstructor(self): def testLen(self): """Test that len function works to count enums.""" - self.assertEquals(7, len(Color)) + self.assertEqual(7, len(Color)) def testNoSubclasses(self): """Test that it is not possible to sub-class enum classes.""" @@ -179,9 +179,9 @@ def testDefEnum(self): 'Saturday': 7, 'Sunday': 8}, 'WeekDay') - self.assertEquals('Wednesday', WeekDay(3).name) - self.assertEquals(6, WeekDay('Friday').number) - self.assertEquals(WeekDay.Sunday, WeekDay('Sunday')) + self.assertEqual('Wednesday', WeekDay(3).name) + self.assertEqual(6, WeekDay('Friday').number) + self.assertEqual(WeekDay.Sunday, WeekDay('Sunday')) def testNonInt(self): """Test that non-integer values rejection by enum def.""" @@ -203,7 +203,7 @@ class NotImportant(messages.Enum): """Testing for value zero""" VALUE = 0 - self.assertEquals(0, int(NotImportant.VALUE)) + self.assertEqual(0, int(NotImportant.VALUE)) def testTooLargeInt(self): """Test that numbers too large are rejected.""" @@ -221,18 +221,18 @@ def testRepeatedInt(self): def testStr(self): """Test converting to string.""" - self.assertEquals('RED', str(Color.RED)) - self.assertEquals('ORANGE', str(Color.ORANGE)) + self.assertEqual('RED', str(Color.RED)) + self.assertEqual('ORANGE', str(Color.ORANGE)) def testInt(self): """Test converting to int.""" - self.assertEquals(20, int(Color.RED)) - self.assertEquals(2, int(Color.ORANGE)) + self.assertEqual(20, int(Color.RED)) + self.assertEqual(2, int(Color.ORANGE)) def testRepr(self): """Test enum representation.""" - self.assertEquals('Color(RED, 20)', repr(Color.RED)) - self.assertEquals('Color(YELLOW, 40)', repr(Color.YELLOW)) + self.assertEqual('Color(RED, 20)', repr(Color.RED)) + self.assertEqual('Color(YELLOW, 40)', repr(Color.YELLOW)) def testDocstring(self): """Test that docstring is supported ok.""" @@ -241,7 +241,7 @@ class NotImportant(messages.Enum): VALUE1 = 1 - self.assertEquals('I have a docstring.', NotImportant.__doc__) + self.assertEqual('I have a docstring.', NotImportant.__doc__) def testDeleteEnumValue(self): """Test that enum values cannot be deleted.""" @@ -250,18 +250,18 @@ def testDeleteEnumValue(self): def testEnumName(self): """Test enum name.""" module_name = test_util.get_module_name(EnumTest) - self.assertEquals('%s.Color' % module_name, Color.definition_name()) - self.assertEquals(module_name, Color.outer_definition_name()) - self.assertEquals(module_name, Color.definition_package()) + self.assertEqual('%s.Color' % module_name, Color.definition_name()) + self.assertEqual(module_name, Color.outer_definition_name()) + self.assertEqual(module_name, Color.definition_package()) def testDefinitionName_OverrideModule(self): """Test enum module is overriden by module package name.""" global package try: package = 'my.package' - self.assertEquals('my.package.Color', Color.definition_name()) - self.assertEquals('my.package', Color.outer_definition_name()) - self.assertEquals('my.package', Color.definition_package()) + self.assertEqual('my.package.Color', Color.definition_name()) + self.assertEqual('my.package', Color.outer_definition_name()) + self.assertEqual('my.package', Color.definition_package()) finally: del package @@ -274,10 +274,10 @@ class Enum1(messages.Enum): sys.modules = dict(sys.modules) try: del sys.modules[__name__] - self.assertEquals('Enum1', Enum1.definition_name()) - self.assertEquals(None, Enum1.outer_definition_name()) - self.assertEquals(None, Enum1.definition_package()) - self.assertEquals(six.text_type, type(Enum1.definition_name())) + self.assertEqual('Enum1', Enum1.definition_name()) + self.assertEqual(None, Enum1.outer_definition_name()) + self.assertEqual(None, Enum1.definition_package()) + self.assertEqual(six.text_type, type(Enum1.definition_name())) finally: sys.modules = original_modules @@ -296,20 +296,20 @@ class NestedEnum(messages.Enum): pass module_name = test_util.get_module_name(EnumTest) - self.assertEquals('%s.MyMessage.NestedEnum' % module_name, + self.assertEqual('%s.MyMessage.NestedEnum' % module_name, MyMessage.NestedEnum.definition_name()) - self.assertEquals('%s.MyMessage' % module_name, + self.assertEqual('%s.MyMessage' % module_name, MyMessage.NestedEnum.outer_definition_name()) - self.assertEquals(module_name, + self.assertEqual(module_name, MyMessage.NestedEnum.definition_package()) - self.assertEquals( + self.assertEqual( '%s.MyMessage.NestedMessage.NestedEnum' % module_name, MyMessage.NestedMessage.NestedEnum.definition_name()) - self.assertEquals( + self.assertEqual( '%s.MyMessage.NestedMessage' % module_name, MyMessage.NestedMessage.NestedEnum.outer_definition_name()) - self.assertEquals( + self.assertEqual( module_name, MyMessage.NestedMessage.NestedEnum.definition_package()) @@ -318,14 +318,14 @@ def testMessageDefinition(self): class OuterEnum(messages.Enum): pass - self.assertEquals(None, OuterEnum.message_definition()) + self.assertEqual(None, OuterEnum.message_definition()) class OuterMessage(messages.Message): class InnerEnum(messages.Enum): pass - self.assertEquals( + self.assertEqual( OuterMessage, OuterMessage.InnerEnum.message_definition()) def testComparison(self): @@ -337,25 +337,25 @@ class Enum1(messages.Enum): class Enum2(messages.Enum): VAL1 = 1 - self.assertEquals(Enum1.VAL1, Enum1.VAL1) - self.assertNotEquals(Enum1.VAL1, Enum1.VAL2) - self.assertNotEquals(Enum1.VAL1, Enum2.VAL1) - self.assertNotEquals(Enum1.VAL1, 'VAL1') - self.assertNotEquals(Enum1.VAL1, 1) - self.assertNotEquals(Enum1.VAL1, 2) - self.assertNotEquals(Enum1.VAL1, None) - self.assertNotEquals(Enum1.VAL1, Enum2.VAL1) + self.assertEqual(Enum1.VAL1, Enum1.VAL1) + self.assertNotEqual(Enum1.VAL1, Enum1.VAL2) + self.assertNotEqual(Enum1.VAL1, Enum2.VAL1) + self.assertNotEqual(Enum1.VAL1, 'VAL1') + self.assertNotEqual(Enum1.VAL1, 1) + self.assertNotEqual(Enum1.VAL1, 2) + self.assertNotEqual(Enum1.VAL1, None) + self.assertNotEqual(Enum1.VAL1, Enum2.VAL1) self.assertTrue(Enum1.VAL1 < Enum1.VAL2) self.assertTrue(Enum1.VAL2 > Enum1.VAL1) - self.assertNotEquals(1, Enum2.VAL1) + self.assertNotEqual(1, Enum2.VAL1) def testPickle(self): """Testing pickling and unpickling of Enum instances.""" colors = list(Color) unpickled = pickle.loads(pickle.dumps(colors)) - self.assertEquals(colors, unpickled) + self.assertEqual(colors, unpickled) # Unpickling shouldn't create new enum instances. for i, color in enumerate(colors): self.assertTrue(color is unpickled[i]) @@ -367,11 +367,11 @@ def setUp(self): self.integer_field = messages.IntegerField(1, repeated=True) def testConstructor(self): - self.assertEquals([1, 2, 3], + self.assertEqual([1, 2, 3], messages.FieldList(self.integer_field, [1, 2, 3])) - self.assertEquals([1, 2, 3], + self.assertEqual([1, 2, 3], messages.FieldList(self.integer_field, (1, 2, 3))) - self.assertEquals([], messages.FieldList(self.integer_field, [])) + self.assertEqual([], messages.FieldList(self.integer_field, [])) def testNone(self): self.assertRaises(TypeError, messages.FieldList, @@ -420,7 +420,7 @@ def testConstructor_Scalars(self): def testSetSlice(self): field_list = messages.FieldList(self.integer_field, [1, 2, 3, 4, 5]) field_list[1:3] = [10, 20] - self.assertEquals([1, 10, 20, 4, 5], field_list) + self.assertEqual([1, 10, 20, 4, 5], field_list) def testSetSlice_InvalidValues(self): field_list = messages.FieldList(self.integer_field, [1, 2, 3, 4, 5]) @@ -439,7 +439,7 @@ def setslice(): def testSetItem(self): field_list = messages.FieldList(self.integer_field, [2]) field_list[0] = 10 - self.assertEquals([10], field_list) + self.assertEqual([10], field_list) def testSetItem_InvalidValues(self): field_list = messages.FieldList(self.integer_field, [2]) @@ -456,7 +456,7 @@ def setitem(): def testAppend(self): field_list = messages.FieldList(self.integer_field, [2]) field_list.append(10) - self.assertEquals([2, 10], field_list) + self.assertEqual([2, 10], field_list) def testAppend_InvalidValues(self): field_list = messages.FieldList(self.integer_field, [2]) @@ -474,7 +474,7 @@ def append(): def testExtend(self): field_list = messages.FieldList(self.integer_field, [2]) field_list.extend([10]) - self.assertEquals([2, 10], field_list) + self.assertEqual([2, 10], field_list) def testExtend_InvalidValues(self): field_list = messages.FieldList(self.integer_field, [2]) @@ -491,7 +491,7 @@ def extend(): def testInsert(self): field_list = messages.FieldList(self.integer_field, [2, 3]) field_list.insert(1, 10) - self.assertEquals([2, 10, 3], field_list) + self.assertEqual([2, 10, 3], field_list) def testInsert_InvalidValues(self): field_list = messages.FieldList(self.integer_field, [2, 3]) @@ -509,9 +509,9 @@ def testPickle(self): """Testing pickling and unpickling of FieldList instances.""" field_list = messages.FieldList(self.integer_field, [1, 2, 3, 4, 5]) unpickled = pickle.loads(pickle.dumps(field_list)) - self.assertEquals(field_list, unpickled) + self.assertEqual(field_list, unpickled) self.assertIsInstance(unpickled.field, messages.IntegerField) - self.assertEquals(1, unpickled.field.number) + self.assertEqual(1, unpickled.field.number) self.assertTrue(unpickled.field.repeated) @@ -588,14 +588,14 @@ def testDefaultVariant(self): """Test that default variant is used when not set.""" def action(field_class): field = field_class(1) - self.assertEquals(field_class.DEFAULT_VARIANT, field.variant) + self.assertEqual(field_class.DEFAULT_VARIANT, field.variant) self.ActionOnAllFieldClasses(action) def testAlternateVariant(self): """Test that default variant is used when not set.""" field = messages.IntegerField(1, variant=messages.Variant.UINT32) - self.assertEquals(messages.Variant.UINT32, field.variant) + self.assertEqual(messages.Variant.UINT32, field.variant) def testDefaultFields_Single(self): """Test default field is correct type (single).""" @@ -659,7 +659,7 @@ class Symbol(messages.Enum): field = messages.EnumField(Symbol, 1, default=Symbol.ALPHA) - self.assertEquals(Symbol.ALPHA, field.default) + self.assertEqual(Symbol.ALPHA, field.default) def testDefaultFields_EnumStringDelayedResolution(self): """Test that enum fields resolve default strings.""" @@ -668,7 +668,7 @@ def testDefaultFields_EnumStringDelayedResolution(self): 1, default='OPTIONAL') - self.assertEquals( + self.assertEqual( descriptor.FieldDescriptor.Label.OPTIONAL, field.default) def testDefaultFields_EnumIntDelayedResolution(self): @@ -678,7 +678,7 @@ def testDefaultFields_EnumIntDelayedResolution(self): 1, default=2) - self.assertEquals( + self.assertEqual( descriptor.FieldDescriptor.Label.REQUIRED, field.default) def testDefaultFields_EnumOkIfTypeKnown(self): @@ -687,7 +687,7 @@ def testDefaultFields_EnumOkIfTypeKnown(self): 1, default='REPEATED') - self.assertEquals( + self.assertEqual( descriptor.FieldDescriptor.Label.REPEATED, field.default) def testDefaultFields_EnumForceCheckIfTypeKnown(self): @@ -854,10 +854,10 @@ def action(field_class): def testValidateCastingElement(self): field = messages.FloatField(1) - self.assertEquals(type(field.validate_element(12)), float) - self.assertEquals(type(field.validate_element(12.0)), float) + self.assertEqual(type(field.validate_element(12)), float) + self.assertEqual(type(field.validate_element(12.0)), float) field = messages.IntegerField(1) - self.assertEquals(type(field.validate_element(12)), int) + self.assertEqual(type(field.validate_element(12)), int) self.assertRaises(messages.ValidationError, field.validate_element, 12.0) # should fails from float to int @@ -894,7 +894,7 @@ class MyMessage(messages.Message): pass field = messages.MessageField(MyMessage, 10) - self.assertEquals(MyMessage, field.type) + self.assertEqual(MyMessage, field.type) def testMessageField_ForwardReference(self): """Test the construction of forward reference message fields.""" @@ -923,19 +923,19 @@ class NestedMessage(messages.Message): pass - self.assertEquals(MyMessage, + self.assertEqual(MyMessage, MyMessage.field_by_name('self_reference').type) - self.assertEquals(ForwardMessage, + self.assertEqual(ForwardMessage, MyMessage.field_by_name('forward').type) - self.assertEquals(ForwardMessage.NestedMessage, + self.assertEqual(ForwardMessage.NestedMessage, MyMessage.field_by_name('nested').type) - self.assertEquals(MyMessage.Inner, + self.assertEqual(MyMessage.Inner, MyMessage.field_by_name('inner').type) - self.assertEquals(MyMessage.Sibling, + self.assertEqual(MyMessage.Sibling, MyMessage.Inner.field_by_name('sibling').type) finally: try: @@ -1076,7 +1076,7 @@ class Color(messages.Enum): BLUE = 3 field = messages.EnumField(Color, 10) - self.assertEquals(Color, field.type) + self.assertEqual(Color, field.type) class Another(messages.Enum): VALUE = 1 @@ -1110,13 +1110,13 @@ class ForwardMessage(messages.Message): class NestedEnum(messages.Enum): pass - self.assertEquals(ForwardEnum, + self.assertEqual(ForwardEnum, MyMessage.field_by_name('forward').type) - self.assertEquals(ForwardMessage.NestedEnum, + self.assertEqual(ForwardMessage.NestedEnum, MyMessage.field_by_name('nested').type) - self.assertEquals(MyMessage.Inner, + self.assertEqual(MyMessage.Inner, MyMessage.field_by_name('inner').type) finally: try: @@ -1150,7 +1150,7 @@ class MyMessage(messages.Message): my_field = messages.StringField(1) - self.assertEquals( + self.assertEqual( MyMessage, MyMessage.field_by_name('my_field').message_definition()) @@ -1163,7 +1163,7 @@ class MyMessage(messages.Message): m1 = MyMessage() m2 = MyMessage() m2.my_field = None - self.assertEquals(m1, m2) + self.assertEqual(m1, m2) def testNonUtf8Str(self): """Test validation fails for non-UTF-8 StringField values.""" @@ -1320,7 +1320,7 @@ class RepeatedMessage(messages.Message): repeated_values = [{}, {'required': 10}, SimpleMessage(required=20)] repeated_message1 = RepeatedMessage(simple=repeated_values) - self.assertEquals(3, len(repeated_message1.simple)) + self.assertEqual(3, len(repeated_message1.simple)) self.assertFalse(repeated_message1.is_initialized()) repeated_message1.simple[0].required = 0 @@ -1328,7 +1328,7 @@ class RepeatedMessage(messages.Message): repeated_message2 = RepeatedMessage() repeated_message2.simple = repeated_values - self.assertEquals(3, len(repeated_message2.simple)) + self.assertEqual(3, len(repeated_message2.simple)) self.assertFalse(repeated_message2.is_initialized()) repeated_message2.simple[0].required = 0 @@ -1368,7 +1368,7 @@ def testNameIsSetOnFields(self): class HasNamedFields(messages.Message): field = messages.StringField(1) - self.assertEquals('field', HasNamedFields.field_by_number(1).name) + self.assertEqual('field', HasNamedFields.field_by_number(1).name) def testSubclassingMessageDisallowed(self): """Not permitted to create sub-classes of message classes.""" @@ -1390,18 +1390,18 @@ def testAllFields(self): # Order does not matter, so sort now. fields = sorted(fields, key=lambda f: f.name) - self.assertEquals(3, len(fields)) - self.assertEquals('a3', fields[0].name) - self.assertEquals('b1', fields[1].name) - self.assertEquals('c2', fields[2].name) + self.assertEqual(3, len(fields)) + self.assertEqual('a3', fields[0].name) + self.assertEqual('b1', fields[1].name) + self.assertEqual('c2', fields[2].name) def testFieldByName(self): """Test getting field by name.""" ComplexMessage = self.CreateMessageClass() - self.assertEquals(3, ComplexMessage.field_by_name('a3').number) - self.assertEquals(1, ComplexMessage.field_by_name('b1').number) - self.assertEquals(2, ComplexMessage.field_by_name('c2').number) + self.assertEqual(3, ComplexMessage.field_by_name('a3').number) + self.assertEqual(1, ComplexMessage.field_by_name('b1').number) + self.assertEqual(2, ComplexMessage.field_by_name('c2').number) self.assertRaises(KeyError, ComplexMessage.field_by_name, @@ -1411,9 +1411,9 @@ def testFieldByNumber(self): """Test getting field by number.""" ComplexMessage = self.CreateMessageClass() - self.assertEquals('a3', ComplexMessage.field_by_number(3).name) - self.assertEquals('b1', ComplexMessage.field_by_number(1).name) - self.assertEquals('c2', ComplexMessage.field_by_number(2).name) + self.assertEqual('a3', ComplexMessage.field_by_number(3).name) + self.assertEqual('b1', ComplexMessage.field_by_number(1).name) + self.assertEqual('c2', ComplexMessage.field_by_number(2).name) self.assertRaises(KeyError, ComplexMessage.field_by_number, @@ -1425,13 +1425,13 @@ class SomeMessage(messages.Message): a_value = messages.StringField(1, default=u'a default') message = SomeMessage() - self.assertEquals(None, message.get_assigned_value('a_value')) + self.assertEqual(None, message.get_assigned_value('a_value')) message.a_value = u'a string' - self.assertEquals(u'a string', message.get_assigned_value('a_value')) + self.assertEqual(u'a string', message.get_assigned_value('a_value')) message.a_value = u'a default' - self.assertEquals(u'a default', message.get_assigned_value('a_value')) + self.assertEqual(u'a default', message.get_assigned_value('a_value')) self.assertRaisesWithRegexpMatch( AttributeError, @@ -1449,22 +1449,22 @@ class SomeMessage(messages.Message): self.assertRaises(AttributeError, message.reset, 'unknown') - self.assertEquals(u'a default', message.a_value) + self.assertEqual(u'a default', message.a_value) message.reset('a_value') - self.assertEquals(u'a default', message.a_value) + self.assertEqual(u'a default', message.a_value) message.a_value = u'a new value' - self.assertEquals(u'a new value', message.a_value) + self.assertEqual(u'a new value', message.a_value) message.reset('a_value') - self.assertEquals(u'a default', message.a_value) + self.assertEqual(u'a default', message.a_value) message.repeated = [1, 2, 3] - self.assertEquals([1, 2, 3], message.repeated) + self.assertEqual([1, 2, 3], message.repeated) saved = message.repeated message.reset('repeated') - self.assertEquals([], message.repeated) + self.assertEqual([], message.repeated) self.assertIsInstance(message.repeated, messages.FieldList) - self.assertEquals([1, 2, 3], saved) + self.assertEqual([1, 2, 3], saved) def testAllowNestedEnums(self): """Test allowing nested enums in a message definition.""" @@ -1480,10 +1480,10 @@ class Currency(messages.Enum): INR = 3 # Sorted by name order seems to be the only feasible option. - self.assertEquals(['Currency', 'Duration'], Trade.__enums__) + self.assertEqual(['Currency', 'Duration'], Trade.__enums__) # Message definition will now be set on Enumerated objects. - self.assertEquals(Trade, Trade.Duration.message_definition()) + self.assertEqual(Trade, Trade.Duration.message_definition()) def testAllowNestedMessages(self): """Test allowing nested messages in a message definition.""" @@ -1496,9 +1496,9 @@ class Agent(messages.Message): pass # Sorted by name order seems to be the only feasible option. - self.assertEquals(['Agent', 'Lot'], Trade.__messages__) - self.assertEquals(Trade, Trade.Agent.message_definition()) - self.assertEquals(Trade, Trade.Lot.message_definition()) + self.assertEqual(['Agent', 'Lot'], Trade.__messages__) + self.assertEqual(Trade, Trade.Agent.message_definition()) + self.assertEqual(Trade, Trade.Lot.message_definition()) # But not Message itself. def action(): @@ -1535,42 +1535,42 @@ class MyMessage(messages.Message): message1 = MyMessage() - self.assertNotEquals('hi', message1) - self.assertNotEquals(AnotherMessage(), message1) - self.assertEquals(message1, message1) + self.assertNotEqual('hi', message1) + self.assertNotEqual(AnotherMessage(), message1) + self.assertEqual(message1, message1) message2 = MyMessage() - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) message1.field1 = 10 - self.assertNotEquals(message1, message2) + self.assertNotEqual(message1, message2) message2.field1 = 20 - self.assertNotEquals(message1, message2) + self.assertNotEqual(message1, message2) message2.field1 = 10 - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) message1.field2 = MyEnum.val1 - self.assertNotEquals(message1, message2) + self.assertNotEqual(message1, message2) message2.field2 = MyEnum.val2 - self.assertNotEquals(message1, message2) + self.assertNotEqual(message1, message2) message2.field2 = MyEnum.val1 - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) message1.field3 = AnotherMessage() message1.field3.string = 'value1' - self.assertNotEquals(message1, message2) + self.assertNotEqual(message1, message2) message2.field3 = AnotherMessage() message2.field3.string = 'value2' - self.assertNotEquals(message1, message2) + self.assertNotEqual(message1, message2) message2.field3.string = 'value1' - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) def testEqualityWithUnknowns(self): """Test message class equality with unknown fields.""" @@ -1580,16 +1580,16 @@ class MyMessage(messages.Message): message1 = MyMessage() message2 = MyMessage() - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) message1.set_unrecognized_field('unknown1', 'value1', messages.Variant.STRING) - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) message1.set_unrecognized_field('unknown2', ['asdf', 3], messages.Variant.STRING) message1.set_unrecognized_field('unknown3', 4.7, messages.Variant.DOUBLE) - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) def testUnrecognizedFieldInvalidVariant(self): class MyMessage(messages.Message): @@ -1672,15 +1672,15 @@ class MyMessage(messages.Message): pass module_name = test_util.get_module_name(FieldTest) - self.assertEquals('%s.MyMessage' % module_name, + self.assertEqual('%s.MyMessage' % module_name, MyMessage.definition_name()) - self.assertEquals(module_name, MyMessage.outer_definition_name()) - self.assertEquals(module_name, MyMessage.definition_package()) + self.assertEqual(module_name, MyMessage.outer_definition_name()) + self.assertEqual(module_name, MyMessage.definition_package()) - self.assertEquals(six.text_type, type(MyMessage.definition_name())) - self.assertEquals(six.text_type, type( + self.assertEqual(six.text_type, type(MyMessage.definition_name())) + self.assertEqual(six.text_type, type( MyMessage.outer_definition_name())) - self.assertEquals(six.text_type, type(MyMessage.definition_package())) + self.assertEqual(six.text_type, type(MyMessage.definition_package())) def testDefinitionName_OverrideModule(self): """Test message module is overriden by module package name.""" @@ -1691,15 +1691,15 @@ class MyMessage(messages.Message): package = 'my.package' try: - self.assertEquals('my.package.MyMessage', + self.assertEqual('my.package.MyMessage', MyMessage.definition_name()) - self.assertEquals('my.package', MyMessage.outer_definition_name()) - self.assertEquals('my.package', MyMessage.definition_package()) + self.assertEqual('my.package', MyMessage.outer_definition_name()) + self.assertEqual('my.package', MyMessage.definition_package()) - self.assertEquals(six.text_type, type(MyMessage.definition_name())) - self.assertEquals(six.text_type, type( + self.assertEqual(six.text_type, type(MyMessage.definition_name())) + self.assertEqual(six.text_type, type( MyMessage.outer_definition_name())) - self.assertEquals(six.text_type, type( + self.assertEqual(six.text_type, type( MyMessage.definition_package())) finally: del package @@ -1713,11 +1713,11 @@ class MyMessage(messages.Message): sys.modules = dict(sys.modules) try: del sys.modules[__name__] - self.assertEquals('MyMessage', MyMessage.definition_name()) - self.assertEquals(None, MyMessage.outer_definition_name()) - self.assertEquals(None, MyMessage.definition_package()) + self.assertEqual('MyMessage', MyMessage.definition_name()) + self.assertEqual(None, MyMessage.outer_definition_name()) + self.assertEqual(None, MyMessage.definition_package()) - self.assertEquals(six.text_type, type(MyMessage.definition_name())) + self.assertEqual(six.text_type, type(MyMessage.definition_name())) finally: sys.modules = original_modules @@ -1732,20 +1732,20 @@ class NestedMessage(messages.Message): pass module_name = test_util.get_module_name(MessageTest) - self.assertEquals('%s.MyMessage.NestedMessage' % module_name, + self.assertEqual('%s.MyMessage.NestedMessage' % module_name, MyMessage.NestedMessage.definition_name()) - self.assertEquals('%s.MyMessage' % module_name, + self.assertEqual('%s.MyMessage' % module_name, MyMessage.NestedMessage.outer_definition_name()) - self.assertEquals(module_name, + self.assertEqual(module_name, MyMessage.NestedMessage.definition_package()) - self.assertEquals( + self.assertEqual( '%s.MyMessage.NestedMessage.NestedMessage' % module_name, MyMessage.NestedMessage.NestedMessage.definition_name()) - self.assertEquals( + self.assertEqual( '%s.MyMessage.NestedMessage' % module_name, MyMessage.NestedMessage.NestedMessage.outer_definition_name()) - self.assertEquals( + self.assertEqual( module_name, MyMessage.NestedMessage.NestedMessage.definition_package()) @@ -1756,8 +1756,8 @@ class OuterMessage(messages.Message): class InnerMessage(messages.Message): pass - self.assertEquals(None, OuterMessage.message_definition()) - self.assertEquals(OuterMessage, + self.assertEqual(None, OuterMessage.message_definition()) + self.assertEqual(OuterMessage, OuterMessage.InnerMessage.message_definition()) def testConstructorKwargs(self): @@ -1769,7 +1769,7 @@ class SomeMessage(messages.Message): expected = SomeMessage() expected.name = 'my name' expected.number = 200 - self.assertEquals(expected, SomeMessage(name='my name', number=200)) + self.assertEqual(expected, SomeMessage(name='my name', number=200)) def testConstructorNotAField(self): """Test kwargs via constructor with wrong names.""" @@ -1788,7 +1788,7 @@ class SomeMessage(messages.Message): repeated = messages.IntegerField(1, repeated=True) instance = SomeMessage() - self.assertEquals([], instance.repeated) + self.assertEqual([], instance.repeated) self.assertTrue(isinstance(instance.repeated, messages.FieldList)) def testCompareAutoInitializedRepeatedFields(self): @@ -1797,7 +1797,7 @@ class SomeMessage(messages.Message): message1 = SomeMessage(repeated=[]) message2 = SomeMessage() - self.assertEquals(message1, message2) + self.assertEqual(message1, message2) def testUnknownValues(self): """Test message class equality with unknown fields.""" @@ -1805,48 +1805,48 @@ class MyMessage(messages.Message): field1 = messages.IntegerField(1) message = MyMessage() - self.assertEquals([], message.all_unrecognized_fields()) - self.assertEquals((None, None), + self.assertEqual([], message.all_unrecognized_fields()) + self.assertEqual((None, None), message.get_unrecognized_field_info('doesntexist')) - self.assertEquals((None, None), + self.assertEqual((None, None), message.get_unrecognized_field_info( 'doesntexist', None, None)) - self.assertEquals(('defaultvalue', 'defaultwire'), + self.assertEqual(('defaultvalue', 'defaultwire'), message.get_unrecognized_field_info( 'doesntexist', 'defaultvalue', 'defaultwire')) - self.assertEquals((3, None), + self.assertEqual((3, None), message.get_unrecognized_field_info( 'doesntexist', value_default=3)) message.set_unrecognized_field('exists', 9.5, messages.Variant.DOUBLE) - self.assertEquals(1, len(message.all_unrecognized_fields())) + self.assertEqual(1, len(message.all_unrecognized_fields())) self.assertTrue('exists' in message.all_unrecognized_fields()) - self.assertEquals((9.5, messages.Variant.DOUBLE), + self.assertEqual((9.5, messages.Variant.DOUBLE), message.get_unrecognized_field_info('exists')) - self.assertEquals((9.5, messages.Variant.DOUBLE), + self.assertEqual((9.5, messages.Variant.DOUBLE), message.get_unrecognized_field_info('exists', 'type', 1234)) - self.assertEquals( + self.assertEqual( (1234, None), message.get_unrecognized_field_info('doesntexist', 1234)) message.set_unrecognized_field( 'another', 'value', messages.Variant.STRING) - self.assertEquals(2, len(message.all_unrecognized_fields())) + self.assertEqual(2, len(message.all_unrecognized_fields())) self.assertTrue('exists' in message.all_unrecognized_fields()) self.assertTrue('another' in message.all_unrecognized_fields()) - self.assertEquals((9.5, messages.Variant.DOUBLE), + self.assertEqual((9.5, messages.Variant.DOUBLE), message.get_unrecognized_field_info('exists')) - self.assertEquals(('value', messages.Variant.STRING), + self.assertEqual(('value', messages.Variant.STRING), message.get_unrecognized_field_info('another')) message.set_unrecognized_field('typetest1', ['list', 0, ('test',)], messages.Variant.STRING) - self.assertEquals((['list', 0, ('test',)], messages.Variant.STRING), + self.assertEqual((['list', 0, ('test',)], messages.Variant.STRING), message.get_unrecognized_field_info('typetest1')) message.set_unrecognized_field( 'typetest2', '', messages.Variant.STRING) - self.assertEquals(('', messages.Variant.STRING), + self.assertEqual(('', messages.Variant.STRING), message.get_unrecognized_field_info('typetest2')) def testPickle(self): @@ -1874,12 +1874,12 @@ class MyMessage(messages.Message): message.set_unrecognized_field('repeated', ['list', 0, ('test',)], messages.Variant.STRING) unpickled = pickle.loads(pickle.dumps(message)) - self.assertEquals(message, unpickled) + self.assertEqual(message, unpickled) self.assertTrue(AnotherMessage.string is unpickled.field3.string.field) self.assertTrue('exists' in message.all_unrecognized_fields()) - self.assertEquals(('value', messages.Variant.STRING), + self.assertEqual(('value', messages.Variant.STRING), message.get_unrecognized_field_info('exists')) - self.assertEquals((['list', 0, ('test',)], messages.Variant.STRING), + self.assertEqual((['list', 0, ('test',)], messages.Variant.STRING), message.get_unrecognized_field_info('repeated')) @@ -2004,10 +2004,10 @@ def testNotADefinition(self): def testGlobalFind(self): """Test finding definitions from fully qualified module names.""" A = self.DefineMessage('a.b.c', 'A', {}) - self.assertEquals(A, messages.find_definition('a.b.c.A', + self.assertEqual(A, messages.find_definition('a.b.c.A', importer=self.Importer)) B = self.DefineMessage('a.b.c', 'B', {'C': {}}) - self.assertEquals( + self.assertEqual( B.C, messages.find_definition('a.b.c.B.C', importer=self.Importer)) @@ -2025,33 +2025,33 @@ def testRelativeToModule(self): D = self.DefineMessage('a.b.d', 'D') # Find A, B, C and D relative to a. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'A', a, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'b.B', a, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'b.c.C', a, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'b.d.D', a, importer=self.Importer)) # Find A, B, C and D relative to b. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'A', b, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'B', b, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'c.C', b, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'd.D', b, importer=self.Importer)) # Find A, B, C and D relative to c. Module d is the same case as c. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'A', c, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'B', c, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'C', c, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'd.D', c, importer=self.Importer)) def testRelativeToMessages(self): @@ -2062,43 +2062,43 @@ def testRelativeToMessages(self): D = A.B.D # Find relative to A. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'A', A, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'B', A, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'B.C', A, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'B.D', A, importer=self.Importer)) # Find relative to B. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'A', B, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'B', B, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'C', B, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'D', B, importer=self.Importer)) # Find relative to C. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'A', C, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'B', C, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'C', C, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'D', C, importer=self.Importer)) # Find relative to C searching from c. - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'b.A', C, importer=self.Importer)) - self.assertEquals(B, messages.find_definition( + self.assertEqual(B, messages.find_definition( 'b.A.B', C, importer=self.Importer)) - self.assertEquals(C, messages.find_definition( + self.assertEqual(C, messages.find_definition( 'b.A.B.C', C, importer=self.Importer)) - self.assertEquals(D, messages.find_definition( + self.assertEqual(D, messages.find_definition( 'b.A.B.D', C, importer=self.Importer)) def testAbsoluteReference(self): @@ -2112,13 +2112,13 @@ def testAbsoluteReference(self): aaA = self.DefineMessage('a.a', 'A') # Always find a.A. - self.assertEquals(aA, messages.find_definition('.a.A', None, + self.assertEqual(aA, messages.find_definition('.a.A', None, importer=self.Importer)) - self.assertEquals(aA, messages.find_definition('.a.A', a, + self.assertEqual(aA, messages.find_definition('.a.A', a, importer=self.Importer)) - self.assertEquals(aA, messages.find_definition('.a.A', aA, + self.assertEqual(aA, messages.find_definition('.a.A', aA, importer=self.Importer)) - self.assertEquals(aA, messages.find_definition('.a.A', aaA, + self.assertEqual(aA, messages.find_definition('.a.A', aaA, importer=self.Importer)) def testFindEnum(self): @@ -2127,7 +2127,7 @@ class Color(messages.Enum): pass A = self.DefineMessage('a', 'A', {'Color': Color}) - self.assertEquals( + self.assertEqual( Color, messages.find_definition('Color', A, importer=self.Importer)) @@ -2150,7 +2150,7 @@ def testSearchAttributeFirst(self): A = self.DefineMessage('a', 'A') module_A = self.DefineModule('a.A') - self.assertEquals(A, messages.find_definition( + self.assertEqual(A, messages.find_definition( 'a.A', None, importer=self.Importer)) diff --git a/apitools/base/protorpclite/protojson_test.py b/apitools/base/protorpclite/protojson_test.py index a5fb97a1..07d9d779 100644 --- a/apitools/base/protorpclite/protojson_test.py +++ b/apitools/base/protorpclite/protojson_test.py @@ -85,7 +85,7 @@ class ProtojsonTest(test_util.TestCase, def CompareEncoded(self, expected_encoded, actual_encoded): """JSON encoding will be laundered to remove string differences.""" - self.assertEquals(json.loads(expected_encoded), + self.assertEqual(json.loads(expected_encoded), json.loads(actual_encoded)) encoded_empty_message = '{}' @@ -165,7 +165,7 @@ def testConvertIntegerToFloat(self): message = protojson.decode_message(MyMessage, '{"a_float": 10}') self.assertTrue(isinstance(message.a_float, float)) - self.assertEquals(10.0, message.a_float) + self.assertEqual(10.0, message.a_float) def testConvertStringToNumbers(self): """Test that strings passed to integer fields are converted.""" @@ -176,7 +176,7 @@ def testConvertStringToNumbers(self): "a_repeated_float": ["1.5", "2", 10] }""") - self.assertEquals(MyMessage(an_integer=10, + self.assertEqual(MyMessage(an_integer=10, a_float=3.5, a_repeated=[1, 2], a_repeated_float=[1.5, 2.0, 10.0]), @@ -201,7 +201,7 @@ def testNumericEnumeration(self): expected_message = MyMessage() expected_message.an_enum = MyMessage.Color.GREEN - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) def testNumericEnumerationNegativeTest(self): """Test with an invalid number for the enum value.""" @@ -211,10 +211,10 @@ def testNumericEnumerationNegativeTest(self): expected_message = MyMessage() - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) # The roundtrip should result in equivalent encoded # message. - self.assertEquals('{"an_enum": 89}', protojson.encode_message(message)) + self.assertEqual('{"an_enum": 89}', protojson.encode_message(message)) def testAlphaEnumeration(self): """Test that alpha enum values work.""" @@ -223,7 +223,7 @@ def testAlphaEnumeration(self): expected_message = MyMessage() expected_message.an_enum = MyMessage.Color.RED - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) def testAlphaEnumerationNegativeTest(self): """The alpha enum value is invalid.""" @@ -233,9 +233,9 @@ def testAlphaEnumerationNegativeTest(self): expected_message = MyMessage() - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) # The roundtrip should result in equivalent encoded message. - self.assertEquals('{"an_enum": "IAMINVALID"}', + self.assertEqual('{"an_enum": "IAMINVALID"}', protojson.encode_message(message)) def testEnumerationNegativeTestWithEmptyString(self): @@ -245,13 +245,13 @@ def testEnumerationNegativeTestWithEmptyString(self): expected_message = MyMessage() - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) # The roundtrip should result in equivalent encoded message. - self.assertEquals('{"an_enum": ""}', protojson.encode_message(message)) + self.assertEqual('{"an_enum": ""}', protojson.encode_message(message)) def testNullValues(self): """Test that null values overwrite existing values.""" - self.assertEquals(MyMessage(), + self.assertEqual(MyMessage(), protojson.decode_message(MyMessage, ('{"an_integer": null,' ' "a_nested": null,' @@ -260,7 +260,7 @@ def testNullValues(self): def testEmptyList(self): """Test that empty lists are ignored.""" - self.assertEquals(MyMessage(), + self.assertEqual(MyMessage(), protojson.decode_message(MyMessage, '{"a_repeated": []}')) @@ -291,20 +291,20 @@ def check_initialized(self): def testMergeEmptyString(self): """Test merging the empty or space only string.""" message = protojson.decode_message(test_util.OptionalMessage, '') - self.assertEquals(test_util.OptionalMessage(), message) + self.assertEqual(test_util.OptionalMessage(), message) message = protojson.decode_message(test_util.OptionalMessage, ' ') - self.assertEquals(test_util.OptionalMessage(), message) + self.assertEqual(test_util.OptionalMessage(), message) def testProtojsonUnrecognizedFieldName(self): """Test that unrecognized fields are saved and can be accessed.""" decoded = protojson.decode_message( MyMessage, ('{"an_integer": 1, "unknown_val": 2}')) - self.assertEquals(decoded.an_integer, 1) - self.assertEquals(1, len(decoded.all_unrecognized_fields())) - self.assertEquals('unknown_val', decoded.all_unrecognized_fields()[0]) - self.assertEquals((2, messages.Variant.INT64), + self.assertEqual(decoded.an_integer, 1) + self.assertEqual(1, len(decoded.all_unrecognized_fields())) + self.assertEqual('unknown_val', decoded.all_unrecognized_fields()[0]) + self.assertEqual((2, messages.Variant.INT64), decoded.get_unrecognized_field_info('unknown_val')) def testProtojsonUnrecognizedFieldNumber(self): @@ -313,17 +313,17 @@ def testProtojsonUnrecognizedFieldNumber(self): MyMessage, '{"an_integer": 1, "1001": "unknown", "-123": "negative", ' '"456_mixed": 2}') - self.assertEquals(decoded.an_integer, 1) - self.assertEquals(3, len(decoded.all_unrecognized_fields())) + self.assertEqual(decoded.an_integer, 1) + self.assertEqual(3, len(decoded.all_unrecognized_fields())) self.assertFalse(1001 in decoded.all_unrecognized_fields()) self.assertTrue('1001' in decoded.all_unrecognized_fields()) - self.assertEquals(('unknown', messages.Variant.STRING), + self.assertEqual(('unknown', messages.Variant.STRING), decoded.get_unrecognized_field_info('1001')) self.assertTrue('-123' in decoded.all_unrecognized_fields()) - self.assertEquals(('negative', messages.Variant.STRING), + self.assertEqual(('negative', messages.Variant.STRING), decoded.get_unrecognized_field_info('-123')) self.assertTrue('456_mixed' in decoded.all_unrecognized_fields()) - self.assertEquals((2, messages.Variant.INT64), + self.assertEqual((2, messages.Variant.INT64), decoded.get_unrecognized_field_info('456_mixed')) def testProtojsonUnrecognizedNull(self): @@ -331,8 +331,8 @@ def testProtojsonUnrecognizedNull(self): decoded = protojson.decode_message( MyMessage, '{"an_integer": 1, "unrecognized_null": null}') - self.assertEquals(decoded.an_integer, 1) - self.assertEquals(decoded.all_unrecognized_fields(), []) + self.assertEqual(decoded.an_integer, 1) + self.assertEqual(decoded.all_unrecognized_fields(), []) def testUnrecognizedFieldVariants(self): """Test that unrecognized fields are mapped to the right variants.""" @@ -352,13 +352,13 @@ def testUnrecognizedFieldVariants(self): ('{"an_integer": 1, "unknown_val": true}', messages.Variant.BOOL)): decoded = protojson.decode_message(MyMessage, encoded) - self.assertEquals(decoded.an_integer, 1) - self.assertEquals(1, len(decoded.all_unrecognized_fields())) - self.assertEquals( + self.assertEqual(decoded.an_integer, 1) + self.assertEqual(1, len(decoded.all_unrecognized_fields())) + self.assertEqual( 'unknown_val', decoded.all_unrecognized_fields()[0]) _, decoded_variant = decoded.get_unrecognized_field_info( 'unknown_val') - self.assertEquals(expected_variant, decoded_variant) + self.assertEqual(expected_variant, decoded_variant) def testDecodeDateTime(self): for datetime_string, datetime_vals in ( @@ -369,7 +369,7 @@ def testDecodeDateTime(self): expected_message = MyMessage( a_datetime=datetime.datetime(*datetime_vals)) - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) def testDecodeInvalidDateTime(self): self.assertRaises(messages.DecodeError, protojson.decode_message, @@ -409,11 +409,11 @@ def testDecodeRepeatedDateTime(self): datetime.datetime(2010, 1, 21, 9, 52), datetime.datetime(2000, 1, 1, 1, 0, 59, 999999)]) - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) def testDecodeCustom(self): message = protojson.decode_message(MyMessage, '{"a_custom": 1}') - self.assertEquals(MyMessage(a_custom=1), message) + self.assertEqual(MyMessage(a_custom=1), message) def testDecodeInvalidCustom(self): self.assertRaises(messages.ValidationError, protojson.decode_message, @@ -426,17 +426,17 @@ def testEncodeCustom(self): def testDecodeRepeatedCustom(self): message = protojson.decode_message( MyMessage, '{"a_repeated_custom": [1, 2, 3]}') - self.assertEquals(MyMessage(a_repeated_custom=[1, 2, 3]), message) + self.assertEqual(MyMessage(a_repeated_custom=[1, 2, 3]), message) def testDecodeRepeatedEmpty(self): message = protojson.decode_message( MyMessage, '{"a_repeated": []}') - self.assertEquals(MyMessage(a_repeated=[]), message) + self.assertEqual(MyMessage(a_repeated=[]), message) def testDecodeNone(self): message = protojson.decode_message( MyMessage, '{"an_integer": []}') - self.assertEquals(MyMessage(an_integer=None), message) + self.assertEqual(MyMessage(an_integer=None), message) def testDecodeBadBase64BytesField(self): """Test decoding improperly encoded base64 bytes value.""" diff --git a/apitools/base/protorpclite/test_util.py b/apitools/base/protorpclite/test_util.py index 4d45ac99..b6e4f94b 100644 --- a/apitools/base/protorpclite/test_util.py +++ b/apitools/base/protorpclite/test_util.py @@ -453,11 +453,11 @@ def CompareEncoded(self, expected_encoded, actual_encoded): expected_encoded: Expected string encoded value. actual_encoded: Actual string encoded value. """ - self.assertEquals(expected_encoded, actual_encoded) + self.assertEqual(expected_encoded, actual_encoded) def EncodeDecode(self, encoded, expected_message): message = self.PROTOLIB.decode_message(type(expected_message), encoded) - self.assertEquals(expected_message, message) + self.assertEqual(expected_message, message) self.CompareEncoded(encoded, self.PROTOLIB.encode_message(message)) def testEmptyMessage(self): @@ -548,10 +548,10 @@ def testUnexpectedField(self): OptionalMessage, self.unexpected_tag_message) # Message should be equal to an empty message, since unknown # values aren't included in equality. - self.assertEquals(OptionalMessage(), loaded_message) + self.assertEqual(OptionalMessage(), loaded_message) # Verify that the encoded message matches the source, including the # unknown value. - self.assertEquals(self.unexpected_tag_message, + self.assertEqual(self.unexpected_tag_message, self.PROTOLIB.encode_message(loaded_message)) def testDoNotSendDefault(self): @@ -618,7 +618,7 @@ class MyMessage(messages.Message): message = MyMessage(value=value) decoded = self.PROTOLIB.decode_message( MyMessage, self.PROTOLIB.encode_message(message)) - self.assertEquals(decoded.value, value) + self.assertEqual(decoded.value, value) def testDateTimeWithTimeZone(self): """Test DateTimeFields with time zones.""" @@ -631,7 +631,7 @@ class MyMessage(messages.Message): message = MyMessage(value=value) decoded = self.PROTOLIB.decode_message( MyMessage, self.PROTOLIB.encode_message(message)) - self.assertEquals(decoded.value, value) + self.assertEqual(decoded.value, value) def pick_unused_port(): diff --git a/apitools/base/protorpclite/util_test.py b/apitools/base/protorpclite/util_test.py index 5d5d3c83..41adad8d 100644 --- a/apitools/base/protorpclite/util_test.py +++ b/apitools/base/protorpclite/util_test.py @@ -39,8 +39,8 @@ def testDecoratedFunction_LengthZero(self): @util.positional(0) def fn(kwonly=1): return [kwonly] - self.assertEquals([1], fn()) - self.assertEquals([2], fn(kwonly=2)) + self.assertEqual([1], fn()) + self.assertEqual([2], fn(kwonly=2)) self.assertRaisesWithRegexpMatch(TypeError, r'fn\(\) takes at most 0 positional ' r'arguments \(1 given\)', @@ -50,8 +50,8 @@ def testDecoratedFunction_LengthOne(self): @util.positional(1) def fn(pos, kwonly=1): return [pos, kwonly] - self.assertEquals([1, 1], fn(1)) - self.assertEquals([2, 2], fn(2, kwonly=2)) + self.assertEqual([1, 1], fn(1)) + self.assertEqual([2, 2], fn(2, kwonly=2)) self.assertRaisesWithRegexpMatch(TypeError, r'fn\(\) takes at most 1 positional ' r'argument \(2 given\)', @@ -61,9 +61,9 @@ def testDecoratedFunction_LengthTwoWithDefault(self): @util.positional(2) def fn(pos1, pos2=1, kwonly=1): return [pos1, pos2, kwonly] - self.assertEquals([1, 1, 1], fn(1)) - self.assertEquals([2, 2, 1], fn(2, 2)) - self.assertEquals([2, 3, 4], fn(2, 3, kwonly=4)) + self.assertEqual([1, 1, 1], fn(1)) + self.assertEqual([2, 2, 1], fn(2, 2)) + self.assertEqual([2, 3, 4], fn(2, 3, kwonly=4)) self.assertRaisesWithRegexpMatch(TypeError, r'fn\(\) takes at most 2 positional ' r'arguments \(3 given\)', @@ -75,8 +75,8 @@ class MyClass(object): @util.positional(2) def meth(self, pos1, kwonly=1): return [pos1, kwonly] - self.assertEquals([1, 1], MyClass().meth(1)) - self.assertEquals([2, 2], MyClass().meth(2, kwonly=2)) + self.assertEqual([1, 1], MyClass().meth(1)) + self.assertEqual([2, 2], MyClass().meth(2, kwonly=2)) self.assertRaisesWithRegexpMatch( TypeError, r'meth\(\) takes at most 2 positional arguments \(3 given\)', @@ -86,8 +86,8 @@ def testDefaultDecoration(self): @util.positional def fn(a, b, c=None): return a, b, c - self.assertEquals((1, 2, 3), fn(1, 2, c=3)) - self.assertEquals((3, 4, None), fn(3, b=4)) + self.assertEqual((1, 2, 3), fn(1, 2, c=3)) + self.assertEqual((3, 4, None), fn(3, b=4)) self.assertRaisesWithRegexpMatch(TypeError, r'fn\(\) takes at most 2 positional ' r'arguments \(3 given\)', @@ -96,7 +96,7 @@ def fn(a, b, c=None): def testDefaultDecorationNoKwdsFails(self): def fn(a): return a - self.assertRaisesRegexp( + self.assertRaisesRegex( ValueError, ('Functions with no keyword arguments must specify ' 'max_positional_args'), @@ -107,7 +107,7 @@ def testDecoratedFunctionDocstring(self): def fn(kwonly=1): """fn docstring.""" return [kwonly] - self.assertEquals('fn docstring.', fn.__doc__) + self.assertEqual('fn docstring.', fn.__doc__) class GetPackageForModuleTest(test_util.TestCase): @@ -127,7 +127,7 @@ def CreateModule(self, name, file_name=None): return module def assertPackageEquals(self, expected, actual): - self.assertEquals(expected, actual) + self.assertEqual(expected, actual) if actual is not None: self.assertTrue(isinstance(actual, six.text_type)) @@ -185,14 +185,14 @@ def testDecodeDateTime(self): ('2012-09-30T15:31:50', (2012, 9, 30, 15, 31, 50, 0))): decoded = util.decode_datetime(datetime_string) expected = datetime.datetime(*datetime_vals) - self.assertEquals(expected, decoded) + self.assertEqual(expected, decoded) def testDecodeDateTimeWithTruncateTime(self): """Test that nanosec time is truncated with truncate_time flag.""" decoded = util.decode_datetime('2012-09-30T15:31:50.262343123', truncate_time=True) expected = datetime.datetime(2012, 9, 30, 15, 31, 50, 262343) - self.assertEquals(expected, decoded) + self.assertEqual(expected, decoded) def testDateTimeTimeZones(self): """Test that a datetime string with a timezone is decoded correctly.""" @@ -214,7 +214,7 @@ def testDateTimeTimeZones(self): for datetime_string, datetime_vals in tests: decoded = util.decode_datetime(datetime_string) expected = datetime.datetime(*datetime_vals) - self.assertEquals(expected, decoded) + self.assertEqual(expected, decoded) def testDecodeDateTimeInvalid(self): """Test that decoding malformed datetime strings raises execptions.""" @@ -233,7 +233,7 @@ def testDecodeDateTimeInvalid(self): def testTimeZoneOffsetDelta(self): """Test that delta works with TimeZoneOffset.""" time_zone = util.TimeZoneOffset(datetime.timedelta(minutes=3)) - epoch = time_zone.utcoffset(datetime.datetime.utcfromtimestamp(0)) + epoch = time_zone.utcoffset(datetime.datetime.fromtimestamp(0, tz=datetime.timezone.utc).replace(tzinfo=None)) self.assertEqual(180, util.total_seconds(epoch)) diff --git a/apitools/base/py/batch_test.py b/apitools/base/py/batch_test.py index ae8afe68..9f688934 100644 --- a/apitools/base/py/batch_test.py +++ b/apitools/base/py/batch_test.py @@ -206,7 +206,7 @@ def _Callback(response, exception): self.assertEqual({'status': '200'}, response.info) self.assertEqual('content', response.content) self.assertEqual(desired_url, response.request_url) - self.assertEquals(1, len(callback_was_called)) + self.assertEqual(1, len(callback_was_called)) def _MakeResponse(self, number_of_parts): return http_wrapper.Response( diff --git a/apitools/base/py/credentials_lib.py b/apitools/base/py/credentials_lib.py index 0823f934..4ddc5cc2 100644 --- a/apitools/base/py/credentials_lib.py +++ b/apitools/base/py/credentials_lib.py @@ -409,7 +409,7 @@ def _do_refresh_request(self, unused_http_request): expires_in = int(credential_info['expires_in']) self.token_expiry = ( datetime.timedelta(seconds=expires_in) + - datetime.datetime.utcnow()) + datetime.datetime.now(tz=datetime.timezone.utc).replace(tzinfo=None)) else: self.token_expiry = None self.invalid = False diff --git a/apitools/base/py/exceptions_test.py b/apitools/base/py/exceptions_test.py index 6e3a1820..d6d96277 100644 --- a/apitools/base/py/exceptions_test.py +++ b/apitools/base/py/exceptions_test.py @@ -32,19 +32,19 @@ def testBadRequest(self): err = exceptions.HttpError.FromResponse(_MakeResponse(400)) self.assertIsInstance(err, exceptions.HttpError) self.assertIsInstance(err, exceptions.HttpBadRequestError) - self.assertEquals(err.status_code, 400) + self.assertEqual(err.status_code, 400) def testUnauthorized(self): err = exceptions.HttpError.FromResponse(_MakeResponse(401)) self.assertIsInstance(err, exceptions.HttpError) self.assertIsInstance(err, exceptions.HttpUnauthorizedError) - self.assertEquals(err.status_code, 401) + self.assertEqual(err.status_code, 401) def testForbidden(self): err = exceptions.HttpError.FromResponse(_MakeResponse(403)) self.assertIsInstance(err, exceptions.HttpError) self.assertIsInstance(err, exceptions.HttpForbiddenError) - self.assertEquals(err.status_code, 403) + self.assertEqual(err.status_code, 403) def testExceptionMessageIncludesErrorDetails(self): err = exceptions.HttpError.FromResponse(_MakeResponse(403)) @@ -56,18 +56,18 @@ def testNotFound(self): err = exceptions.HttpError.FromResponse(_MakeResponse(404)) self.assertIsInstance(err, exceptions.HttpError) self.assertIsInstance(err, exceptions.HttpNotFoundError) - self.assertEquals(err.status_code, 404) + self.assertEqual(err.status_code, 404) def testConflict(self): err = exceptions.HttpError.FromResponse(_MakeResponse(409)) self.assertIsInstance(err, exceptions.HttpError) self.assertIsInstance(err, exceptions.HttpConflictError) - self.assertEquals(err.status_code, 409) + self.assertEqual(err.status_code, 409) def testUnknownStatus(self): err = exceptions.HttpError.FromResponse(_MakeResponse(499)) self.assertIsInstance(err, exceptions.HttpError) - self.assertEquals(err.status_code, 499) + self.assertEqual(err.status_code, 499) def testMalformedStatus(self): err = exceptions.HttpError.FromResponse(_MakeResponse('BAD')) diff --git a/apitools/base/py/list_pager_test.py b/apitools/base/py/list_pager_test.py index 1ea63680..6cad50e6 100644 --- a/apitools/base/py/list_pager_test.py +++ b/apitools/base/py/list_pager_test.py @@ -292,7 +292,7 @@ def Custom_Getter(message, attribute): client.column, request, get_field_func=Custom_Getter) self._AssertInstanceSequence(results, 1) - self.assertEquals(1, len(custom_getter_called)) + self.assertEqual(1, len(custom_getter_called)) class ListPagerAttributeTest(unittest.TestCase): @@ -338,8 +338,8 @@ def testYieldFromListWithAttributes(self): i = 0 for i, instance in enumerate(results): - self.assertEquals('c{0}'.format(i), instance.fullResourcePath) - self.assertEquals(2, i) + self.assertEqual('c{0}'.format(i), instance.fullResourcePath) + self.assertEqual(2, i) def testYieldFromListWithNoBatchSizeAttribute(self): self.mocked_client.iamPolicies.GetPolicyDetails.Expect( @@ -364,5 +364,5 @@ def testYieldFromListWithNoBatchSizeAttribute(self): i = 0 for i, instance in enumerate(results): - self.assertEquals('c{0}'.format(i), instance.fullResourcePath) - self.assertEquals(1, i) + self.assertEqual('c{0}'.format(i), instance.fullResourcePath) + self.assertEqual(1, i) diff --git a/apitools/base/py/testing/mock_test.py b/apitools/base/py/testing/mock_test.py index 9bd8f052..ffc2cf0c 100644 --- a/apitools/base/py/testing/mock_test.py +++ b/apitools/base/py/testing/mock_test.py @@ -197,12 +197,12 @@ def testClientUnmock(self): def testMockHasMessagesModule(self): with mock.Client(fusiontables.FusiontablesV1) as mock_client: - self.assertEquals(fusiontables_messages, + self.assertEqual(fusiontables_messages, mock_client.MESSAGES_MODULE) def testMockHasUrlProperty(self): with mock.Client(fusiontables.FusiontablesV1) as mock_client: - self.assertEquals(fusiontables.FusiontablesV1.BASE_URL, + self.assertEqual(fusiontables.FusiontablesV1.BASE_URL, mock_client.url) self.assertFalse(hasattr(mock_client, 'url')) @@ -211,7 +211,7 @@ def testMockHasOverrideUrlProperty(self): get_credentials=False) with mock.Client(fusiontables.FusiontablesV1, real_client) as mock_client: - self.assertEquals('http://localhost:8080/', mock_client.url) + self.assertEqual('http://localhost:8080/', mock_client.url) def testMockHasHttpProperty(self): with mock.Client(fusiontables.FusiontablesV1) as mock_client: @@ -224,13 +224,13 @@ def testMockHasOverrideHttpProperty(self): get_credentials=False) with mock.Client(fusiontables.FusiontablesV1, real_client) as mock_client: - self.assertEquals('SomeHttpObject', mock_client.http) + self.assertEqual('SomeHttpObject', mock_client.http) def testMockPreservesServiceMethods(self): services = _GetApiServices(fusiontables.FusiontablesV1) with mock.Client(fusiontables.FusiontablesV1): mocked_services = _GetApiServices(fusiontables.FusiontablesV1) - self.assertEquals(services.keys(), mocked_services.keys()) + self.assertEqual(services.keys(), mocked_services.keys()) for name, service in six.iteritems(services): mocked_service = mocked_services[name] methods = service.GetMethodsList() @@ -238,7 +238,7 @@ def testMockPreservesServiceMethods(self): mocked_method = getattr(mocked_service, method) mocked_method_config = mocked_method.method_config() method_config = getattr(service, method).method_config() - self.assertEquals(method_config, mocked_method_config) + self.assertEqual(method_config, mocked_method_config) class _NestedMessage(messages.Message): diff --git a/apitools/base/py/transfer_test.py b/apitools/base/py/transfer_test.py index 7961b4bf..0f1c4262 100644 --- a/apitools/base/py/transfer_test.py +++ b/apitools/base/py/transfer_test.py @@ -551,7 +551,7 @@ def testRetryRequestChunks(self): upload.StreamInChunks() # Ensure the mock was called the correct number of times. - self.assertEquals(make_request.call_count, len(responses)) + self.assertEqual(make_request.call_count, len(responses)) def testStreamInChunks(self): """Test StreamInChunks.""" @@ -589,7 +589,7 @@ def testStreamInChunks(self): upload.StreamInChunks() # Ensure the mock was called the correct number of times. - self.assertEquals(make_request.call_count, len(responses)) + self.assertEqual(make_request.call_count, len(responses)) @mock.patch.object(transfer.Upload, 'RefreshResumableUploadState', new=mock.Mock()) diff --git a/apitools/base/py/util_test.py b/apitools/base/py/util_test.py index c3a47329..9c8e7db4 100644 --- a/apitools/base/py/util_test.py +++ b/apitools/base/py/util_test.py @@ -53,10 +53,10 @@ class UtilTest(unittest.TestCase): def testExpand(self): method_config_xy = MockedMethodConfig(relative_path='{x}/y/{z}', path_params=['x', 'z']) - self.assertEquals( + self.assertEqual( util.ExpandRelativePath(method_config_xy, {'x': '1', 'z': '2'}), '1/y/2') - self.assertEquals( + self.assertEqual( util.ExpandRelativePath( method_config_xy, {'x': '1', 'z': '2'}, @@ -66,11 +66,11 @@ def testExpand(self): def testReservedExpansion(self): method_config_reserved = MockedMethodConfig(relative_path='{+x}/baz', path_params=['x']) - self.assertEquals('foo/:bar:/baz', util.ExpandRelativePath( + self.assertEqual('foo/:bar:/baz', util.ExpandRelativePath( method_config_reserved, {'x': 'foo/:bar:'})) method_config_no_reserved = MockedMethodConfig(relative_path='{x}/baz', path_params=['x']) - self.assertEquals('foo%2F%3Abar%3A/baz', util.ExpandRelativePath( + self.assertEqual('foo%2F%3Abar%3A/baz', util.ExpandRelativePath( method_config_no_reserved, {'x': 'foo/:bar:'})) def testCalculateWaitForRetry(self): @@ -105,27 +105,27 @@ class Class3(object): instance_of_class1 = Class1() - self.assertEquals( + self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, Class1)) - self.assertEquals( + self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, ((Class1, Class2), Class3))) - self.assertEquals( + self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, (Class1, (Class2, Class3)))) - self.assertEquals( + self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, Class1, 'message')) - self.assertEquals( + self.assertEqual( instance_of_class1, util.Typecheck( instance_of_class1, ((Class1, Class2), Class3), 'message')) - self.assertEquals( + self.assertEqual( instance_of_class1, util.Typecheck( instance_of_class1, (Class1, (Class2, Class3)), 'message')) diff --git a/apitools/gen/gen_client_test.py b/apitools/gen/gen_client_test.py index 683d3743..84a225fb 100644 --- a/apitools/gen/gen_client_test.py +++ b/apitools/gen/gen_client_test.py @@ -34,7 +34,7 @@ def _GetContent(file_path): class ClientGenCliTest(unittest.TestCase): def testHelp_NotEnoughArguments(self): - with self.assertRaisesRegexp(SystemExit, '0'): + with self.assertRaisesRegex(SystemExit, '0'): with test_utils.CaptureOutput() as (_, err): gen_client.main([gen_client.__file__, '-h']) err_output = err.getvalue() diff --git a/samples/dns_sample/gen_dns_client_test.py b/samples/dns_sample/gen_dns_client_test.py index 862ddba5..493c57e8 100644 --- a/samples/dns_sample/gen_dns_client_test.py +++ b/samples/dns_sample/gen_dns_client_test.py @@ -29,18 +29,18 @@ class DnsGenClientSanityTest(unittest.TestCase): def testBaseUrl(self): - self.assertEquals(u'https://www.googleapis.com/dns/v1/', + self.assertEqual(u'https://www.googleapis.com/dns/v1/', dns_v1_client.DnsV1.BASE_URL) def testMessagesModule(self): - self.assertEquals(dns_v1_messages, dns_v1_client.DnsV1.MESSAGES_MODULE) + self.assertEqual(dns_v1_messages, dns_v1_client.DnsV1.MESSAGES_MODULE) def testAttributes(self): inner_classes = set([]) for key, value in dns_v1_client.DnsV1.__dict__.items(): if isinstance(value, six.class_types): inner_classes.add(key) - self.assertEquals(set([ + self.assertEqual(set([ 'ChangesService', 'ProjectsService', 'ManagedZonesService', @@ -57,7 +57,7 @@ def setUp(self): def testFlatPath(self): get_method_config = self.mocked_dns_v1.projects.GetMethodConfig('Get') self.assertIsNone(get_method_config.flat_path) - self.assertEquals('projects/{project}', + self.assertEqual('projects/{project}', get_method_config.relative_path) def testRecordSetList(self): @@ -84,4 +84,4 @@ def testRecordSetList(self): type='green'), limit=100, field='rrsets')) - self.assertEquals([response_record_set], results) + self.assertEqual([response_record_set], results) diff --git a/samples/iam_sample/iam_client_test.py b/samples/iam_sample/iam_client_test.py index 017a2d05..9857f44f 100644 --- a/samples/iam_sample/iam_client_test.py +++ b/samples/iam_sample/iam_client_test.py @@ -28,18 +28,18 @@ class DnsGenClientSanityTest(unittest.TestCase): def testBaseUrl(self): - self.assertEquals(u'https://iam.googleapis.com/', + self.assertEqual(u'https://iam.googleapis.com/', iam_v1_client.IamV1.BASE_URL) def testMessagesModule(self): - self.assertEquals(iam_v1_messages, iam_v1_client.IamV1.MESSAGES_MODULE) + self.assertEqual(iam_v1_messages, iam_v1_client.IamV1.MESSAGES_MODULE) def testAttributes(self): inner_classes = set([]) for key, value in iam_v1_client.IamV1.__dict__.items(): if isinstance(value, six.class_types): inner_classes.add(key) - self.assertEquals(set([ + self.assertEqual(set([ 'IamPoliciesService', 'ProjectsService', 'ProjectsServiceAccountsKeysService', @@ -57,10 +57,10 @@ def setUp(self): def testFlatPath(self): get_method_config = (self.mocked_iam_v1.projects_serviceAccounts_keys .GetMethodConfig('Get')) - self.assertEquals('v1/projects/{projectsId}/serviceAccounts' + self.assertEqual('v1/projects/{projectsId}/serviceAccounts' '/{serviceAccountsId}/keys/{keysId}', get_method_config.flat_path) - self.assertEquals('v1/{+name}', get_method_config.relative_path) + self.assertEqual('v1/{+name}', get_method_config.relative_path) def testServiceAccountsKeysList(self): response_key = iam_v1_messages.ServiceAccountKey( @@ -75,4 +75,4 @@ def testServiceAccountsKeysList(self): iam_v1_messages.IamProjectsServiceAccountsKeysListRequest( name=u'test-service-account.')) - self.assertEquals([response_key], result.keys) + self.assertEqual([response_key], result.keys) diff --git a/samples/uptodate_check_test.py b/samples/uptodate_check_test.py index 6e8c9fb5..c9d5cc69 100644 --- a/samples/uptodate_check_test.py +++ b/samples/uptodate_check_test.py @@ -58,7 +58,7 @@ def _CheckGeneratedFiles(self, api_name, api_version): set([prefix + '_client.py', prefix + '_messages.py', '__init__.py'])) - self.assertEquals(expected_files, set(os.listdir(tmp_dir_path))) + self.assertEqual(expected_files, set(os.listdir(tmp_dir_path))) for expected_file in expected_files: self.AssertDiffEqual( _GetContent(GetSampleClientPath(