Merge ~cjwatson/lazr.restful:pretty-print-list-ordered-dict into lazr.restful:main

Proposed by Colin Watson
Status: Merged
Merged at revision: ae24b1f9f093c92290dff8b37ebd7a1f33d0aaae
Proposed branch: ~cjwatson/lazr.restful:pretty-print-list-ordered-dict
Merge into: lazr.restful:main
Diff against target: 77 lines (+48/-1)
3 files modified
NEWS.rst (+2/-0)
src/lazr/restful/testing/webservice.py (+3/-1)
src/lazr/restful/tests/test_testing.py (+43/-0)
Reviewer Review Type Date Requested Status
Andrey Fedoseev (community) Approve
Review via email: mp+425673@code.launchpad.net

Commit message

Fix regression in pretty-printing lists of OrderedDicts

Description of the change

Launchpad's test suite (in `lib/lp/registry/stories/webservice/xx-project-registry.rst`) relies on lists of `OrderedDict` objects being pretty-printed as if they were ordinary dicts; the change in https://code.launchpad.net/~cjwatson/lazr.restful/+git/lazr.restful/+merge/413872 regressed this. Restore the previous behaviour, and ensure we have a local test for it.

To post a comment you must log in.
Revision history for this message
Andrey Fedoseev (andrey-fedoseev) :
review: Approve
Revision history for this message
Andrey Fedoseev (andrey-fedoseev) wrote :

Colin,

I noticed that you didn't update the version number in `setup.py`. I assumed that you didn't do that on purpose (like, to add some other changes before releasing 2.0.1), but I wanted to let you know anyway.

Revision history for this message
Colin Watson (cjwatson) wrote :

Yeah, I did that in a release commit, but thanks for checking.

Revision history for this message
Jürgen Gmach (jugmac00) wrote (last edit ):

What I often see is that immediately after a release another "back to development" commit is done which updates the version number to version+1 and the dev0 suffix.

Revision history for this message
Colin Watson (cjwatson) wrote :

Fair enough - done for 2.0.2.dev0.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/NEWS.rst b/NEWS.rst
2index cf82019..b366942 100644
3--- a/NEWS.rst
4+++ b/NEWS.rst
5@@ -6,6 +6,8 @@ NEWS for lazr.restful
6 =====
7
8 - Remove simplejson dependency.
9+- Fix regression in rendering of lists of ``OrderedDict`` objects by
10+ ``lazr.restful.testing.webservice.pformat_value``.
11
12 2.0.0 (2022-06-01)
13 ==================
14diff --git a/src/lazr/restful/testing/webservice.py b/src/lazr/restful/testing/webservice.py
15index 1de10b6..e3f8b7e 100644
16--- a/src/lazr/restful/testing/webservice.py
17+++ b/src/lazr/restful/testing/webservice.py
18@@ -194,7 +194,9 @@ def pformat_value(value):
19 This is similar to `repr()`, but for doctest compatibility we format
20 values in a way that is unambiguous across Python versions.
21 """
22- if isinstance(value, OrderedDict):
23+ if isinstance(value, list):
24+ return "[" + ", ".join(pformat_value(item) for item in value) + "]"
25+ elif isinstance(value, OrderedDict):
26 # WebServiceResponseWrapper.jsonBody turns JSON objects into
27 # OrderedDicts, but for doctest compatibility we just want to
28 # re-sort and render these as if they were ordinary dicts.
29diff --git a/src/lazr/restful/tests/test_testing.py b/src/lazr/restful/tests/test_testing.py
30new file mode 100644
31index 0000000..3a77fc8
32--- /dev/null
33+++ b/src/lazr/restful/tests/test_testing.py
34@@ -0,0 +1,43 @@
35+# Copyright 2022 Canonical Ltd. All rights reserved.
36+#
37+# This file is part of lazr.restful.
38+#
39+# lazr.restful is free software: you can redistribute it and/or modify it
40+# under the terms of the GNU Lesser General Public License as published by
41+# the Free Software Foundation, version 3 of the License.
42+#
43+# lazr.restful is distributed in the hope that it will be useful, but WITHOUT
44+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
46+# License for more details.
47+#
48+# You should have received a copy of the GNU Lesser General Public License
49+# along with lazr.restful. If not, see <http://www.gnu.org/licenses/>.
50+
51+from collections import OrderedDict
52+
53+from testtools import TestCase
54+
55+from lazr.restful.testing.webservice import pformat_value
56+
57+
58+class TestPrettyFormatValue(TestCase):
59+ """Test `lazr.restful.testing.webservice.pformat_value`."""
60+
61+ def test_string(self):
62+ self.assertEqual("'foo'", pformat_value("foo"))
63+
64+ def test_bytes(self):
65+ self.assertEqual("b'foo'", pformat_value(b"foo"))
66+
67+ def test_ordered_dict(self):
68+ self.assertEqual(
69+ "{'abc': 'def', 'ghi': 'jkl'}",
70+ pformat_value(OrderedDict((("abc", "def"), ("ghi", "jkl")))),
71+ )
72+
73+ def test_list_of_ordered_dicts(self):
74+ self.assertEqual(
75+ "[{'abc': 'def', 'ghi': 'jkl'}]",
76+ pformat_value([OrderedDict((("abc", "def"), ("ghi", "jkl")))]),
77+ )

Subscribers

People subscribed via source and target branches