Пример #1
0
 def test_unicode_output(self):
     with patch.dict(json_out.__opts__, {'output_indent': 'pretty'}):
         decoded = {'test': 'Д', 'example': 'one'}
         encoded = {'test': salt.utils.stringutils.to_str('Д'), 'example': 'one'}
         # json.dumps on Python 2 adds a space before a newline while in the
         # process of dumping a dictionary.
         if six.PY2:
             expected = salt.utils.stringutils.to_str('{\n    "example": "one", \n    "test": "Д"\n}')
         else:
             expected = '{\n    "example": "one",\n    "test": "Д"\n}'
         self.assertEqual(json_out.output(decoded), expected)
         self.assertEqual(json_out.output(encoded), expected)
Пример #2
0
 def test_unicode_output(self):
     with patch.dict(json_out.__opts__, {"output_indent": "pretty"}):
         decoded = {"test": "Д", "example": "one"}
         encoded = {
             "test": salt.utils.stringutils.to_str("Д"),
             "example": "one"
         }
         # json.dumps on Python 2 adds a space before a newline while in the
         # process of dumping a dictionary.
         expected = '{\n    "example": "one",\n    "test": "Д"\n}'
         self.assertEqual(json_out.output(decoded), expected)
         self.assertEqual(json_out.output(encoded), expected)
Пример #3
0
 def test_unicode_output(self):
     json.__opts__['output_indent'] = 'pretty'
     data = {'test': '\xe1', 'example': 'one'}
     expect = ('{"message": "\'utf8\' codec can\'t decode byte 0xe1 in position 0: unexpected end of data", '
               '"error": "Unable to serialize output to json"}')
     ret = json.output(data)
     self.assertEqual(expect, ret)
Пример #4
0
 def test_unicode_output(self):
     json.__opts__['output_indent'] = 'pretty'
     data = {'test': '\xe1', 'example': 'one'}
     expect = (
         '{"message": "\'utf8\' codec can\'t decode byte 0xe1 in position 0: unexpected end of data", '
         '"error": "Unable to serialize output to json"}')
     ret = json.output(data)
     self.assertEqual(expect, ret)
Пример #5
0
 def test_unicode_output(self):
     with patch.dict(json_out.__opts__, {'output_indent': 'pretty'}):
         data = {'test': '\xe1', 'example': 'one'}
         expect = ('{"message": "\'utf8\' codec can\'t decode byte 0xe1 in position 0: unexpected end of data", '
                   '"error": "Unable to serialize output to json"}')
         ret = json_out.output(data)
         if six.PY2:
             self.assertEqual(expect, ret)
         else:
             self.assertEqual(json.loads(ret), data)
Пример #6
0
 def test_negative_int_output(self):
     json.__opts__['output_indent'] = -1
     ret = json.output(self.data)
     self.assertIn('"test": "two"', ret)
     self.assertIn('"example": "one"', ret)
Пример #7
0
 def test_pretty_output(self):
     json.__opts__['output_indent'] = 'pretty'
     ret = json.output(self.data)
     self.assertIn('"test": "two"', ret)
     self.assertIn('"example": "one"', ret)
Пример #8
0
 def test_indent_output(self):
     json_out.__opts__['output_indent'] = 2
     ret = json_out.output(self.data)
     self.assertIn('"test": "two"', ret)
     self.assertIn('"example": "one"', ret)
Пример #9
0
 def test_pretty_output(self):
     json.__opts__['output_indent'] = 'pretty'
     ret = json.output(self.data)
     expect = '{\n    "example": "one", \n    "test": "two"\n}'
     self.assertEqual(expect, ret)
Пример #10
0
 def test_negative_int_output(self):
     with patch.dict(json_out.__opts__, {'output_indent': -1}):
         ret = json_out.output(self.data)
         self.assertIn('"test": "two"', ret)
         self.assertIn('"example": "one"', ret)
Пример #11
0
 def test_pretty_output(self):
     json.__opts__['output_indent'] = 'pretty'
     ret = json.output(self.data)
     expect = '{\n    "example": "one", \n    "test": "two"\n}'
     self.assertEqual(expect, ret)
Пример #12
0
 def test_default_output(self):
     ret = json.output(self.data)
     expect = '{\n    "test": "two", \n    "example": "one"\n}'
     self.assertEqual(expect, ret)
Пример #13
0
 def test_negative_int_output(self):
     json.__opts__['output_indent'] = -1
     expect = '{"test": "two", "example": "one"}'
     ret = json.output(self.data)
     self.assertEqual(expect, ret)
Пример #14
0
 def test_negative_zero_output(self):
     json.__opts__['output_indent'] = 0
     expect = '{\n"test": "two", \n"example": "one"\n}'
     ret = json.output(self.data)
     self.assertEqual(expect, ret)
Пример #15
0
 def test_default_output(self):
     ret = json_out.output(self.data)
     self.assertIn('"test": "two"', ret)
     self.assertIn('"example": "one"', ret)
Пример #16
0
 def test_pretty_output(self):
     with patch.dict(json_out.__opts__, {'output_indent': 'pretty'}):
         ret = json_out.output(self.data)
         self.assertIn('"test": "two"', ret)
         self.assertIn('"example": "one"', ret)
Пример #17
0
 def test_negative_zero_output(self):
     json.__opts__['output_indent'] = 0
     expect = '{\n"test": "two", \n"example": "one"\n}'
     ret = json.output(self.data)
     self.assertEqual(expect, ret)
Пример #18
0
 def test_negative_int_output(self):
     json.__opts__['output_indent'] = -1
     expect = '{"test": "two", "example": "one"}'
     ret = json.output(self.data)
     self.assertEqual(expect, ret)
Пример #19
0
 def test_default_output(self):
     ret = json.output(self.data)
     expect = '{\n    "test": "two", \n    "example": "one"\n}'
     self.assertEqual(expect, ret)