Dateien hochladen nach „SL2“
parent
0e3a09ba8d
commit
e0fa295a64
|
@ -0,0 +1,11 @@
|
|||
import re
|
||||
|
||||
def normalize(number):
|
||||
phone_regex = re.compile(r'\+?1?.?.?([2-9]\d{2}).?.?(\d{3}).?([2-9][0-8]\d{2}$)')
|
||||
|
||||
tmp = phone_regex.match(number)
|
||||
if(tmp):
|
||||
return '1' + '-' + tmp.group(1) + '-' + tmp.group(2) + '-' + tmp.group(3)
|
||||
else: raise ValueError('Ungültige Telefonnummer')
|
||||
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
import unittest
|
||||
import s2_a4_a
|
||||
test_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"]
|
||||
class TestPhoneNumber(unittest.TestCase):
|
||||
|
||||
|
||||
def test_phoneCorrect1(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[0]), "1-223-456-7890")
|
||||
def test_phoneCorrect2(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[1]), "1-223-456-7890")
|
||||
def test_phoneCorrect3(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[2]), "1-223-456-7890")
|
||||
def test_phoneCorrect4(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[3]), "1-223-456-7890")
|
||||
def test_phoneCorrect5(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[4]), "1-223-456-7890")
|
||||
def test_phoneCorrect6(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[5]), "1-223-456-7890")
|
||||
def test_phoneCorrect7(self):
|
||||
self.assertEqual(s2_a4_a.normalize(test_numbers[6]), "1-989-111-2222")
|
||||
def test_failure(self):
|
||||
self.assertRaises(ValueError,s2_a4_a.normalize, "adasd")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue