-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-39828: Fix json.tool to catch BrokenPipeError. #18779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f1fc4ab
dfa361d
871eabf
337fdd2
d02c089
f67630c
e6931d8
e9c7eaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,4 +72,7 @@ def main(): | |
|
||
|
||
if __name__ == '__main__': | ||
main() | ||
try: | ||
main() | ||
except BrokenPipeError as exc: | ||
sys.exit(exc.errno) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import errno | ||
import os | ||
import sys | ||
import textwrap | ||
import unittest | ||
import subprocess | ||
|
||
from test import support | ||
from test.support.script_helper import assert_python_ok | ||
|
||
|
@@ -206,3 +208,14 @@ def test_ensure_ascii_default(self): | |
# asserting an ascii encoded output file | ||
expected = [b'{', rb' "key": "\ud83d\udca9"', b"}"] | ||
self.assertEqual(lines, expected) | ||
|
||
@unittest.skipIf(sys.platform =="win32", "The test is failed with ValueError on Windows") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR is now closed. You can write a new PR to enhance the skip message. |
||
def test_broken_pipe_error(self): | ||
cmd = [sys.executable, '-m', 'json.tool'] | ||
proc = subprocess.Popen(cmd, | ||
stdout=subprocess.PIPE, | ||
stdin=subprocess.PIPE) | ||
corona10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# bpo-39828: Closing before json.tool attempts to write into stdout. | ||
proc.stdout.close() | ||
proc.communicate(b'"{}"') | ||
self.assertEqual(proc.returncode, errno.EPIPE) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix :mod:`json.tool` to catch :exc:`BrokenPipeError`. Patch by Dong-hee Na. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the ValueError come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/python/cpython/pull/18779/checks?check_run_id=496883234