(root)/
Python-3.11.7/
Lib/
test/
test_json/
test_separators.py
       1  import textwrap
       2  from test.test_json import PyTest, CTest
       3  
       4  
       5  class ESC[4;38;5;81mTestSeparators:
       6      def test_separators(self):
       7          h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
       8               {'nifty': 87}, {'field': 'yes', 'morefield': False} ]
       9  
      10          expect = textwrap.dedent("""\
      11          [
      12            [
      13              "blorpie"
      14            ] ,
      15            [
      16              "whoops"
      17            ] ,
      18            [] ,
      19            "d-shtaeou" ,
      20            "d-nthiouh" ,
      21            "i-vhbjkhnth" ,
      22            {
      23              "nifty" : 87
      24            } ,
      25            {
      26              "field" : "yes" ,
      27              "morefield" : false
      28            }
      29          ]""")
      30  
      31  
      32          d1 = self.dumps(h)
      33          d2 = self.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
      34  
      35          h1 = self.loads(d1)
      36          h2 = self.loads(d2)
      37  
      38          self.assertEqual(h1, h)
      39          self.assertEqual(h2, h)
      40          self.assertEqual(d2, expect)
      41  
      42      def test_illegal_separators(self):
      43          h = {1: 2, 3: 4}
      44          self.assertRaises(TypeError, self.dumps, h, separators=(b', ', ': '))
      45          self.assertRaises(TypeError, self.dumps, h, separators=(', ', b': '))
      46          self.assertRaises(TypeError, self.dumps, h, separators=(b', ', b': '))
      47  
      48  
      49  class ESC[4;38;5;81mTestPySeparators(ESC[4;38;5;149mTestSeparators, ESC[4;38;5;149mPyTest): pass
      50  class ESC[4;38;5;81mTestCSeparators(ESC[4;38;5;149mTestSeparators, ESC[4;38;5;149mCTest): pass