def testIllegalArguments(self): """Tests the value type semantics for matches with a None number.""" try: PhoneNumberMatch(-110, "1 800 234 45 67", PhoneNumber()) self.fail("Expected failed constructor") except Exception: pass try: PhoneNumberMatch(10, "1 800 234 45 67", None) self.fail("Expected failed constructor") except Exception: pass try: PhoneNumberMatch(10, None, PhoneNumber()) self.fail("Expected failed constructor") except Exception: pass try: PhoneNumberMatch(10, None, None) self.fail("Expected failed constructor") except Exception: pass
def testValueTypeSemantics(self): number = PhoneNumber() match1 = PhoneNumberMatch(10, "1 800 234 45 67", number) match2 = PhoneNumberMatch(10, "1 800 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)
def testMatchesMultiplePhoneNumbersSeparatedByPhoneNumberPunctuation(self): text = "Call 650-253-4561 -- 455-234-3451" region = "US" number1 = PhoneNumber(country_code=phonenumberutil.country_code_for_region(region), national_number=6502534561) match1 = PhoneNumberMatch(5, "650-253-4561", number1) number2 = PhoneNumber(country_code=phonenumberutil.country_code_for_region(region), national_number=4552343451) match2 = PhoneNumberMatch(21, "455-234-3451", number2) matches = PhoneNumberMatcher(text, region) self.assertEqual(match1, matches.next()) self.assertEqual(match2, matches.next())
def testStringConvert(self): """Check string conversion""" number = PhoneNumber() match = PhoneNumberMatch(10, "1 800 234 45 67", number) self.assertEquals("PhoneNumberMatch [10,25) 1 800 234 45 67", str(match))
def testStringConvert(self): """Check string conversion""" number = PhoneNumber() match = PhoneNumberMatch(10, "1 800 234 45 67", number) self.assertEqual("PhoneNumberMatch [10,25) 1 800 234 45 67", str(match)) # Python version extra test 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))
def testValueTypeSemantics(self): number = PhoneNumber() match1 = PhoneNumberMatch(10, "1 800 234 45 67", number) match2 = PhoneNumberMatch(10, "1 800 234 45 67", number) match3 = PhoneNumberMatch(10, "1 801 234 45 67", number) 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) # Python-specific: Check only comparisons of the same type work self.assertNotEqual(match1, None) self.assertNotEqual(match1, "") self.assertNotEqual(match1, "1 800 234 45 67") self.assertNotEqual(match1, 0)
def testSequences(self): # Test multiple occurrences. text = "Call 033316005 or 032316005!" region = "NZ" number1 = PhoneNumber() number1.country_code = phonenumberutil.country_code_for_region(region) number1.national_number = 33316005 match1 = PhoneNumberMatch(5, "033316005", number1) number2 = PhoneNumber() number2.country_code = phonenumberutil.country_code_for_region(region) number2.national_number = 32316005 match2 = PhoneNumberMatch(19, "032316005", number2) matcher = PhoneNumberMatcher(text, region, Leniency.POSSIBLE, 65535) self.assertEqual(match1, matcher.next()) self.assertEqual(match2, matcher.next()) self.assertFalse(matcher.has_next())