示例#1
0
    def test_format(self):
        """Test method :meth:`plugins.phonenumber.PhoneNumber.format`

        **Tested:**

        - The returned phone number format is correct.
        """
        nr = phonenumber.PhoneNumber('(123) 456.7890')
        self.assertEqual(nr.format(), '(xxx) xxx.xxxx')
示例#2
0
    def test_raw(self):
        """Test method :meth:`plugins.phonenumber.PhoneNumber.raw`

        **Tested:**

        - The returned raw phone number is correct.
        """
        nr = phonenumber.PhoneNumber('1-800-VERIZON')
        self.assertEqual(nr.raw(), '1-800-8374966')
示例#3
0
    def test___init__(self):
        """Test method :meth:`plugins.phonenumber.PhoneNumber.__init__`

        **Tested:**

        - The attributes of a phone number are correct after initialization.
        """
        nr = phonenumber.PhoneNumber('123-456-7890')
        self.assertEqual(nr.entered, '123-456-7890')
        self.assertEqual(nr.country, 'US')
示例#4
0
    def test_transform_to_format(self):
        """Test method :meth:`plugins.phonenumber.PhoneNumber.transform_to_format`

        **Tested:**

        - The returned transformed phone number is correct.
        - A ValueError is raised when there is a mismatch between the length of the phone
          number and the length of the desired format.
        """
        nr = phonenumber.PhoneNumber('1-800-VERIZON')
        self.assertEqual(nr.transform_to_format('x-xxx-xxx-xxxx'), '1-800-837-4966')
        with self.assertRaises(ValueError):
            nr.transform_to_format('x-xxx-xxx-xxx')
示例#5
0
def run():
    """Execute the challenges.010e module."""
    numbers = [
        '1234567890',
        '123-456-7890',
        '123.456.7890',
        '(123)456-7890',
        '(123) 456-7890',
        '456-7890',
        '123-45-6789',
        '123:4567890',
        '123/456-7980',
    ]
    validation = [pn.PhoneNumber(nr).is_valid() for nr in numbers]
    validity = {True: 'valid', False: 'invalid'}
    for nr, valid in zip(numbers, validation):
        print("The phone number '{}' is {}.".format(nr, validity[valid]))
示例#6
0
    def test_is_valid(self):
        """Test method :meth:`plugins.phonenumber.PhoneNumber.is_valid`

        **Tested:**

        - The returned boolean correctly indicates a phone number's validity.
        """
        numbers = [
            '1234567890',
            '123-456-7890',
            '123.456.7890',
            '(123)456-7890',
            '(123) 456-7890',
            '456-7890',
            '123-45-6789',
            '123:4567890',
            '123/456-7980',
        ]
        result = [phonenumber.PhoneNumber(nr).is_valid() for nr in numbers]
        expected = [True]*6 + [False]*3
        self.assertEqual(result, expected)
示例#7
0
def run():
    """Execute the challenges.018e module."""
    nr = pn.PhoneNumber(utils.get_input("Input: "))
    print("Output: " + nr.transform_to_format('x-xxx-xxx-xxxx'))