From: Jun Omae Date: Tue, 4 Aug 2015 22:21:34 +0000 (+0900) Subject: Added unit tests for that *.dat files have only babel classes X-Git-Tag: dev-2a51c9b95d06~33^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6acf7ae1c95156d2adb956da77a8ec51b7e064da;p=thirdparty%2Fbabel.git Added unit tests for that *.dat files have only babel classes --- diff --git a/tests/test_core.py b/tests/test_core.py index 7e16765f..a4253d80 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')