|
1 | 1 | from decimal import Decimal
|
2 |
| -from test.support import verbose, is_android, is_emscripten, is_wasi |
| 2 | +from test.support import verbose, is_android, is_emscripten, is_wasi, os_helper |
3 | 3 | from test.support.warnings_helper import check_warnings
|
4 | 4 | from test.support.import_helper import import_fresh_module
|
5 | 5 | from unittest import mock
|
@@ -499,25 +499,16 @@ def test_defaults_UTF8(self):
|
499 | 499 | else:
|
500 | 500 | orig_getlocale = None
|
501 | 501 |
|
502 |
| - orig_env = {} |
503 | 502 | try:
|
504 |
| - for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): |
505 |
| - if key in os.environ: |
506 |
| - orig_env[key] = os.environ[key] |
507 |
| - del os.environ[key] |
| 503 | + with os_helper.EnvironmentVarGuard() as env: |
| 504 | + for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): |
| 505 | + env.unset(key) |
508 | 506 |
|
509 |
| - os.environ['LC_CTYPE'] = 'UTF-8' |
510 |
| - |
511 |
| - with check_warnings(('', DeprecationWarning)): |
512 |
| - self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8')) |
| 507 | + env.set('LC_CTYPE', 'UTF-8') |
513 | 508 |
|
| 509 | + with check_warnings(('', DeprecationWarning)): |
| 510 | + self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8')) |
514 | 511 | finally:
|
515 |
| - for k in orig_env: |
516 |
| - os.environ[k] = orig_env[k] |
517 |
| - |
518 |
| - if 'LC_CTYPE' not in orig_env: |
519 |
| - del os.environ['LC_CTYPE'] |
520 |
| - |
521 | 512 | if orig_getlocale is not None:
|
522 | 513 | _locale._getdefaultlocale = orig_getlocale
|
523 | 514 |
|
|
0 commit comments