Patchwork [4,of,4] run-tests: handle json.dumps divergence

login
register
mail settings
Submitter timeless
Date May 11, 2016, 5:23 a.m.
Message ID <260197dd6a3adaa773ab.1462944204@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/15008/
State Superseded, archived
Headers show

Comments

timeless - May 11, 2016, 5:23 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1462490239 0
#      Thu May 05 23:17:19 2016 +0000
# Node ID 260197dd6a3adaa773abd0df1cdd3cf8a5e5d199
# Parent  e3cd6b9a9dff64a497650ac81588091bca0b52a6
# EXP-Topic runtests
# Available At bb://timeless/mercurial-crew
#              hg pull bb://timeless/mercurial-crew -r 260197dd6a3a
run-tests: handle json.dumps divergence

In py2, json.dumps includes a trailing space after a comma at the
end of lines. The py3 behavior which omits the trailing space is
preferable, so we're going to strip it.
Martijn Pieters - May 18, 2016, 4:39 p.m.
On 11 May 2016 at 06:23, timeless <timeless@fmr.im> wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1462490239 0
> #      Thu May 05 23:17:19 2016 +0000
> # Node ID 260197dd6a3adaa773abd0df1cdd3cf8a5e5d199
> # Parent  e3cd6b9a9dff64a497650ac81588091bca0b52a6
> # EXP-Topic runtests
> # Available At bb://timeless/mercurial-crew
> #              hg pull bb://timeless/mercurial-crew -r 260197dd6a3a
> run-tests: handle json.dumps divergence
>
> In py2, json.dumps includes a trailing space after a comma at the
> end of lines. The py3 behavior which omits the trailing space is
> preferable, so we're going to strip it.
>
> diff -r e3cd6b9a9dff -r 260197dd6a3a tests/run-tests.py
> --- a/tests/run-tests.py        Tue Apr 05 01:35:58 2016 +0000
> +++ b/tests/run-tests.py        Thu May 05 23:17:19 2016 +0000
> @@ -1843,7 +1843,8 @@
>                                  tres = {'result': res}
>
>                              outcome[tc.name] = tres
> -                    jsonout = json.dumps(outcome, sort_keys=True, indent=4)
> +                    out = json.dumps(outcome, sort_keys=True, indent=4)
> +                    jsonout = '\n'.join([l.rstrip() for l in out.splitlines()])
>                      fp.writelines(("testreport =", jsonout))

Rather than strip, tell json.dumps not to include it in the first place:

   out = json.dumps(outcome, sort_keys=True, indent=4, separators=(',', ': '))

In Python 2, the default for separators is (', ', ': ') (so with
spaces), always, but in Python 3.4 and up, that changes to (',', ': ')
(no space after a comma) when indent is not set to None.

>              self._runner._checkhglib('Tested')
> diff -r e3cd6b9a9dff -r 260197dd6a3a tests/test-run-tests.t
> --- a/tests/test-run-tests.t    Tue Apr 05 01:35:58 2016 +0000
> +++ b/tests/test-run-tests.t    Thu May 05 23:17:19 2016 +0000
> @@ -586,7 +586,7 @@
>    testreport ={
>        "test-bogus.t": {
>            "result": "skip"
> -      },
> +      },
>        "test-failure.t": {
>            "result": "skip"
>        }
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r e3cd6b9a9dff -r 260197dd6a3a tests/run-tests.py
--- a/tests/run-tests.py	Tue Apr 05 01:35:58 2016 +0000
+++ b/tests/run-tests.py	Thu May 05 23:17:19 2016 +0000
@@ -1843,7 +1843,8 @@ 
                                 tres = {'result': res}
 
                             outcome[tc.name] = tres
-                    jsonout = json.dumps(outcome, sort_keys=True, indent=4)
+                    out = json.dumps(outcome, sort_keys=True, indent=4)
+                    jsonout = '\n'.join([l.rstrip() for l in out.splitlines()])
                     fp.writelines(("testreport =", jsonout))
 
             self._runner._checkhglib('Tested')
diff -r e3cd6b9a9dff -r 260197dd6a3a tests/test-run-tests.t
--- a/tests/test-run-tests.t	Tue Apr 05 01:35:58 2016 +0000
+++ b/tests/test-run-tests.t	Thu May 05 23:17:19 2016 +0000
@@ -586,7 +586,7 @@ 
   testreport ={
       "test-bogus.t": {
           "result": "skip"
-      }, 
+      },
       "test-failure.t": {
           "result": "skip"
       }