diff --git a/.gitignore b/.gitignore index ed180a5c6..8584514c9 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ gaenv/ # pip-related files *.egg-info dist +*.ok_refresh +*.ok_messages diff --git a/client/tests/utils/formatting_test.py b/client/tests/utils/formatting_test.py index 5b51bd5be..838e65f0c 100644 --- a/client/tests/utils/formatting_test.py +++ b/client/tests/utils/formatting_test.py @@ -17,27 +17,43 @@ def testString_singleLine(self): def testString_multipleLines(self): self.assertFormat(""" - \"\"\" + r\"\"\" hello world \"\"\" """, "hello\nworld") - def testString_multipleLines(self): + def testString_multipleLinesSurroundingNewlines(self): self.assertFormat(""" - \"\"\" + r\"\"\" hello world \"\"\" """, "\nhello\nworld\n") + def testString_rawStringSingleLine(self): + self.assertFormat(r""" + 'hello \\ there' + """, r"hello \ there") + + def testString_rawStringMultiLine(self): + self.assertFormat(""" + r\"\"\" + hello \\ + there + \"\"\" + """, r""" + hello \ + there + """) + def testList_onlyPrimitives(self): self.assertFormat(""" [ 42, 3.14, 'hello world', - \"\"\" + r\"\"\" hello world \"\"\" @@ -66,7 +82,7 @@ def testDict_onlyPrimitives(self): self.assertFormat(""" { 'answer': 'hello world', - 'multi': \"\"\" + 'multi': r\"\"\" answer here \"\"\", diff --git a/client/utils/formatting.py b/client/utils/formatting.py index 2eae2f2ce..bd4723d43 100644 --- a/client/utils/formatting.py +++ b/client/utils/formatting.py @@ -69,6 +69,9 @@ def prettyjson(json, indentation=' '): json -- Python object that is serializable into json. indentation -- str; represents one level of indentation + NOTES: + All multiline strings are treated as raw strings. + RETURNS: str; the formatted json-like string. """ @@ -76,7 +79,7 @@ def prettyjson(json, indentation=' '): return str(json) elif isinstance(json, str): if '\n' in json: - return '"""\n' + dedent(json) + '\n"""' + return 'r"""\n' + dedent(json) + '\n"""' return repr(json) elif isinstance(json, list): lst = [indent(prettyjson(el, indentation), indentation) for el in json]