classification
Title: regression: -m json.tool module is broken
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: 16333 Superseder:
Assigned To: ezio.melotti Nosy List: Arfrever, berker.peksag, ezio.melotti, jcea, martin.panter, python-dev, serhiy.storchaka, techtonik
Priority: normal Keywords: easy, patch

Created on 2012-11-24 23:19 by techtonik, last changed 2013-12-08 17:35 by Arfrever. This issue is now closed.

Files
File name Uploaded Description Edit
stdlibx.json techtonik, 2012-11-24 23:18
json_tool_open.patch serhiy.storchaka, 2012-11-25 13:31 review
issue16549.diff berker.peksag, 2012-11-25 15:18 review
json_tool_tests.patch serhiy.storchaka, 2012-11-25 15:22 Tests for json.tool review
json_tool_tests_2.patch serhiy.storchaka, 2012-11-25 17:49 Tests for json.tool review
Messages (15)
msg176324 - (view) Author: anatoly techtonik (techtonik) Date: 2012-11-24 23:18
Awesome json tool doesn't work anymore in Python 3 (needs tests?).
http://stackoverflow.com/questions/352098/how-to-pretty-print-json-script

C:\Python27>python -m json.tool stdlibx.json
{
    "distutils": [
        "Doc/distutils",
        "Lib/distutils",
        "Lib/test/test_distutils.py"
    ],
    "json": [
        "Doc/library/json.rst",
        "Lib/json",
        "Lib/test/json_tests",
        "Lib/test/test_json.py"
    ]
}

C:\Python33>python -m json.tool stdlibx.json
Traceback (most recent call last):
  File "C:\Python33\lib\runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python33\lib\runpy.py", line 73, in _run_code
    exec(code, run_globals)
  File "C:\Python33\lib\json\tool.py", line 37, in <module>
    main()
  File "C:\Python33\lib\json\tool.py", line 29, in main
    obj = json.load(infile)
  File "C:\Python33\lib\json\__init__.py", line 264, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\Python33\lib\json\__init__.py", line 309, in loads
    return _default_decoder.decode(s)
  File "C:\Python33\lib\json\decoder.py", line 352, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: can't use a string pattern on a bytes-like object
msg176350 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-25 13:31
Here is a simple patch.
msg176364 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-11-25 15:18
Lib/json/tool.py is triggering a ResourceWarning.

Patch attached with a test.
msg176365 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-25 15:22
Tests added. They fail until issue16333 will be resolved.
msg176366 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-25 15:25
Oops. This issue becomes very popular.
msg176378 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-25 17:25
Berker and me wrote the different tests. I were add a separate test file because json.tool should not be tested for both C and Python implementation and because json tests already splitted on many files. Berker tests using json.tool as a filter. Both tests should be merged. Of course, using a `with` for open files is a good idea.
msg176379 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-25 17:49
Here is a merged tests.
msg176594 - (view) Author: Roundup Robot (python-dev) Date: 2012-11-29 00:27
New changeset 08e5973fdc7e by Ezio Melotti in branch '2.7':
#16549: Add tests for json.tools.  Initial patch by Berker Peksag and Serhiy Storchaka.
http://hg.python.org/cpython/rev/08e5973fdc7e

New changeset 44c544809e6c by Ezio Melotti in branch '3.2':
#16549: Make json.tool work again on Python 3 and add tests.  Initial patch by Berker Peksag and Serhiy Storchaka.
http://hg.python.org/cpython/rev/44c544809e6c

New changeset 1e2ae5e01963 by Ezio Melotti in branch '3.3':
#16549: merge with 3.2.
http://hg.python.org/cpython/rev/1e2ae5e01963

New changeset cdeca27b32e5 by Ezio Melotti in branch 'default':
#16549: merge with 3.3.
http://hg.python.org/cpython/rev/cdeca27b32e5
msg176596 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-29 00:31
Fixed, thanks for the patches!
msg176616 - (view) Author: Roundup Robot (python-dev) Date: 2012-11-29 03:10
New changeset 4102c1a02417 by Ezio Melotti in branch '2.7':
#16549: fix test failures on Windows.
http://hg.python.org/cpython/rev/4102c1a02417

New changeset 4ec9f0b0f8f1 by Ezio Melotti in branch '3.2':
#16549: fix test failures on Windows.
http://hg.python.org/cpython/rev/4ec9f0b0f8f1

New changeset e26345437f9f by Ezio Melotti in branch '3.3':
#16549: merge with 3.2.
http://hg.python.org/cpython/rev/e26345437f9f

New changeset 2a73d9e64d34 by Ezio Melotti in branch 'default':
#16549: merge with 3.3.
http://hg.python.org/cpython/rev/2a73d9e64d34
msg176660 - (view) Author: anatoly techtonik (techtonik) Date: 2012-11-29 16:34
+1
msg204884 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2013-12-01 05:23
2 tests fail (only on 2.7 branch) when `make test` runs test suite the second time:

======================================================================
ERROR: test_infile_outfile (json.tests.test_tool.TestTool)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-lang/python-2.7.7_pre20131201/work/python-2.7.7_pre20131201/Lib/json/tests/test_tool.py", line 64, in test_infile_outfile
    rc, out, err = assert_python_ok('-m', 'json.tool', infile, outfile)
  File "/var/tmp/portage/dev-lang/python-2.7.7_pre20131201/work/python-2.7.7_pre20131201/Lib/test/script_helper.py", line 55, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
TypeError: 'NoneType' object is not callable

======================================================================
ERROR: test_infile_stdout (json.tests.test_tool.TestTool)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/tmp/portage/dev-lang/python-2.7.7_pre20131201/work/python-2.7.7_pre20131201/Lib/json/tests/test_tool.py", line 57, in test_infile_stdout
    rc, out, err = assert_python_ok('-m', 'json.tool', infile)
  File "/var/tmp/portage/dev-lang/python-2.7.7_pre20131201/work/python-2.7.7_pre20131201/Lib/test/script_helper.py", line 55, in assert_python_ok
    return _assert_python(True, *args, **env_vars)
TypeError: 'NoneType' object is not callable

======================================================================
msg204911 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-12-01 11:15
This doesn't look related to json tests. Are there other tests failures with similar symptoms (_assert_python is None)?
msg204925 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2013-12-01 14:36
No other tests fail in this way.
msg205587 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * Date: 2013-12-08 17:35
Somehow these errors do not occur today. Maybe they were side effects of other failures in test_json. Closing for now.
History
Date User Action Args
2013-12-08 17:35:29Arfreversetstatus: open -> closed
resolution: fixed
messages: + msg205587

stage: resolved
2013-12-01 14:36:37Arfreversetmessages: + msg204925
2013-12-01 11:15:02serhiy.storchakasetmessages: + msg204911
2013-12-01 05:23:06Arfreversetstatus: closed -> open

nosy: + Arfrever
messages: + msg204884

resolution: fixed -> (no value)
stage: resolved -> (no value)
2012-11-29 16:34:25techtoniksetmessages: + msg176660
2012-11-29 03:10:58python-devsetmessages: + msg176616
2012-11-29 00:31:17ezio.melottisetstatus: open -> closed
versions: + Python 2.7
messages: + msg176596

resolution: fixed
stage: patch review -> resolved
2012-11-29 00:27:47python-devsetnosy: + python-dev
messages: + msg176594
2012-11-28 04:05:44martin.pantersetnosy: + martin.panter
2012-11-26 17:19:32jceasetassignee: ezio.melotti
stage: needs patch -> patch review
versions: + Python 3.4, - Python 3.1
2012-11-26 17:18:35jceasetassignee: ezio.melotti -> (no value)
stage: patch review -> needs patch

nosy: + jcea
versions: + Python 3.1, - Python 3.4
2012-11-25 17:49:37serhiy.storchakasetfiles: + json_tool_tests_2.patch

messages: + msg176379
2012-11-25 17:25:47serhiy.storchakasetmessages: + msg176378
2012-11-25 15:25:08serhiy.storchakasetdependencies: + Trailing whitespace in json dump when using indent
messages: + msg176366
stage: test needed -> patch review
2012-11-25 15:22:41serhiy.storchakasetfiles: + json_tool_tests.patch

messages: + msg176365
2012-11-25 15:18:30berker.peksagsetfiles: + issue16549.diff
nosy: + berker.peksag
messages: + msg176364

2012-11-25 13:38:05ezio.melottisetassignee: ezio.melotti

nosy: + ezio.melotti
stage: needs patch -> test needed
2012-11-25 13:31:51serhiy.storchakasetfiles: + json_tool_open.patch
versions: + Python 3.4, - Python 3.1
nosy: + serhiy.storchaka

messages: + msg176350

keywords: + patch
2012-11-24 23:29:56pitrousetkeywords: + easy
type: behavior
stage: needs patch
2012-11-24 23:19:20techtoniksetcomponents: + Library (Lib)
title: regression: -m json.tool module -> regression: -m json.tool module is broken
2012-11-24 23:19:00techtonikcreate