[pypy-svn] r63713 - pypy/trunk/pypy/module/_locale/test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Apr 6 13:54:05 CEST 2009


Author: cfbolz
Date: Mon Apr  6 13:54:03 2009
New Revision: 63713

Modified:
   pypy/trunk/pypy/module/_locale/test/test_locale.py
Log:
Check for the presence of the locales that the tests use and skip if they are
not there.


Modified: pypy/trunk/pypy/module/_locale/test/test_locale.py
==============================================================================
--- pypy/trunk/pypy/module/_locale/test/test_locale.py	(original)
+++ pypy/trunk/pypy/module/_locale/test/test_locale.py	Mon Apr  6 13:54:03 2009
@@ -1,11 +1,12 @@
 # -*- coding: utf-8 -*-
+import py
 from pypy.conftest import gettestobjspace
 
 import sys
 
 class AppTestLocaleTrivia:
     def setup_class(cls):
-        cls.space = gettestobjspace(usemodules=['_locale'])
+        cls.space = space = gettestobjspace(usemodules=['_locale'])
         if sys.platform != 'win32':
             cls.w_language_en = cls.space.wrap("en_US")
             cls.w_language_utf8 = cls.space.wrap("en_US.UTF-8")
@@ -14,6 +15,19 @@
             cls.w_language_en = cls.space.wrap("English_US")
             cls.w_language_utf8 = cls.space.wrap("English_US.65001")
             cls.w_language_pl = cls.space.wrap("Polish_Poland")
+        import _locale
+        # check whether used locales are installed, otherwise the tests will
+        # fail
+        current = _locale.setlocale(_locale.LC_ALL)
+        try:
+            try:
+                _locale.setlocale(_locale.LC_ALL, space.str_w(cls.w_language_en))
+                _locale.setlocale(_locale.LC_ALL, space.str_w(cls.w_language_utf8))
+                _locale.setlocale(_locale.LC_ALL, space.str_w(cls.w_language_pl))
+            except _locale.Error:
+                py.test.skip("necessary locales not installed")
+        finally:
+            _locale.setlocale(_locale.LC_ALL, current)
 
     def test_import(self):
         import _locale



More information about the Pypy-commit mailing list