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
1diff --git a/src/lazr/restful/testing/webservice.py b/src/lazr/restful/testing/webservice.py
2index 85e8ba6..193ada8 100644
3--- a/src/lazr/restful/testing/webservice.py
4+++ b/src/lazr/restful/testing/webservice.py
5@@ -193,19 +193,9 @@ def pformat_value(value):
6 """Pretty-format a single value.
7
8 This is similar to `repr()`, but for doctest compatibility we format
9- text and bytes in a way that looks the same on both Python 2 and 3.
10- JSON strings are always Unicode, never bytes, so this doesn't introduce
11- ambiguity.
12+ values in a way that is unambiguous across Python versions.
13 """
14- if isinstance(value, str):
15- value = value.encode("unicode_escape").decode("ASCII")
16- if "'" in value and '"' not in value:
17- return '"%s"' % value
18- else:
19- return "'%s'" % value.replace("'", "\\'")
20- elif isinstance(value, list):
21- return "[" + ", ".join(pformat_value(item) for item in value) + "]"
22- elif isinstance(value, OrderedDict):
23+ if isinstance(value, OrderedDict):
24 # WebServiceResponseWrapper.jsonBody turns JSON objects into
25 # OrderedDicts, but for doctest compatibility we just want to
26 # re-sort and render these as if they were ordinary dicts.

Subscribers

People subscribed via source and target branches