summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_support.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-04-30 11:13:56 (GMT)
committerGeorg Brandl <georg@python.org>2006-04-30 11:13:56 (GMT)
commitde9b624fb943295263f8140d9d2eda393348b8ec (patch)
tree5d2af20626e9afd98486b718235fa1f9b466812e /Lib/test/test_support.py
parent44a118af5043ed6919bd1d0bcfc603f496ae4d7c (diff)
downloadcpython-de9b624fb943295263f8140d9d2eda393348b8ec.zip
cpython-de9b624fb943295263f8140d9d2eda393348b8ec.tar.gz
cpython-de9b624fb943295263f8140d9d2eda393348b8ec.tar.bz2
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
On the way, add a decorator to test_support to facilitate running single test functions in different locales with automatic cleanup.
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r--Lib/test/test_support.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index c1a635a..2d08f4d 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -252,6 +252,42 @@ def open_urlresource(url):
return open(fn)
#=======================================================================
+# Decorator for running a function in a different locale, correctly resetting
+# it afterwards.
+
+def run_with_locale(catstr, *locales):
+ def decorator(func):
+ def inner(*args, **kwds):
+ try:
+ import locale
+ category = getattr(locale, catstr)
+ orig_locale = locale.setlocale(category)
+ except AttributeError:
+ # if the test author gives us an invalid category string
+ raise
+ except:
+ # cannot retrieve original locale, so do nothing
+ locale = orig_locale = None
+ else:
+ for loc in locales:
+ try:
+ locale.setlocale(category, loc)
+ break
+ except:
+ pass
+
+ # now run the function, resetting the locale on exceptions
+ try:
+ return func(*args, **kwds)
+ finally:
+ if locale and orig_locale:
+ locale.setlocale(category, orig_locale)
+ inner.func_name = func.func_name
+ inner.__doc__ = func.__doc__
+ return inner
+ return decorator
+
+#=======================================================================
# Big-memory-test support. Separate from 'resources' because memory use should be configurable.
# Some handy shorthands. Note that these are used for byte-limits as well