summaryrefslogtreecommitdiff
path: root/Lib/test/test_optparse.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2009-04-26 20:51:44 +0000
committerWalter Dörwald <walter@livinglogic.de>2009-04-26 20:51:44 +0000
commit4b965f6ab17370b06ee587c7b12ad3bcd96163e3 (patch)
treef0b91e2341aac4251161bf630770740bd0b4c8af /Lib/test/test_optparse.py
parente73cbe7a4eba3498f03e8cd27248affcd99e1d74 (diff)
downloadcpython-git-4b965f6ab17370b06ee587c7b12ad3bcd96163e3.tar.gz
Use test.test_support.EnvironmentVarGuard where tests change environment vars.
Diffstat (limited to 'Lib/test/test_optparse.py')
-rw-r--r--Lib/test/test_optparse.py20
1 files changed, 4 insertions, 16 deletions
diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py
index 7a917d8574..f27864ae46 100644
--- a/Lib/test/test_optparse.py
+++ b/Lib/test/test_optparse.py
@@ -1464,15 +1464,9 @@ class TestHelp(BaseTest):
# we must restore its original value -- otherwise, this test
# screws things up for other tests when it's part of the Python
# test suite.
- orig_columns = os.environ.get('COLUMNS')
- os.environ['COLUMNS'] = str(columns)
- try:
+ with test_support.EnvironmentVarGuard() as env:
+ env.set('COLUMNS', str(columns))
return InterceptingOptionParser(option_list=options)
- finally:
- if orig_columns is None:
- del os.environ['COLUMNS']
- else:
- os.environ['COLUMNS'] = orig_columns
def assertHelpEquals(self, expected_output):
if type(expected_output) is types.UnicodeType:
@@ -1499,16 +1493,10 @@ class TestHelp(BaseTest):
self.assertHelpEquals(_expected_help_long_opts_first)
def test_help_title_formatter(self):
- save = os.environ.get("COLUMNS")
- try:
- os.environ["COLUMNS"] = "80"
+ with test_support.EnvironmentVarGuard() as env:
+ env.set("COLUMNS", "80")
self.parser.formatter = TitledHelpFormatter()
self.assertHelpEquals(_expected_help_title_formatter)
- finally:
- if save is not None:
- os.environ["COLUMNS"] = save
- else:
- del os.environ["COLUMNS"]
def test_wrap_columns(self):
# Ensure that wrapping respects $COLUMNS environment variable.