]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Added unit tests for that *.dat files have only babel classes 188/head
authorJun Omae <jun66j5@gmail.com>
Tue, 4 Aug 2015 22:21:34 +0000 (07:21 +0900)
committerJun Omae <jun66j5@gmail.com>
Wed, 5 Aug 2015 15:11:33 +0000 (00:11 +0900)
tests/test_core.py

index 7e16765fc76e245570532381d2927a6bd679a342..a4253d806271350fc9b32cb05508ddff3b5c6962 100644 (file)
@@ -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')