[PATCH resend] run-tests: make sure to check if pygments is installed before using it

Jun Wu quark at fb.com
Mon Jul 17 15:24:26 EDT 2017


LGTM.

Excerpts from Pulkit Goyal's message of 2017-07-18 00:07:32 +0530:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit at gmail.com>
> # Date 1500065225 -19800
> #      Sat Jul 15 02:17:05 2017 +0530
> # Node ID 37df34ca705cf68eef4fa6b4087eb039f775d4e6
> # Parent  0353c051d54702a960e4efba1eea6fbc13ad401a
> 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.
> 
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -89,7 +89,7 @@
>  processlock = threading.Lock()
>  
>  with_color = False
> -
> +pygmentspresent = False
>  # ANSI color is unsupported prior to Windows 10
>  if os.name != 'nt':
>      try: # is pygments installed
> @@ -97,6 +97,7 @@
>          import pygments.lexers as lexers
>          import pygments.formatters as formatters
>          with_color = True
> +        pygmentspresent = True
>      except ImportError:
>          pass
>  
> @@ -1650,7 +1651,7 @@
>                  else:
>                      self.stream.write('\n')
>                      for line in lines:
> -                        if with_color:
> +                        if with_color and pygmentspresent:
>                              line = pygments.highlight(
>                                      line,
>                                      lexers.DiffLexer(),
> diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
> --- a/tests/test-run-tests.t
> +++ b/tests/test-run-tests.t
> @@ -121,7 +121,7 @@
>  
>  test diff colorisation
>  
> -#if no-windows
> +#if no-windows pygments
>    $ rt test-failure.t --color always
>    
>    \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc)


More information about the Mercurial-devel mailing list