34 lines
956 B
Python
34 lines
956 B
Python
|
import unittest
|
||
|
from s2_a4_a import normalize_number
|
||
|
|
||
|
|
||
|
class TestPhoneNumber(unittest.TestCase):
|
||
|
test_correct_numbers = [
|
||
|
"+1 223-456-7890",
|
||
|
"1-223-456-7890",
|
||
|
"+1 223 456-7890",
|
||
|
"(223) 456-7890",
|
||
|
"1 223 456 7890",
|
||
|
"223.456.7890",
|
||
|
"1-989-111-2222"
|
||
|
]
|
||
|
|
||
|
test_wrong_numbers = [
|
||
|
"+1 123-234-3333",
|
||
|
"1 222-333-1111",
|
||
|
"222-333-9999",
|
||
|
"22-333-4444"
|
||
|
]
|
||
|
|
||
|
def test_given_numbers_correct(self):
|
||
|
for numbers in self.test_correct_numbers[:-1]:
|
||
|
self.assertEqual("1-223-456-7890", normalize_number(numbers))
|
||
|
self.assertEqual("1-989-111-2222", normalize_number("1-989-111-2222"))
|
||
|
|
||
|
def test_number_exception(self):
|
||
|
for numbers in self.test_wrong_numbers:
|
||
|
with self.assertRaises(ValueError) as context:
|
||
|
normalize_number(numbers)
|
||
|
|
||
|
self.assertTrue('This is broken' in context.exception)
|