+++ /dev/null
-import os\r
-import sys\r
-import textwrap\r
-import unittest\r
-import subprocess\r
-from test import test_support\r
-from test.script_helper import assert_python_ok\r
-\r
-class TestTool(unittest.TestCase):\r
- data = """\r
-\r
- [["blorpie"],[ "whoops" ] , [\r
- ],\t"d-shtaeou",\r"d-nthiouh",\r
- "i-vhbjkhnth", {"nifty":87}, {"morefield" :\tfalse,"field"\r
- :"yes"} ]\r
- """\r
-\r
- expect = textwrap.dedent("""\\r
- [\r
- [\r
- "blorpie"\r
- ],\r
- [\r
- "whoops"\r
- ],\r
- [],\r
- "d-shtaeou",\r
- "d-nthiouh",\r
- "i-vhbjkhnth",\r
- {\r
- "nifty": 87\r
- },\r
- {\r
- "field": "yes",\r
- "morefield": false\r
- }\r
- ]\r
- """)\r
-\r
- def test_stdin_stdout(self):\r
- proc = subprocess.Popen(\r
- (sys.executable, '-m', 'json.tool'),\r
- stdin=subprocess.PIPE, stdout=subprocess.PIPE)\r
- out, err = proc.communicate(self.data.encode())\r
- self.assertEqual(out.splitlines(), self.expect.encode().splitlines())\r
- self.assertEqual(err, None)\r
-\r
- def _create_infile(self):\r
- infile = test_support.TESTFN\r
- with open(infile, "w") as fp:\r
- self.addCleanup(os.remove, infile)\r
- fp.write(self.data)\r
- return infile\r
-\r
- def test_infile_stdout(self):\r
- infile = self._create_infile()\r
- rc, out, err = assert_python_ok('-m', 'json.tool', infile)\r
- self.assertEqual(out.splitlines(), self.expect.encode().splitlines())\r
- self.assertEqual(err, b'')\r
-\r
- def test_infile_outfile(self):\r
- infile = self._create_infile()\r
- outfile = test_support.TESTFN + '.out'\r
- rc, out, err = assert_python_ok('-m', 'json.tool', infile, outfile)\r
- self.addCleanup(os.remove, outfile)\r
- with open(outfile, "r") as fp:\r
- self.assertEqual(fp.read(), self.expect)\r
- self.assertEqual(out, b'')\r
- self.assertEqual(err, b'')\r