diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2001-09-05 17:09:48 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2001-09-05 17:09:48 (GMT) |
commit | 7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf (patch) | |
tree | ed1541d4f1e8ed463f1bfbee97bd9793d62d2ae5 /Lib/test | |
parent | 044d95e9f7e0c9d5840c623350df339526f037af (diff) | |
download | cpython-7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf.zip cpython-7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf.tar.gz cpython-7c82a3e0fcde5b0d58bdfbb0aed6c0a245ade4bf.tar.bz2 |
Patch #449815: Set filesystemencoding based on CODESET.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_unicode_file.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/test/test_unicode_file.py b/Lib/test/test_unicode_file.py index 7078197..8b5757c 100644 --- a/Lib/test/test_unicode_file.py +++ b/Lib/test/test_unicode_file.py @@ -6,8 +6,20 @@ import os from test_support import verify, TestSkipped, TESTFN_UNICODE try: from test_support import TESTFN_ENCODING + oldlocale = None except ImportError: - raise TestSkipped("No Unicode filesystem semantics on this platform.") + import locale + # try to run the test in an UTF-8 locale. If this locale is not + # available, avoid running the test since the locale's encoding + # might not support TESTFN_UNICODE. Likewise, if the system does + # not support locale.CODESET, Unicode file semantics is not + # available, either. + oldlocale = locale.setlocale(locale.LC_CTYPE) + try: + locale.setlocale(locale.LC_CTYPE,"en_US.UTF-8") + TESTFN_ENCODING = locale.nl_langinfo(locale.CODESET) + except (locale.Error, AttributeError): + raise TestSkipped("No Unicode filesystem semantics on this platform.") TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING) @@ -79,3 +91,5 @@ finally: os.chdir(cwd) os.rmdir(abs_encoded) print "All the Unicode tests appeared to work" +if oldlocale: + locale.setlocale(locale.LC_CTYPE, oldlocale) |