Browse files

Improve test coverage

  • Loading branch information...
1 parent d9bb97c commit a5281c78d013c987fdf2f8099f8657e09412369c @daviddrysdale committed Nov 15, 2013
View
2 python/phonenumbers/shortnumberinfo.py
@@ -217,7 +217,7 @@ def expected_cost(numobj):
elif cost_for_region == ShortNumberCost.TOLL_FREE:
# Do nothing
pass
- else:
+ else: # pragma no cover
raise Exception("Unrecognized cost for region: %s", cost_for_region)
return cost
View
9 python/tests/examplenumberstest.py
@@ -24,6 +24,7 @@
from phonenumbers import PhoneNumberType, PhoneMetadata, NumberParseException
from phonenumbers import phonenumberutil, PhoneNumber, is_emergency_number
from phonenumbers import shortnumberinfo, ShortNumberCost, AsYouTypeFormatter
+from phonenumbers import PhoneNumberMatcher, Leniency
from phonenumbers.util import prnt
from phonenumbers.re_util import fullmatch
@@ -220,6 +221,14 @@ def testIsCarrierSpecific(self):
self.assertFalse(shortnumberinfo.is_carrier_specific(esNumber))
# Extra tests that need access to the real metadata
+ def testIsraelShortNumber(self):
+ # Python version extra test:
+ # Send in a 4-digit Israel phone number
+ matcher = PhoneNumberMatcher("1234", "IL", leniency=Leniency.POSSIBLE)
+ self.assertFalse(matcher.has_next())
+ matcher2 = PhoneNumberMatcher("*1234", "IL", leniency=Leniency.POSSIBLE)
+ self.assertTrue(matcher2.has_next())
+
def testBlankMetadata(self):
# Python version extra test
# Some metadata is blank; check that we cope with this.
View
5 python/tests/geocodertest.py
@@ -124,6 +124,11 @@ def testGetDescriptionForKoreanNumber(self):
def testGetDescriptionForArgentinianMobileNumber(self):
self.assertEqual("La Plata", description_for_number(AR_MOBILE_NUMBER, _ENGLISH))
+ # Python version extra test
+ # Put an invalid number after the mobile token ("9") and lie about
+ # this being a valid number
+ arInvalidMobileNumber = PhoneNumber(country_code=54, national_number=91)
+ self.assertEqual("Argentina", description_for_valid_number(arInvalidMobileNumber, _ENGLISH))
def testGetDescriptionForFallBack(self):
# No fallback, as the location name for the given phone number is
View
1 python/tests/phonenumberutiltest.py
@@ -740,6 +740,7 @@ def testFormatNumberForMobileDialing(self):
self.assertEqual("", phonenumbers.format_number_for_mobile_dialing(auNumber, "NZ", False))
# Python version extra tests
+ self.assertNotEqual(-1, str(auNumber).find("Number of leading zeros"))
number = PhoneNumber()
number.merge_from(XY_NUMBER)
self.assertEqual("", phonenumbers.format_number_for_mobile_dialing(number, "US", False))
View
6 python/tests/shortnumberinfotest.py
@@ -56,8 +56,11 @@ def testIsValidShortNumber(self):
# Python version extra test: check invalid region code
self.assertFalse(is_valid_short_number_for_region("123456", "XY"))
+ self.assertFalse(is_valid_short_number(PhoneNumber(country_code=99, national_number=123)))
# Python version extra test: not matching general desc
self.assertFalse(is_valid_short_number_for_region("2123456", "US"))
+ # Python version extra test: shared country code (44 => GB+GG) but not valid in either
+ self.assertFalse(is_valid_short_number(PhoneNumber(country_code=44, national_number=58001)))
def testGetExpectedCost(self):
premiumRateExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.PREMIUM_RATE)
@@ -92,7 +95,6 @@ def testGetExpectedCost(self):
unknownCostNumber.national_number = 911
self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost(unknownCostNumber))
-
def testGetExpectedCostForSharedCountryCallingCode(self):
# Test some numbers which have different costs in countries sharing
# the same country calling code. In Australia, 1234 is premium-rate,
@@ -275,7 +277,7 @@ def testEmergencyNumberForSharedCountryCallingCode(self):
self.assertTrue(shortnumberinfo.is_valid_short_number(sharedEmergencyNumber))
self.assertEqual(ShortNumberCost.TOLL_FREE,
shortnumberinfo.expected_cost(sharedEmergencyNumber))
-
+
def testOverlappingNANPANumber(self):
# 211 is an emergency number in Barbados, while it is a toll-free
# information line in Canada and the USA.

0 comments on commit a5281c7

Please sign in to comment.