def testWhitespaceInNationalPrefixForParsing(self):
     # Python version extra test
     # AR metadata has whitespace in the RE for nationalPrefixForParsing
     number = phonenumberutil.parse("+540348215617137", "AR")
     self.assertTrue(phonenumberutil.is_valid_number(number))
     self.assertEqual(PhoneNumberType.MOBILE, phonenumberutil.number_type(number))
     number = phonenumberutil.parse("0344615614207", "AR")
     self.assertTrue(phonenumberutil.is_valid_number(number))
     self.assertEqual(PhoneNumberType.MOBILE, phonenumberutil.number_type(number))
 def testWhitespaceInNationalPrefixForParsing(self):
     # Python version extra test
     # AR metadata has whitespace in the RE for nationalPrefixForParsing
     number = phonenumberutil.parse("+540348215617137", "AR")
     self.assertTrue(phonenumberutil.is_valid_number(number))
     self.assertEqual(PhoneNumberType.MOBILE, phonenumberutil.number_type(number))
     number = phonenumberutil.parse("0344615614207", "AR")
     self.assertTrue(phonenumberutil.is_valid_number(number))
     self.assertEqual(PhoneNumberType.MOBILE, phonenumberutil.number_type(number))
 def _checkNumbersValidAndCorrectType(self, exampleNumberRequestedType,
                                      possibleExpectedTypes):
     """
     Arguments:
     exampleNumberRequestedType -- type we are requesting an example number for
     possibleExpectedTypes -- acceptable types that this number should match, such as
           FIXED_LINE and FIXED_LINE_OR_MOBILE for a fixed line example number.
     """
     for regionCode in phonenumberutil.SUPPORTED_REGIONS:
         exampleNumber = phonenumberutil.example_number_for_type(
             regionCode, exampleNumberRequestedType)
         if exampleNumber is not None:
             if not phonenumberutil.is_valid_number(exampleNumber):
                 self.invalid_cases.append(exampleNumber)
                 prnt("Failed validation for %s" % exampleNumber,
                      file=sys.stderr)
             else:
                 # We know the number is valid, now we check the type.
                 exampleNumberType = phonenumberutil.number_type(
                     exampleNumber)
                 if exampleNumberType not in possibleExpectedTypes:
                     self.wrong_type_cases.append(exampleNumber)
                     prnt("Wrong type for %s: got %s" %
                          (exampleNumber, exampleNumberType),
                          file=sys.stderr)
                     prnt("Expected types: ", file=sys.stderr)
                     for phone_type in possibleExpectedTypes:
                         prnt("  %s" % phone_type, file=sys.stderr)
Пример #4
0
 def testGlobalNetworkNumbers(self):
     for callingCode in PhoneMetadata.country_code_metadata.keys():
         exampleNumber = phonenumberutil.example_number_for_non_geo_entity(callingCode)
         self.assertTrue(exampleNumber is not None,
                         msg="No example phone number for calling code %s" % callingCode)
         if not phonenumberutil.is_valid_number(exampleNumber):
             self.invalidCases.append(exampleNumber)
             print >> sys.stderr, "Failed validation for %s" % exampleNumber
 def testGlobalNetworkNumbers(self):
     PhoneMetadata.load_all()
     for callingCode in PhoneMetadata._country_code_metadata.keys():
         exampleNumber = phonenumberutil.example_number_for_non_geo_entity(callingCode)
         self.assertTrue(exampleNumber is not None,
                         msg="No example phone number for calling code %s" % callingCode)
         if not phonenumberutil.is_valid_number(exampleNumber):
             self.invalid_cases.append(exampleNumber)
             prnt("Failed validation for %s" % exampleNumber, file=sys.stderr)
     self.assertEqual(0, len(self.invalid_cases))
 def testGlobalNetworkNumbers(self):
     PhoneMetadata.load_all()
     for callingCode in PhoneMetadata._country_code_metadata.keys():
         exampleNumber = phonenumberutil.example_number_for_non_geo_entity(callingCode)
         self.assertTrue(exampleNumber is not None,
                         msg="No example phone number for calling code %s" % callingCode)
         if not phonenumberutil.is_valid_number(exampleNumber):
             self.invalid_cases.append(exampleNumber)
             prnt("Failed validation for %s" % exampleNumber, file=sys.stderr)
     self.assertEqual(0, len(self.invalid_cases))
Пример #7
0
 def phone_info(self):
     """ Get phone number information.
     """
     try:
         number = parse(self.phone)
         region = pnu.region_code_for_country_code(number.country_code)
         return {
             'number': number,
             'valid': pnu.is_valid_number(number),
             'country': countries.get(alpha2=region),
         }
     except pnu.NumberParseException:
         return {}
 def _checkNumbersValidAndCorrectType(self,
                                      exampleNumberRequestedType,
                                      possibleExpectedTypes):
     """
     Arguments:
     exampleNumberRequestedType -- type we are requesting an example number for
     possibleExpectedTypes -- acceptable types that this number should match, such as
           FIXED_LINE and FIXED_LINE_OR_MOBILE for a fixed line example number.
     """
     for regionCode in phonenumberutil.SUPPORTED_REGIONS:
         exampleNumber = phonenumberutil.example_number_for_type(regionCode, exampleNumberRequestedType)
         if exampleNumber is not None:
             if not phonenumberutil.is_valid_number(exampleNumber):
                 self.invalid_cases.append(exampleNumber)
                 print >> sys.stderr, "Failed validation for %s" % exampleNumber
             else:
                 # We know the number is valid, now we check the type.
                 exampleNumberType = phonenumberutil.number_type(exampleNumber)
                 if exampleNumberType not in possibleExpectedTypes:
                     self.wrong_type_cases.append(exampleNumber)
                     print >> sys.stderr, "Wrong type for %s: got %s" % (exampleNumber, exampleNumberType)
                     print >> sys.stderr, "Expected types: "
                     for phone_type in possibleExpectedTypes:
                         print >> sys.stderr, "  %s" % phone_type
 def doTestFindInContext(self, number, defaultCountry):
     """Tests numbers found by PhoneNumberMatcher in various textual contexts"""
     self.findPossibleInContext(number, defaultCountry)
     parsed = phonenumberutil.parse(number, defaultCountry)
     if phonenumberutil.is_valid_number(parsed):
         self.findValidInContext(number, defaultCountry)
Пример #10
0
 def doTestFindInContext(self, number, defaultCountry):
     """Tests numbers found by PhoneNumberMatcher in various textual contexts"""
     self.findPossibleInContext(number, defaultCountry)
     parsed = phonenumberutil.parse(number, defaultCountry)
     if phonenumberutil.is_valid_number(parsed):
         self.findValidInContext(number, defaultCountry)