Permalink
Browse files

Change test.assertEquals to test.assertEqual

They are identical in Python 2, but assertEquals is deprecated in Python 3
  • Loading branch information...
1 parent d73f576 commit c5688b8003c6436c8247b3480e7728a47183ba4a @daviddrysdale committed Oct 25, 2011
Oops, something went wrong.
@@ -64,50 +64,50 @@ def _checkNumbersValidAndCorrectType(self,
def testFixedLine(self):
fixedLineTypes = set((PhoneNumberType.FIXED_LINE, PhoneNumberType.FIXED_LINE_OR_MOBILE))
self._checkNumbersValidAndCorrectType(PhoneNumberType.FIXED_LINE, fixedLineTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testMobile(self):
mobileTypes = set((PhoneNumberType.MOBILE, PhoneNumberType.FIXED_LINE_OR_MOBILE,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.MOBILE, mobileTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testTollFree(self):
tollFreeTypes = set((PhoneNumberType.TOLL_FREE,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.TOLL_FREE, tollFreeTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testPremiumRate(self):
premiumRateTypes = set((PhoneNumberType.PREMIUM_RATE,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.PREMIUM_RATE, premiumRateTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testVoip(self):
voipTypes = set((PhoneNumberType.VOIP,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.VOIP, voipTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testPager(self):
pagerTypes = set((PhoneNumberType.PAGER,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.PAGER, pagerTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testUan(self):
uanTypes = set((PhoneNumberType.UAN,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.UAN, uanTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testSharedCost(self):
sharedCostTypes = set((PhoneNumberType.SHARED_COST,))
self._checkNumbersValidAndCorrectType(PhoneNumberType.SHARED_COST, sharedCostTypes)
- self.assertEquals(0, len(self.invalid_cases))
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.invalid_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testCanBeInternationallyDialled(self):
for regionCode in phonenumberutil.SUPPORTED_REGIONS:
@@ -126,7 +126,7 @@ def testCanBeInternationallyDialled(self):
if (exampleNumber is not None and
phonenumberutil._can_be_internationally_dialled(exampleNumber)):
self.wrong_type_cases.append(exampleNumber)
- self.assertEquals(0, len(self.wrong_type_cases))
+ self.assertEqual(0, len(self.wrong_type_cases))
def testEveryRegionHasAnExampleNumber(self):
for regionCode in phonenumberutil.SUPPORTED_REGIONS:
@@ -140,7 +140,7 @@ def testBlankMetadata(self):
# Some metadata is blank; check that we cope with this.
# Example: MH (+692)
number = phonenumberutil.parse("+6927654321", "US")
- self.assertEquals("Country Code: 692 National Number: 7654321 Leading Zero: False", str(number))
+ self.assertEqual("Country Code: 692 National Number: 7654321 Leading Zero: False", str(number))
def testFormatNumberForMobile(self):
# Python version extra test. Special cases for CO and BR in
@@ -149,15 +149,15 @@ def testFormatNumberForMobile(self):
brNumberFixed = PhoneNumber(country_code=55, national_number=1123456789L)
brNumberMobile = PhoneNumber(country_code=55, national_number=1161234567L,
preferred_domestic_carrier_code="303")
- self.assertEquals("0312345678",
+ self.assertEqual("0312345678",
phonenumberutil.format_number_for_mobile_dialing(coNumberFixed, "CO", False))
- self.assertEquals("03 1 2345678",
+ self.assertEqual("03 1 2345678",
phonenumberutil.format_number_for_mobile_dialing(coNumberFixed, "CO", True))
- self.assertEquals("",
+ self.assertEqual("",
phonenumberutil.format_number_for_mobile_dialing(brNumberFixed, "BR", False))
- self.assertEquals("",
+ self.assertEqual("",
phonenumberutil.format_number_for_mobile_dialing(brNumberFixed, "BR", True))
- self.assertEquals("03031161234567",
+ self.assertEqual("03031161234567",
phonenumberutil.format_number_for_mobile_dialing(brNumberMobile, "BR", False))
- self.assertEquals("0 303 (11) 6123-4567",
+ self.assertEqual("0 303 (11) 6123-4567",
phonenumberutil.format_number_for_mobile_dialing(brNumberMobile, "BR", True))
@@ -77,72 +77,72 @@ def tearDown(self):
def testGetDescriptionForNumberWithNoDataFile(self):
# No data file containing mappings for US numbers is available in Chinese for the unittests. As
# a result, the country name of United States in simplified Chinese is returned.
- self.assertEquals(u"\u7F8E\u56FD",
+ self.assertEqual(u"\u7F8E\u56FD",
geocoder.description_for_number(US_NUMBER1, _CHINESE, region=_CHINA))
- self.assertEquals("Bahamas",
+ self.assertEqual("Bahamas",
geocoder.description_for_number(BS_NUMBER1, _ENGLISH, region=_USA))
- self.assertEquals("Australia",
+ self.assertEqual("Australia",
geocoder.description_for_number(AU_NUMBER, _ENGLISH, region=_USA))
- self.assertEquals("",
+ self.assertEqual("",
geocoder.description_for_number(NUMBER_WITH_INVALID_COUNTRY_CODE, _ENGLISH, region=_USA))
def testGetDescriptionForNumberWithMissingPrefix(self):
# Test that the name of the country is returned when the number passed in
# is valid but not covered by the geocoding data file.
- self.assertEquals("United States",
+ self.assertEqual("United States",
geocoder.description_for_number(US_NUMBER4, _ENGLISH, region=_USA))
def testGetDescriptionForNumber_en_US(self):
- self.assertEquals("CA",
+ self.assertEqual("CA",
geocoder.description_for_number(US_NUMBER1, _ENGLISH, region=_USA))
- self.assertEquals("Mountain View, CA",
+ self.assertEqual("Mountain View, CA",
geocoder.description_for_number(US_NUMBER2, _ENGLISH, region=_USA))
- self.assertEquals("New York, NY",
+ self.assertEqual("New York, NY",
geocoder.description_for_number(US_NUMBER3, _ENGLISH, region=_USA))
def testGetDescriptionForKoreanNumber(self):
- self.assertEquals("Seoul",
+ self.assertEqual("Seoul",
geocoder.description_for_number(KO_NUMBER1, _ENGLISH))
- self.assertEquals("Incheon",
+ self.assertEqual("Incheon",
geocoder.description_for_number(KO_NUMBER2, _ENGLISH))
- self.assertEquals("Jeju",
+ self.assertEqual("Jeju",
geocoder.description_for_number(KO_NUMBER3, _ENGLISH))
- self.assertEquals(u"\uC11C\uC6B8",
+ self.assertEqual(u"\uC11C\uC6B8",
geocoder.description_for_number(KO_NUMBER1, _KOREAN))
- self.assertEquals(u"\uC778\uCC9C",
+ self.assertEqual(u"\uC778\uCC9C",
geocoder.description_for_number(KO_NUMBER2, _KOREAN))
def testGetDescriptionForFallBack(self):
# No fallback, as the location name for the given phone number is
# available in the requested language.
- self.assertEquals("Kalifornien",
+ self.assertEqual("Kalifornien",
geocoder.description_for_number(US_NUMBER1, _GERMAN))
# German falls back to English.
- self.assertEquals("New York, NY",
+ self.assertEqual("New York, NY",
geocoder.description_for_number(US_NUMBER3, _GERMAN))
# Italian falls back to English.
- self.assertEquals("CA",
+ self.assertEqual("CA",
geocoder.description_for_number(US_NUMBER1, _ITALIAN))
# Korean doesn't fall back to English.
- self.assertEquals(u"\uB300\uD55C\uBBFC\uAD6D",
+ self.assertEqual(u"\uB300\uD55C\uBBFC\uAD6D",
geocoder.description_for_number(KO_NUMBER3, _KOREAN))
def testGetDescriptionForInvalidNumber(self):
- self.assertEquals("", geocoder.description_for_number(KO_INVALID_NUMBER, _ENGLISH))
- self.assertEquals("", geocoder.description_for_number(US_INVALID_NUMBER, _ENGLISH))
+ self.assertEqual("", geocoder.description_for_number(KO_INVALID_NUMBER, _ENGLISH))
+ self.assertEqual("", geocoder.description_for_number(US_INVALID_NUMBER, _ENGLISH))
def testCoverage(self):
# Python version extra tests
invalid_number = PhoneNumber(country_code=210, national_number=123456L)
- self.assertEquals("", geocoder.country_name_for_number(invalid_number, "en"))
+ self.assertEqual("", geocoder.country_name_for_number(invalid_number, "en"))
# Add in some script and region specific fictional names
TEST_GEOCODE_DATA['1650960'] = {'en': u'Mountain View, CA',
"en_GB": u'Mountain View California',
"en_Latn": u'MountainView'}
- self.assertEquals("Mountain View California",
+ self.assertEqual("Mountain View California",
geocoder.description_for_number(US_NUMBER2, _ENGLISH, region="GB"))
- self.assertEquals("MountainView",
+ self.assertEqual("MountainView",
geocoder.description_for_number(US_NUMBER2, _ENGLISH, script="Latn"))
- self.assertEquals("MountainView",
+ self.assertEqual("MountainView",
geocoder.description_for_number(US_NUMBER2, _ENGLISH, script="Latn", region="GB"))
TEST_GEOCODE_DATA['1650960'] = {'en': u'Mountain View, CA'}
@@ -44,12 +44,12 @@ def testValueTypeSemantics(self):
match2 = PhoneNumberMatch(10, "1 800 234 45 67", number)
match3 = PhoneNumberMatch(10, "1 801 234 45 67", number)
- self.assertEquals(match1, match2)
- self.assertEquals(match1.start, match2.start)
- self.assertEquals(match1.end, match2.end)
- self.assertEquals(match1.number, match2.number)
- self.assertEquals(match1.raw_string, match2.raw_string)
- self.assertEquals("1 800 234 45 67", match1.raw_string)
+ self.assertEqual(match1, match2)
+ self.assertEqual(match1.start, match2.start)
+ self.assertEqual(match1.end, match2.end)
+ self.assertEqual(match1.number, match2.number)
+ self.assertEqual(match1.raw_string, match2.raw_string)
+ self.assertEqual("1 800 234 45 67", match1.raw_string)
# Python-specific: check __ne__()
self.assertNotEqual(match1, match3)
self.assertTrue(match1 != match3)
@@ -90,9 +90,9 @@ def testStringConvert(self):
number = PhoneNumber()
match = PhoneNumberMatch(10, "1 800 234 45 67", number)
- self.assertEquals("PhoneNumberMatch [10,25) 1 800 234 45 67", str(match))
+ self.assertEqual("PhoneNumberMatch [10,25) 1 800 234 45 67", str(match))
# Python version extra test
- self.assertEquals("PhoneNumberMatch(start=10, raw_string='1 800 234 45 67', " +
+ self.assertEqual("PhoneNumberMatch(start=10, raw_string='1 800 234 45 67', " +
"numobj=PhoneNumber(country_code=None, national_number=None, extension=None, " +
"italian_leading_zero=False, country_code_source=None, preferred_domestic_carrier_code=None))", repr(match))
@@ -367,8 +367,8 @@ def testMatchWithSurroundingZipcodes(self):
match = None
self.assertTrue(match is not None,
msg="Did not find a number in '" + zipPreceding + "'; expected " + number)
- self.assertEquals(expectedResult, match.number)
- self.assertEquals(number, match.raw_string)
+ self.assertEqual(expectedResult, match.number)
+ self.assertEqual(number, match.raw_string)
# Now repeat, but this time the phone number has spaces in it. It should still be found.
number = "(415) 666 7777"
@@ -381,8 +381,8 @@ def testMatchWithSurroundingZipcodes(self):
matchWithSpaces = None
self.assertTrue(matchWithSpaces is not None,
msg="Did not find a number in '" + zipFollowing + "'; expected " + number)
- self.assertEquals(expectedResult, matchWithSpaces.number)
- self.assertEquals(number, matchWithSpaces.raw_string)
+ self.assertEqual(expectedResult, matchWithSpaces.number)
+ self.assertEqual(number, matchWithSpaces.raw_string)
def testIsLatinLetter(self):
self.assertTrue(PhoneNumberMatcher._is_latin_letter('c'))
@@ -483,8 +483,8 @@ def testMatchesMultiplePhoneNumbersSeparatedByPhoneNumberPunctuation(self):
match2 = PhoneNumberMatch(21, "455-234-3451", number2)
matches = PhoneNumberMatcher(text, region)
- self.assertEquals(match1, matches.next())
- self.assertEquals(match2, matches.next())
+ self.assertEqual(match1, matches.next())
+ self.assertEqual(match2, matches.next())
def testDoesNotMatchMultiplePhoneNumbersSeparatedWithNoWhiteSpace(self):
# No white-space found between numbers - neither is found.
@@ -524,8 +524,8 @@ def _doTestNumberMatchesForLeniency(self, testCases, leniency):
if test.rawString != match.raw_string:
wrongMatchFoundCount += 1
print >> sys.stderr, "Found wrong match in test %s. Found %s" % (test, match)
- self.assertEquals(0, noMatchFoundCount)
- self.assertEquals(0, wrongMatchFoundCount)
+ self.assertEqual(0, noMatchFoundCount)
+ self.assertEqual(0, wrongMatchFoundCount)
def _doTestNumberNonMatchesForLeniency(self, testCases, leniency):
matchFoundCount = 0
@@ -538,7 +538,7 @@ def _doTestNumberNonMatchesForLeniency(self, testCases, leniency):
if match is not None:
matchFoundCount += 1
print >> sys.stderr, "Match found in %s for leniency: " % (test, leniency)
- self.assertEquals(0, matchFoundCount)
+ self.assertEqual(0, matchFoundCount)
def findMatchesInContexts(self, contexts, isValid, isPossible,
region="US", number="415-666-7777"):
@@ -608,8 +608,8 @@ def testSequences(self):
matcher = PhoneNumberMatcher(text, region, Leniency.POSSIBLE, sys.maxint)
- self.assertEquals(match1, matcher.next())
- self.assertEquals(match2, matcher.next())
+ self.assertEqual(match1, matcher.next())
+ self.assertEqual(match2, matcher.next())
self.assertFalse(matcher.has_next())
def testNoneInput(self):
@@ -627,7 +627,7 @@ def testMaxMatches(self):
matcher = PhoneNumberMatcher(numbers, "US", Leniency.VALID, 10)
actual = [x.number for x in matcher]
- self.assertEquals(expected, actual)
+ self.assertEqual(expected, actual)
def testMaxMatchesInvalid(self):
# Set up text with 10 invalid phone numbers followed by 100 valid.
@@ -647,7 +647,7 @@ def testMaxMatchesMixed(self):
matcher = PhoneNumberMatcher(numbers, "US", Leniency.VALID, 10)
actual = [x.number for x in matcher]
- self.assertEquals(expected, actual)
+ self.assertEqual(expected, actual)
def testEmptyIteration(self):
matcher = PhoneNumberMatcher("", "ZZ")
@@ -728,9 +728,9 @@ def assertEqualRange(self, text, index, start, end):
self.assertTrue(matcher.has_next())
match = matcher.next()
- self.assertEquals(start - index, match.start)
- self.assertEquals(end - index, match.end)
- self.assertEquals(sub[match.start:match.end], match.raw_string)
+ self.assertEqual(start - index, match.start)
+ self.assertEqual(end - index, match.end)
+ self.assertEqual(sub[match.start:match.end], match.raw_string)
def doTestFindInContext(self, number, defaultCountry):
"""Tests numbers found by PhoneNumberMatcher in various textual contexts"""
@@ -803,12 +803,12 @@ def doTestInContext(self, number, defaultCountry, contextPairs, leniency):
msg="Did not find a number in '" + text + "'; expected '" + number + "'")
extracted = text[match.start:match.end]
- self.assertEquals(start, match.start,
+ self.assertEqual(start, match.start,
msg="Unexpected phone region in '" + text + "'; extracted '" + extracted + "'")
- self.assertEquals(end, match.end,
+ self.assertEqual(end, match.end,
msg="Unexpected phone region in '" + text + "'; extracted '" + extracted + "'")
- self.assertEquals(number, extracted)
- self.assertEquals(match.raw_string, extracted)
+ self.assertEqual(number, extracted)
+ self.assertEqual(match.raw_string, extracted)
self.ensureTermination(text, defaultCountry, leniency)
@@ -35,7 +35,7 @@ def test_equal_simple_number(self):
numberA.country_code = 1
numberA.national_number = 6502530000L
numberB = PhoneNumber(country_code=1, national_number=6502530000L)
- self.assertEquals(numberA, numberB)
+ self.assertEqual(numberA, numberB)
def test_equal_with_italian_leading_zero_set_to_default(self):
numberA = PhoneNumber()
@@ -47,7 +47,7 @@ def test_equal_with_italian_leading_zero_set_to_default(self):
numberB.national_number = 6502530000L
# These should still be equal, since the default value for this field
# is false.
- self.assertEquals(numberA, numberB)
+ self.assertEqual(numberA, numberB)
def test_equal_with_country_code_source_set(self):
numberA = PhoneNumber()
@@ -56,7 +56,7 @@ def test_equal_with_country_code_source_set(self):
numberB = PhoneNumber()
numberB.raw_input = "+1 650 253 00 00"
numberB.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
- self.assertEquals(numberA, numberB)
+ self.assertEqual(numberA, numberB)
def test_non_equal_with_italian_leading_zero_set(self):
numberA = PhoneNumber()
@@ -105,7 +105,7 @@ def test_equal_with_preferred_dcc_set(self):
numberB.country_code = 1
numberB.national_number = 6502530000L
numberB.preferred_domestic_carrier_code = ""
- self.assertEquals(numberA, numberB)
+ self.assertEqual(numberA, numberB)
def test_equal_other_objects(self):
# Python-specific extra tests for equality against other types
Oops, something went wrong.

0 comments on commit c5688b8

Please sign in to comment.