Merge lp:~cjwatson/lazr.restful/pformat-value-ordered-dict into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 301
Proposed branch: lp:~cjwatson/lazr.restful/pformat-value-ordered-dict
Merge into: lp:lazr.restful
Diff against target: 19 lines (+10/-0)
1 file modified
src/lazr/restful/testing/webservice.py (+10/-0)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/pformat-value-ordered-dict
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+403088@code.launchpad.net

Commit message

Handle OrderedDicts in pformat_value.

Description of the change

Now that WebServiceResponseWrapper.jsonBody turns JSON objects into OrderedDicts, this is useful for doctest compatibility; a few Launchpad tests fail without this.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lazr/restful/testing/webservice.py'
2--- src/lazr/restful/testing/webservice.py 2021-05-18 16:02:47 +0000
3+++ src/lazr/restful/testing/webservice.py 2021-05-20 20:56:28 +0000
4@@ -194,6 +194,16 @@
5 return "'%s'" % value.replace("'", "\\'")
6 elif isinstance(value, list):
7 return '[' + ', '.join(pformat_value(item) for item in value) + ']'
8+ elif isinstance(value, OrderedDict):
9+ # WebServiceResponseWrapper.jsonBody turns JSON objects into
10+ # OrderedDicts, but for doctest compatibility we just want to
11+ # re-sort and render these as if they were ordinary dicts.
12+ return (
13+ '{' +
14+ ', '.join(
15+ '%s: %s' % (pformat_value(k), pformat_value(v))
16+ for k, v in sorted(value.items())) +
17+ '}')
18 else:
19 return repr(value)
20

Subscribers

People subscribed via source and target branches