better default for bogus terminal getdimensions() call, fixes issue63
--HG-- branch : trunk
This commit is contained in:
parent
53fc3204fb
commit
f7c562e492
|
@ -1,4 +1,9 @@
|
||||||
Changes between 1.X and 1.1.1
|
Changes between 1.2.1 and 1.2.0
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
- fix issue63: assume <40 columns to be a bogus terminal width, default to 80
|
||||||
|
|
||||||
|
Changes between 1.2 and 1.1.1
|
||||||
=====================================
|
=====================================
|
||||||
|
|
||||||
- moved dist/looponfailing from py.test core into a new
|
- moved dist/looponfailing from py.test core into a new
|
||||||
|
|
|
@ -74,9 +74,11 @@ def get_terminal_width():
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
# FALLBACK
|
# FALLBACK
|
||||||
width = int(os.environ.get('COLUMNS', 80))-1
|
width = int(os.environ.get('COLUMNS', 80))
|
||||||
# XXX the windows getdimensions may be bogus, let's sanify a bit
|
else:
|
||||||
width = max(width, 40) # we alaways need 40 chars
|
# XXX the windows getdimensions may be bogus, let's sanify a bit
|
||||||
|
if width < 40:
|
||||||
|
width = 80
|
||||||
return width
|
return width
|
||||||
|
|
||||||
terminal_width = get_terminal_width()
|
terminal_width = get_terminal_width()
|
||||||
|
|
|
@ -8,14 +8,20 @@ def test_terminal_width_COLUMNS(monkeypatch):
|
||||||
fcntl = py.test.importorskip("fcntl")
|
fcntl = py.test.importorskip("fcntl")
|
||||||
monkeypatch.setattr(fcntl, 'ioctl', lambda *args: int('x'))
|
monkeypatch.setattr(fcntl, 'ioctl', lambda *args: int('x'))
|
||||||
monkeypatch.setenv('COLUMNS', '42')
|
monkeypatch.setenv('COLUMNS', '42')
|
||||||
assert terminalwriter.get_terminal_width() == 41
|
assert terminalwriter.get_terminal_width() == 42
|
||||||
monkeypatch.delenv('COLUMNS', raising=False)
|
monkeypatch.delenv('COLUMNS', raising=False)
|
||||||
|
|
||||||
def test_terminalwriter_defaultwidth_80(monkeypatch):
|
def test_terminalwriter_defaultwidth_80(monkeypatch):
|
||||||
monkeypatch.setattr(terminalwriter, '_getdimensions', lambda: 0/0)
|
monkeypatch.setattr(terminalwriter, '_getdimensions', lambda: 0/0)
|
||||||
monkeypatch.delenv('COLUMNS', raising=False)
|
monkeypatch.delenv('COLUMNS', raising=False)
|
||||||
tw = py.io.TerminalWriter()
|
tw = py.io.TerminalWriter()
|
||||||
assert tw.fullwidth == 80-1
|
assert tw.fullwidth == 80
|
||||||
|
|
||||||
|
def test_terminalwriter_getdimensions_bogus(monkeypatch):
|
||||||
|
monkeypatch.setattr(terminalwriter, '_getdimensions', lambda: (10,10))
|
||||||
|
monkeypatch.delenv('COLUMNS', raising=False)
|
||||||
|
tw = py.io.TerminalWriter()
|
||||||
|
assert tw.fullwidth == 80
|
||||||
|
|
||||||
def test_terminalwriter_computes_width(monkeypatch):
|
def test_terminalwriter_computes_width(monkeypatch):
|
||||||
monkeypatch.setattr(terminalwriter, 'get_terminal_width', lambda: 42)
|
monkeypatch.setattr(terminalwriter, 'get_terminal_width', lambda: 42)
|
||||||
|
|
Loading…
Reference in New Issue