# HG changeset patch # User Zbigniew Jędrzejewski-Szmek # Date 1329166573 -3600 # Branch issue13041 # Node ID 56846891a2b6d7f9cabecfb3746cd6fa64995c21 # Parent e9cf34d56ff1fd1f5c7c67c50075e3b07a1d31c5 issue13041: autodetect terminal width The tests are corrected to use COLUMNS override. diff --git a/Lib/argparse.py b/Lib/argparse.py --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -89,6 +89,7 @@ import re as _re import sys as _sys import textwrap as _textwrap +import shutil as _shutil from gettext import gettext as _, ngettext @@ -156,10 +157,7 @@ # default setting for width if width is None: - try: - width = int(_os.environ['COLUMNS']) - except (KeyError, ValueError): - width = 80 + width = _shutil.get_terminal_size().columns width -= 2 self._prog = prog diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -31,9 +31,9 @@ def setUp(self): # The tests assume that line wrapping occurs at 80 columns, but this # behaviour can be overridden by setting the COLUMNS environment - # variable. To ensure that this assumption is true, unset COLUMNS. + # variable. To ensure that this width is used, set COLUMNS=80. env = support.EnvironmentVarGuard() - env.unset("COLUMNS") + env['COLUMNS'] = '80' self.addCleanup(env.__exit__)