summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorErick Wilder <erickwilder@gmail.com>2015-09-09 18:59:13 -0300
committerErick Wilder <erickwilder@gmail.com>2015-09-09 18:59:13 -0300
commit471f8c842e952ba00579f7cf6d9bb5f5800690f8 (patch)
tree21c1a6641e213eeb289eee69c2197d0f2f439199 /tests
parent74ebe2a6b7234629433867648feaec91a6144ced (diff)
parent6acf7ae1c95156d2adb956da77a8ec51b7e064da (diff)
downloadbabel-471f8c842e952ba00579f7cf6d9bb5f5800690f8.tar.gz
Merge pull request #188 from jun66j5/issue174/workaround
Avoid incompatible *.dat files between Python 2 and 3
Diffstat (limited to 'tests')
-rw-r--r--tests/test_core.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
index 7e16765..a4253d8 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -269,3 +269,29 @@ def test_parse_locale():
assert core.parse_locale('en_US.UTF-8') == ('en', 'US', None, None)
assert (core.parse_locale('de_DE.iso885915@euro') ==
('de', 'DE', None, None))
+
+def test_compatible_classes_in_global_and_localedata():
+ # Use pickle module rather than cPickle since cPickle.Unpickler is a method
+ # on Python 2
+ import pickle
+
+ class Unpickler(pickle.Unpickler):
+ def find_class(self, module, name):
+ # *.dat files must have compatible classes between Python 2 and 3
+ if module.split('.')[0] == 'babel':
+ return pickle.Unpickler.find_class(self, module, name)
+ raise pickle.UnpicklingError("global '%s.%s' is forbidden" %
+ (module, name))
+
+ def load(filename):
+ with open(filename, 'rb') as f:
+ return Unpickler(f).load()
+
+ load('babel/global.dat')
+ load('babel/localedata/root.dat')
+ load('babel/localedata/en.dat')
+ load('babel/localedata/en_US.dat')
+ load('babel/localedata/en_US_POSIX.dat')
+ load('babel/localedata/zh_Hans_CN.dat')
+ load('babel/localedata/zh_Hant_TW.dat')
+ load('babel/localedata/es_419.dat')