Merge ~cjwatson/lazr.restful:simplify-pformat-value into lazr.restful:main

Proposed by Colin Watson
Status: Merged
Merged at revision: 9a53af78c72e6a6bed159c5e13f3482833037606
Proposed branch: ~cjwatson/lazr.restful:simplify-pformat-value
Merge into: lazr.restful:main
Diff against target: 26 lines (+2/-12)
1 file modified
src/lazr/restful/testing/webservice.py (+2/-12)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+413872@code.launchpad.net

Commit message

Simplify lazr.restful.testing.webservice.pformat_value

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/lazr/restful/testing/webservice.py b/src/lazr/restful/testing/webservice.py
index 85e8ba6..193ada8 100644
--- a/src/lazr/restful/testing/webservice.py
+++ b/src/lazr/restful/testing/webservice.py
@@ -193,19 +193,9 @@ def pformat_value(value):
193 """Pretty-format a single value.193 """Pretty-format a single value.
194194
195 This is similar to `repr()`, but for doctest compatibility we format195 This is similar to `repr()`, but for doctest compatibility we format
196 text and bytes in a way that looks the same on both Python 2 and 3.196 values in a way that is unambiguous across Python versions.
197 JSON strings are always Unicode, never bytes, so this doesn't introduce
198 ambiguity.
199 """197 """
200 if isinstance(value, str):198 if isinstance(value, OrderedDict):
201 value = value.encode("unicode_escape").decode("ASCII")
202 if "'" in value and '"' not in value:
203 return '"%s"' % value
204 else:
205 return "'%s'" % value.replace("'", "\\'")
206 elif isinstance(value, list):
207 return "[" + ", ".join(pformat_value(item) for item in value) + "]"
208 elif isinstance(value, OrderedDict):
209 # WebServiceResponseWrapper.jsonBody turns JSON objects into199 # WebServiceResponseWrapper.jsonBody turns JSON objects into
210 # OrderedDicts, but for doctest compatibility we just want to200 # OrderedDicts, but for doctest compatibility we just want to
211 # re-sort and render these as if they were ordinary dicts.201 # re-sort and render these as if they were ordinary dicts.

Subscribers

People subscribed via source and target branches