summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJun Omae <jun66j5@gmail.com>2015-08-05 07:21:34 +0900
committerJun Omae <jun66j5@gmail.com>2015-08-06 00:11:33 +0900
commit6acf7ae1c95156d2adb956da77a8ec51b7e064da (patch)
tree7d1359a66af59b5af2df5a5c59384271d8fc4190 /tests
parent94f68302796149898fe99c14edc2a5519baad5e8 (diff)
downloadbabel-6acf7ae1c95156d2adb956da77a8ec51b7e064da.tar.gz
Added unit tests for that *.dat files have only babel classes
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')