diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/json/tool.py | 5 | ||||
-rw-r--r-- | Lib/test/test_json/test_tool.py | 11 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Lib/json/tool.py b/Lib/json/tool.py index 8db9ea4..c42138a 100644 --- a/Lib/json/tool.py +++ b/Lib/json/tool.py @@ -52,4 +52,7 @@ def main(): if __name__ == '__main__': - main() + try: + main() + except BrokenPipeError as exc: + sys.exit(exc.errno) diff --git a/Lib/test/test_json/test_tool.py b/Lib/test/test_json/test_tool.py index f362f1b..a62a5d4 100644 --- a/Lib/test/test_json/test_tool.py +++ b/Lib/test/test_json/test_tool.py @@ -1,7 +1,9 @@ +import errno import os import sys import textwrap import unittest + from subprocess import Popen, PIPE from test import support from test.support.script_helper import assert_python_ok @@ -149,3 +151,12 @@ class TestTool(unittest.TestCase): self.assertEqual(out.splitlines(), self.expect_without_sort_keys.encode().splitlines()) self.assertEqual(err, b'') + + @unittest.skipIf(sys.platform =="win32", "The test is failed with ValueError on Windows") + def test_broken_pipe_error(self): + cmd = [sys.executable, '-m', 'json.tool'] + proc = Popen(cmd, stdout=PIPE, stdin=PIPE) + # bpo-39828: Closing before json.tool attempts to write into stdout. + proc.stdout.close() + proc.communicate(b'"{}"') + self.assertEqual(proc.returncode, errno.EPIPE) |