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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
def test_default_output(self): ret = json.output(self.data) expect = '{\n "test": "two", \n "example": "one"\n}' self.assertEqual(expect, ret)
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)
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)
def test_default_output(self): ret = json_out.output(self.data) self.assertIn('"test": "two"', ret) self.assertIn('"example": "one"', ret)
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)