Coverage for src / couchers / phone / check.py: 80%
8 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-05 01:15 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-05 01:15 +0000
1import phonenumbers
4def is_e164_format(phone: str) -> bool:
5 """Return true if string is in E.164 format with leading +, for example "+46701740605" """
6 return len(phone) > 2 and phone[0] == "+" and phone[1:].isdigit() and len(phone) <= 16
9def is_known_operator(phone: str) -> bool:
10 """Return true if phone is in E.164 format with leading +, and has the
11 correct amount of digits considering the country and operator.
12 """
14 if not is_e164_format(phone): 14 ↛ 15line 14 didn't jump to line 15 because the condition on line 14 was never true
15 return False
17 z = phonenumbers.parse(phone)
18 return phonenumbers.is_valid_number(z)