Skip to content

Commit d237a82

Browse files
committed
Use local metadata copy now it's immutable
1 parent a587316 commit d237a82

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

python/tests/geocodertest.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,19 @@ def testCoverage(self):
175175
self.assertEqual("CA", _prefix_description_for_number(TEST_GEOCODE_DATA, TEST_GEOCODE_LONGEST_PREFIX, US_NUMBER1, "en"))
176176
self.assertEqual("CA", description_for_valid_number(US_NUMBER1, "en"))
177177
self.assertEqual("", description_for_valid_number(US_INVALID_NUMBER, "en"))
178+
179+
# Save off the current (immutable) metadata.
180+
saved_geocode_data = geocoder.GEOCODE_DATA
181+
geocoder.GEOCODE_DATA = {}
182+
for key, value in saved_geocode_data.items():
183+
geocoder.GEOCODE_DATA[key] = value
184+
178185
# Add in some script and region specific fictional names
179-
TEST_GEOCODE_DATA['1650960'] = {'en': u("Mountain View, CA"),
180-
"en_GB": u("Mountain View California"),
181-
"en_US": u("Mountain View, Sunny California"),
182-
"en_Xyzz_US": u("MTV - xyzz"),
183-
"en_Latn": u("MountainView")}
186+
geocoder.GEOCODE_DATA['1650960'] = {'en': u("Mountain View, CA"),
187+
"en_GB": u("Mountain View California"),
188+
"en_US": u("Mountain View, Sunny California"),
189+
"en_Xyzz_US": u("MTV - xyzz"),
190+
"en_Latn": u("MountainView")}
184191
# The following test might one day return "Mountain View California"
185192
self.assertEqual("United States",
186193
description_for_number(US_NUMBER2, _ENGLISH, region="GB"))
@@ -197,11 +204,14 @@ def testCoverage(self):
197204
# Get a different result when there is a script-specific variant
198205
self.assertEqual("MountainView",
199206
description_for_number(US_NUMBER2, _ENGLISH, script="Latn", region="US"))
200-
TEST_GEOCODE_DATA['1650960'] = {'en': u("Mountain View, CA")}
207+
geocoder.GEOCODE_DATA['1650960'] = {'en': u("Mountain View, CA")}
201208

202209
# Test the locale mapping
203-
TEST_GEOCODE_DATA['8868'] = {'zh': u("Chinese"), 'zh_Hant': u("Hant-specific")}
210+
geocoder.GEOCODE_DATA['8868'] = {'zh': u("Chinese"), 'zh_Hant': u("Hant-specific")}
204211
tw_number = FrozenPhoneNumber(country_code=886, national_number=810080123)
205212
self.assertEqual("Hant-specific",
206213
description_for_number(tw_number, "zh", region="TW"))
207-
del TEST_GEOCODE_DATA['8868']
214+
del geocoder.GEOCODE_DATA['8868']
215+
216+
# Restore the original (immutable) test metadata
217+
geocoder.GEOCODE_DATA = saved_geocode_data

0 commit comments

Comments
 (0)