From 300e3380559f3a4dba19e16a2e2959979395f4da Mon Sep 17 00:00:00 2001 From: Albert Wu Date: Fri, 10 Oct 2014 11:27:20 -0700 Subject: [PATCH 1/2] Make client test dumping handle raw strings --- client/tests/utils/formatting_test.py | 26 +++++++++++++++++++++----- client/utils/formatting.py | 5 ++++- 2 files changed, 25 insertions(+), 6 deletions(-) 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] From c9ca9333a56d700e08c37b68c2f30f40f127eb5a Mon Sep 17 00:00:00 2001 From: Albert Wu Date: Fri, 10 Oct 2014 11:27:36 -0700 Subject: [PATCH 2/2] Add ok-generated dotfiles to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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