forked from daviddrysdale/python-phonenumbers
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphonenumbertest.py
More file actions
executable file
·122 lines (107 loc) · 4.57 KB
/
Copy pathphonenumbertest.py
File metadata and controls
executable file
·122 lines (107 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
"""Unit tests for phonenumberutil.py"""
# Based on original Java code:
# java/test/com/google/i18n/phonenumbers/PhoneNumberTest.java
# Copyright (C) 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import pathfix
pathfix.fix()
from phonenumbers import PhoneNumber, CountryCodeSource
class PhoneNumberTest(unittest.TestCase):
"""Tests for the Phonenumber.PhoneNumber object itself."""
def setUp(self):
pass
def tearDown(self):
pass
def test_equal_simple_number(self):
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberB = PhoneNumber(country_code=1, national_number=6502530000L)
self.assertEquals(numberA, numberB)
def test_equal_with_italian_leading_zero_set_to_default(self):
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberA.italian_leading_zero = False
numberB = PhoneNumber()
numberB.country_code = 1
numberB.national_number = 6502530000L
# These should still be equal, since the default value for this field
# is false.
self.assertEquals(numberA, numberB)
def test_equal_with_country_code_source_set(self):
numberA = PhoneNumber()
numberA.raw_input = "+1 650 253 00 00"
numberA.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
numberB = PhoneNumber()
numberB.raw_input = "+1 650 253 00 00"
numberB.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
self.assertEquals(numberA, numberB)
def test_non_equal_with_italian_leading_zero_set(self):
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberA.italian_leading_zero = True
numberB = PhoneNumber()
numberB.country_code = 1
numberB.national_number = 6502530000L
self.assertNotEqual(numberA, numberB)
def test_non_equal_with_differing_raw_input(self):
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberA.raw_input = "+1 650 253 00 00"
numberA.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
numberB = PhoneNumber()
# Although these numbers would pass an isNumberMatch test, they are
# not considered "equal" as objects, since their raw input is
# different.
numberB.country_code = 1
numberB.national_number = 6502530000L
numberB.raw_input = "+1-650-253-00-00"
numberB.country_code_source = CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN
self.assertNotEqual(numberA, numberB)
# Python-specific: Force a test of __ne__() method
self.assertTrue(numberA != numberB)
def test_non_equal_with_preferred_dcc_default(self):
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberA.preferred_domestic_carrier_code = ""
numberB = PhoneNumber()
numberB.country_code = 1
numberB.national_number = 6502530000L
self.assertNotEqual(numberA, numberB)
def test_equal_with_preferred_dcc_set(self):
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberA.preferred_domestic_carrier_code = ""
numberB = PhoneNumber()
numberB.country_code = 1
numberB.national_number = 6502530000L
numberB.preferred_domestic_carrier_code = ""
self.assertEquals(numberA, numberB)
def test_equal_other_objects(self):
# Python-specific extra tests for equality against other types
numberA = PhoneNumber()
numberA.country_code = 1
numberA.national_number = 6502530000L
numberA.preferred_domestic_carrier_code = ""
self.assertNotEqual(numberA, None)
self.assertNotEqual(numberA, "")
self.assertNotEqual(numberA, "+16502530000")
self.assertNotEqual(numberA, 6502530000L)