import os as _os
import re as _re
+import shutil as _shutil
import sys as _sys
from gettext import gettext as _, ngettext
# 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
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 to 80.
env = support.EnvironmentVarGuard()
- env.unset("COLUMNS")
+ env['COLUMNS'] = '80'
self.addCleanup(env.__exit__)
class TestWrappingMetavar(TestCase):
def setUp(self):
+ super().setUp()
self.parser = ErrorRaisingArgumentParser(
'this_is_spammy_prog_with_a_long_name_sorry_about_the_name'
)