Patchwork run-tests: make sure to check if pygments is installed before using it

login
register
mail settings
Submitter Pulkit Goyal
Date July 14, 2017, 9:05 p.m.
Message ID <07928a5240e51e2cd44f.1500066328@workspace>
Download mbox | patch
Permalink /patch/22380/
State Accepted
Headers show

Comments

Pulkit Goyal - July 14, 2017, 9:05 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1500065225 -19800
#      Sat Jul 15 02:17:05 2017 +0530
# Node ID 07928a5240e51e2cd44f7e05fccda32053ee0133
# Parent  2cbccf36af1bd0d9ae9df1ad5fd4a7f8d870ae6c
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.
Jun Wu - July 14, 2017, 9:09 p.m.
Looks good to me.

Excerpts from Pulkit Goyal's message of 2017-07-15 02:35:28 +0530:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1500065225 -19800
> #      Sat Jul 15 02:17:05 2017 +0530
> # Node ID 07928a5240e51e2cd44f7e05fccda32053ee0133
> # Parent  2cbccf36af1bd0d9ae9df1ad5fd4a7f8d870ae6c
> 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,10 +89,12 @@
>  processlock = threading.Lock()
>  
>  with_color = False
> +pygmentspresent = False
>  try: # is pygments installed
>      import pygments
>      import pygments.lexers as lexers
>      import pygments.formatters as formatters
> +    pygmentspresent = True
>      with_color = True
>  except ImportError:
>      pass
> @@ -1647,7 +1649,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,6 +121,8 @@
>  
>  test diff colorisation
>  
> +#if pygments
> +
>    $ rt test-failure.t --color always
>    
>    \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc)
> @@ -138,6 +140,8 @@
>    python hash seed: * (glob)
>    [1]
>  
> +#endif
> +
>    $ rt test-failure.t 2> tmp.log
>    [1]
>    $ cat tmp.log
Augie Fackler - July 14, 2017, 10:19 p.m.
On Sat, Jul 15, 2017 at 02:35:28AM +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1500065225 -19800
> #      Sat Jul 15 02:17:05 2017 +0530
> # Node ID 07928a5240e51e2cd44f7e05fccda32053ee0133
> # Parent  2cbccf36af1bd0d9ae9df1ad5fd4a7f8d870ae6c
> run-tests: make sure to check if pygments is installed before using it

queued, thanks
Augie Fackler - July 17, 2017, 2:37 p.m.
On Sat, Jul 15, 2017 at 02:35:28AM +0530, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1500065225 -19800
> #      Sat Jul 15 02:17:05 2017 +0530
> # Node ID 07928a5240e51e2cd44f7e05fccda32053ee0133
> # Parent  2cbccf36af1bd0d9ae9df1ad5fd4a7f8d870ae6c
> run-tests: make sure to check if pygments is installed before using it

This collided with mharbison's checks for Windows. Could you rebase
and resend?

>
> 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,10 +89,12 @@
>  processlock = threading.Lock()
>
>  with_color = False
> +pygmentspresent = False
>  try: # is pygments installed
>      import pygments
>      import pygments.lexers as lexers
>      import pygments.formatters as formatters
> +    pygmentspresent = True
>      with_color = True
>  except ImportError:
>      pass
> @@ -1647,7 +1649,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,6 +121,8 @@
>
>  test diff colorisation
>
> +#if pygments
> +
>    $ rt test-failure.t --color always
>
>    \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc)
> @@ -138,6 +140,8 @@
>    python hash seed: * (glob)
>    [1]
>
> +#endif
> +
>    $ rt test-failure.t 2> tmp.log
>    [1]
>    $ cat tmp.log
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -89,10 +89,12 @@ 
 processlock = threading.Lock()
 
 with_color = False
+pygmentspresent = False
 try: # is pygments installed
     import pygments
     import pygments.lexers as lexers
     import pygments.formatters as formatters
+    pygmentspresent = True
     with_color = True
 except ImportError:
     pass
@@ -1647,7 +1649,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,6 +121,8 @@ 
 
 test diff colorisation
 
+#if pygments
+
   $ rt test-failure.t --color always
   
   \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc)
@@ -138,6 +140,8 @@ 
   python hash seed: * (glob)
   [1]
 
+#endif
+
   $ rt test-failure.t 2> tmp.log
   [1]
   $ cat tmp.log