def testPythonToYaml(self): pythonDict = dict() pythonDict['foo'] = 'test \'legal\' yaml' pythonDict['bar'] = 'test "legal" yaml' pythonDict['baz'] = 'test \'legal\' yaml' pythonDict['newline'] = 'test embedded\nnewline yaml' translator = PythonToFile(pythonDict) translator.write_to_file(self._target_yaml_file) translator = FileToPython(self._target_yaml_file, use_ordering=True) newPythonDict = translator.parse() self.assertEqual('foo' in newPythonDict, True) self.assertEqual('bar' in newPythonDict, True) self.assertEqual('baz' in newPythonDict, True) self.assertEquals('newline' in newPythonDict, True) quotedValue = newPythonDict['foo'] self.assertEqual(quotedValue, 'test \'legal\' yaml') quotedValue = newPythonDict['bar'] self.assertEqual(quotedValue, 'test "legal" yaml') quotedValue = newPythonDict['baz'] self.assertEqual(quotedValue, 'test \'legal\' yaml') quotedValue = newPythonDict['newline'] self.assertEqual(quotedValue, 'test embedded\nnewline yaml')
def testPythonToJson(self): pythonDict = dict() pythonDict['foo'] = 'this is a "legal" JSON value' pythonDict['keys "can" have quotes too'] = 123 translator = PythonToFile(pythonDict) translator.write_to_file(self._target_json_file) translator = FileToPython(self._target_json_file) newPythonDict = translator.parse() self.assertEqual('foo' in newPythonDict, True) self.assertEqual('keys "can" have quotes too' in newPythonDict, True) self.assertEqual(newPythonDict['foo'], 'this is a "legal" JSON value') self.assertEqual(newPythonDict['keys "can" have quotes too'], 123)