comparison tests/run-tests.py @ 33561:2893face0af5

run-tests: check if stream is a tty before using color Previous implementation (e80041832eec) checked only if sys.stderr was a tty which was less general. Also makes sure that colors is never used if pygments is not available, irrespective of --color flag value.
author Matthieu Laneuville <matthieu.laneuville@octobus.net>
date Tue, 18 Jul 2017 07:19:26 +0900
parents 754569f5e999
children 0982d900dccb
comparison
equal deleted inserted replaced
33560:d4df141f90d1 33561:2893face0af5
98 import pygments.formatters as formatters 98 import pygments.formatters as formatters
99 with_color = True 99 with_color = True
100 pygmentspresent = True 100 pygmentspresent = True
101 except ImportError: 101 except ImportError:
102 pass 102 pass
103
104 if not sys.stderr.isatty(): # check if the terminal is capable
105 with_color = False
106 103
107 if sys.version_info > (3, 5, 0): 104 if sys.version_info > (3, 5, 0):
108 PYTHON3 = True 105 PYTHON3 = True
109 xrange = range # we use xrange in one place, and we'd rather not use range 106 xrange = range # we use xrange in one place, and we'd rather not use range
110 def _bytespath(p): 107 def _bytespath(p):
414 if options.chg and options.with_hg: 411 if options.chg and options.with_hg:
415 # chg shares installation location with hg 412 # chg shares installation location with hg
416 parser.error('--chg does not work when --with-hg is specified ' 413 parser.error('--chg does not work when --with-hg is specified '
417 '(use --with-chg instead)') 414 '(use --with-chg instead)')
418 415
419 global with_color
420 if options.color != 'auto':
421 if options.color == 'never':
422 with_color = False
423 else: # 'always', for testing purposes
424 with_color = True
425
426 global useipv6 416 global useipv6
427 if options.ipv6: 417 if options.ipv6:
428 useipv6 = checksocketfamily('AF_INET6') 418 useipv6 = checksocketfamily('AF_INET6')
429 else: 419 else:
430 # only use IPv6 if IPv4 is unavailable and IPv6 is available 420 # only use IPv6 if IPv4 is unavailable and IPv6 is available
1572 self._firststarttime = None 1562 self._firststarttime = None
1573 # Data stored for the benefit of generating xunit reports. 1563 # Data stored for the benefit of generating xunit reports.
1574 self.successes = [] 1564 self.successes = []
1575 self.faildata = {} 1565 self.faildata = {}
1576 1566
1567 global with_color
1568 if not self.stream.isatty(): # check if the terminal is capable
1569 with_color = False
1570
1571 if options.color != 'auto':
1572 if options.color == 'never':
1573 with_color = False
1574 else: # 'always', for testing purposes
1575 if pygmentspresent:
1576 with_color = True
1577
1577 def addFailure(self, test, reason): 1578 def addFailure(self, test, reason):
1578 self.failures.append((test, reason)) 1579 self.failures.append((test, reason))
1579 1580
1580 if self._options.first: 1581 if self._options.first:
1581 self.stop() 1582 self.stop()