Mercurial > hg
comparison tests/run-tests.py @ 33552:754569f5e999
run-tests: make sure to check if pygments is installed before using it
e80041832e introduced support to color the output of tests but used pygments
without checking whether it's installed or not. That breaks test-run-tests.t for
machines which don't have pygments installed. This patch conditionalize the
color test in test-run-tests.t and also add a check to make sure pygments is
installed before using that.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 15 Jul 2017 02:17:05 +0530 |
parents | 9c6e64911de0 |
children | 2893face0af5 |
comparison
equal
deleted
inserted
replaced
33551:1d1779734c99 | 33552:754569f5e999 |
---|---|
87 origenviron = os.environ.copy() | 87 origenviron = os.environ.copy() |
88 osenvironb = getattr(os, 'environb', os.environ) | 88 osenvironb = getattr(os, 'environb', os.environ) |
89 processlock = threading.Lock() | 89 processlock = threading.Lock() |
90 | 90 |
91 with_color = False | 91 with_color = False |
92 | 92 pygmentspresent = False |
93 # ANSI color is unsupported prior to Windows 10 | 93 # ANSI color is unsupported prior to Windows 10 |
94 if os.name != 'nt': | 94 if os.name != 'nt': |
95 try: # is pygments installed | 95 try: # is pygments installed |
96 import pygments | 96 import pygments |
97 import pygments.lexers as lexers | 97 import pygments.lexers as lexers |
98 import pygments.formatters as formatters | 98 import pygments.formatters as formatters |
99 with_color = True | 99 with_color = True |
100 pygmentspresent = True | |
100 except ImportError: | 101 except ImportError: |
101 pass | 102 pass |
102 | 103 |
103 if not sys.stderr.isatty(): # check if the terminal is capable | 104 if not sys.stderr.isatty(): # check if the terminal is capable |
104 with_color = False | 105 with_color = False |
1648 raise test.failureException( | 1649 raise test.failureException( |
1649 'server failed to start (HGPORT=%s)' % test._startport) | 1650 'server failed to start (HGPORT=%s)' % test._startport) |
1650 else: | 1651 else: |
1651 self.stream.write('\n') | 1652 self.stream.write('\n') |
1652 for line in lines: | 1653 for line in lines: |
1653 if with_color: | 1654 if with_color and pygmentspresent: |
1654 line = pygments.highlight( | 1655 line = pygments.highlight( |
1655 line, | 1656 line, |
1656 lexers.DiffLexer(), | 1657 lexers.DiffLexer(), |
1657 formatters.Terminal256Formatter()) | 1658 formatters.Terminal256Formatter()) |
1658 if PYTHON3: | 1659 if PYTHON3: |