[pypy-commit] pypy default: Add try/finally logic in test_unicode_join_str_arg_utf8 to fix sys.modules
dripton
noreply at buildbot.pypy.org
Mon Mar 12 23:36:00 CET 2012
Author: David Ripton <dripton at ripton.net>
Branch:
Changeset: r53367:66408094335d
Date: 2012-03-12 15:11 -0700
http://bitbucket.org/pypy/pypy/changeset/66408094335d/
Log: Add try/finally logic in test_unicode_join_str_arg_utf8 to fix
sys.modules
diff --git a/pypy/objspace/std/test/test_stringobject.py b/pypy/objspace/std/test/test_stringobject.py
--- a/pypy/objspace/std/test/test_stringobject.py
+++ b/pypy/objspace/std/test/test_stringobject.py
@@ -509,26 +509,30 @@
# is removed after startup.
import sys
old_encoding = sys.getdefaultencoding()
-
# Duplicate unittest.test_support.CleanImport logic because it won't
# import.
self.original_modules = sys.modules.copy()
- for module_name in ['sys']:
- if module_name in sys.modules:
- module = sys.modules[module_name]
- # It is possible that module_name is just an alias for
- # another module (e.g. stub for modules renamed in 3.x).
- # In that case, we also need delete the real module to clear
- # the import cache.
- if module.__name__ != module_name:
- del sys.modules[module.__name__]
- del sys.modules[module_name]
-
- import sys as temp_sys
- temp_sys.setdefaultencoding('utf-8')
- assert u''.join(['\xc3\xa1']) == u'\xe1'
- temp_sys.setdefaultencoding(old_encoding)
- sys.modules.update(self.original_modules)
+ try:
+ for module_name in ['sys']:
+ if module_name in sys.modules:
+ module = sys.modules[module_name]
+ # It is possible that module_name is just an alias for
+ # another module (e.g. stub for modules renamed in 3.x).
+ # In that case, we also need delete the real module to
+ # clear the import cache.
+ if module.__name__ != module_name:
+ del sys.modules[module.__name__]
+ del sys.modules[module_name]
+ import sys as temp_sys
+ temp_sys.setdefaultencoding('utf-8')
+ assert u''.join(['\xc3\xa1']) == u'\xe1'
+ finally:
+ try:
+ temp_sys.setdefaultencoding(old_encoding)
+ except NameError:
+ # It failed before we declared temp_sys
+ pass
+ sys.modules.update(self.original_modules)
def test_unicode_join_endcase(self):
# This class inserts a Unicode object into its argument's natural
More information about the pypy-commit
mailing list