Example #1
0
 def testInternals(self):
     # Python-specific test: coverage of internals
     from phonenumbers.phonenumbermatcher import _limit, _verify, _is_national_prefix_present_if_required, _get_national_number_groups
     from phonenumbers import CountryCodeSource
     self.assertEqual("{1,2}", _limit(1, 2))
     self.assertRaises(Exception, _limit, *(-1, 2))
     self.assertRaises(Exception, _limit, *(1, 0))
     self.assertRaises(Exception, _limit, *(2, 1))
     number = PhoneNumber(country_code=44, national_number=7912345678L)
     self.assertRaises(Exception, _verify, *(99, number, "12345678"))
     self.assertRaises(ValueError, PhoneNumberMatcher, *("text", "US"),
                       **{"leniency": None})
     self.assertRaises(ValueError, PhoneNumberMatcher, *("text", "US"),
                       **{"max_tries": -2})
     # Invalid country looks like national prefix is present (no way to tell)
     number2 = PhoneNumber(
         country_code=99,
         national_number=12345678L,
         country_code_source=CountryCodeSource.FROM_DEFAULT_COUNTRY)
     self.assertTrue(_is_national_prefix_present_if_required(number2))
     # National prefix rule has no lead digits
     number3 = PhoneNumber(
         country_code=61,
         national_number=1234567890L,
         country_code_source=CountryCodeSource.FROM_DEFAULT_COUNTRY)
     self.assertTrue(_is_national_prefix_present_if_required(number3))
     # Coverage for _get_national_number_groups() with a formatting pattern provided
     us_number = PhoneNumber(country_code=1, national_number=6502530000L)
     num_format = NumberFormat(pattern="(\\d{3})(\\d{3})(\\d{4})",
                               format="\\1-\\2-\\3")
     self.assertEqual(["650", "253", "0000"],
                      _get_national_number_groups(us_number, num_format))
 def testInternals(self):
     # Python-specific test: coverage of internals
     from phonenumbers.phonenumbermatcher import _limit, _verify, _is_national_prefix_present_if_required, _get_national_number_groups
     from phonenumbers import CountryCodeSource
     self.assertEqual("{1,2}", _limit(1, 2))
     self.assertRaises(Exception, _limit, *(-1, 2))
     self.assertRaises(Exception, _limit, *(1, 0))
     self.assertRaises(Exception, _limit, *(2, 1))
     number = PhoneNumber(country_code=44, national_number=7912345678)
     self.assertRaises(Exception, _verify, *(99, number, "12345678"))
     self.assertRaises(ValueError, PhoneNumberMatcher, *("text", "US"), **{"leniency": None})
     self.assertRaises(ValueError, PhoneNumberMatcher, *("text", "US"), **{"max_tries": -2})
     # Invalid country looks like national prefix is present (no way to tell)
     number2 = PhoneNumber(country_code=99, national_number=12345678, country_code_source=CountryCodeSource.FROM_DEFAULT_COUNTRY)
     self.assertTrue(_is_national_prefix_present_if_required(number2))
     # National prefix rule has no lead digits
     number3 = PhoneNumber(country_code=61, national_number=1234567890, country_code_source=CountryCodeSource.FROM_DEFAULT_COUNTRY)
     self.assertTrue(_is_national_prefix_present_if_required(number3))
     # Coverage for _get_national_number_groups() with a formatting pattern provided
     us_number = PhoneNumber(country_code=1, national_number=6502530000)
     num_format = NumberFormat(pattern="(\\d{3})(\\d{3})(\\d{4})", format="\\1-\\2-\\3")
     self.assertEqual(["650", "253", "0000"],
                      _get_national_number_groups(us_number, num_format))