Closed Bug 1467225 Opened 8 years ago Closed 8 years ago

Test suite fails with extra whitespace in test output

Categories

(Developer Services :: Mercurial: hg.mozilla.org, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: mars, Unassigned)

Details

Some tests in the hgext/hgmo/tests/ directory fail because the output of json.tool contains trailing whitespace. It appears to be a known side-effect of the Python json.tool module. I observed this running Python 2.7.15. This whitespace gotcha has been documented in the Python 2.7.15 module docs. See the Note about separator() in https://docs.python.org/2/library/json.html#basic-usage. Steps to reproduce: 1. Copy an output produced by json.tool from a test file into a new file. e.g. hgext/hgmo/tests/test-json-changeset.t 2. 'cat -A test.json' produces the expected output 3. 'python -m json.tool test.json | cat -A' shows extra trailing whitespace. Example failure: ./run-tests hgext/hgmo/tests/test-json-extradata.t 2>&1 | cat -A Will run 15 non-Docker tests concurrently$ Running non-Docker Mercurial tests$ $ --- /home/mars/work/version-control-tools/hgext/hgmo/tests/test-json-extradata.t$ +++ /home/mars/work/version-control-tools/hgext/hgmo/tests/test-json-extradata.t.err$ @@ -48,28 +48,28 @@$ $ $ python -m json.tool < body$ {$ - "backedoutby": "",$ - "bookmarks": [],$ - "branch": "default",$ + "backedoutby": "", $ + "bookmarks": [], $ + "branch": "default", $ "date": [$ - 0.0,$ + 0.0, $ 0$ - ],$ - "desc": "NO BUG",$ - "landingsystem": "wobble",$ - "node": "c761ad6d27c96f72f7e4637789e967c3f9730255",$ + ], $ + "desc": "NO BUG", $ + "landingsystem": "wobble", $ + "node": "40e31a84e3dcf059c2e33d5a266edc6bad3b81ed", $ "parents": [$ - "ef0e7ae3b607356f580e6d7671abea63db849cc2"$ - ],$ - "phase": "public",$ + "afa8227ab48e5f3c749fb59f2e886cb487594cf2"$ + ], $ + "phase": "public", $ "pushdate": [$ - \d+, (re)$ + 1528302892, $ \d+ (re)$ - ],$ - "pushid": 3,$ - "pushuser": "hguser",$ + ], $ + "pushid": 3, $ + "pushuser": "hguser", $ "tags": [$ "tip"$ - ],$ + ], $ "user": "test"$ }$ $ ERROR: test-json-extradata.t output changed$ !$ Failed test-json-extradata.t: output changed$ # Ran 1 tests, 0 skipped, 1 failed.$
There was definitely a change in the standard library json/tool.py file at some point. pycharm-2016 json/tool.py: ... with outfile: json.dump(obj, outfile, sort_keys=True, indent=4, separators=(',', ': ')) outfile.write('\n') pyenv python-2.7 json/tool.py: ... json.dump(obj, outfile, sort_keys=True, indent=4) # uses default separator of ', ' outfile.write('\n')
I had an incorrectly configured environment and was using the wrong Python 2.7 interpreter. I rebuilt my environment on top of Python 2.7.14 and the test suite passes.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.