Merge ~cjwatson/launchpad:py3-remaining-doctest-unicode-strings into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 74457e44a8de776ac7e5d52e64ccafd65e81e88b
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-remaining-doctest-unicode-strings
Merge into: launchpad:master
Diff against target: 139 lines (+55/-26)
2 files modified
lib/lp/registry/browser/tests/karmacontext-views.txt (+15/-8)
lib/lp/services/database/postgresql.py (+40/-18)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+398699@code.launchpad.net

Commit message

Fix remaining u'...' doctest examples for Python 3

Description of the change

I missed a couple of spots when landing earlier similar changes.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Self-approving, like other similar previous changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/registry/browser/tests/karmacontext-views.txt b/lib/lp/registry/browser/tests/karmacontext-views.txt
index 3546713..e412bba 100644
--- a/lib/lp/registry/browser/tests/karmacontext-views.txt
+++ b/lib/lp/registry/browser/tests/karmacontext-views.txt
@@ -15,18 +15,25 @@ contributors on a given context and the top contributors by category.
15 >>> view = create_initialized_view(15 >>> view = create_initialized_view(
16 ... product, '+topcontributors', principal=user)16 ... product, '+topcontributors', principal=user)
17 >>> contributors = view._getTopContributorsWithLimit(limit=3)17 >>> contributors = view._getTopContributorsWithLimit(limit=3)
18 >>> [(contrib.person.name, contrib.karmavalue)18 >>> for contrib in contributors:
19 ... for contrib in contributors]19 ... print(contrib.person.name, contrib.karmavalue)
20 [(u'name16', 175), (u'mark', 22), (u'carlos', 9)]20 name16 175
21 mark 22
22 carlos 9
2123
22 >>> contributors = view.top_contributors_by_category24 >>> contributors = view.top_contributors_by_category
23 >>> categories = sorted(contributors.keys())25 >>> categories = sorted(contributors.keys())
24 >>> for category in categories:26 >>> for category in categories:
25 ... print(category, [(contrib.person.name, contrib.karmavalue)27 ... print(category)
26 ... for contrib in contributors[category]])28 ... for contrib in contributors[category]:
27 Bug Management [(u'name16', 11)]29 ... print(contrib.person.name, contrib.karmavalue)
28 Specification Tracking [(u'mark', 22)]30 Bug Management
29 Translations in Rosetta [(u'name16', 164), (u'carlos', 9)]31 name16 11
32 Specification Tracking
33 mark 22
34 Translations in Rosetta
35 name16 164
36 carlos 9
3037
31The view renders summaries by category.38The view renders summaries by category.
3239
diff --git a/lib/lp/services/database/postgresql.py b/lib/lp/services/database/postgresql.py
index a3fae61..b735476 100644
--- a/lib/lp/services/database/postgresql.py
+++ b/lib/lp/services/database/postgresql.py
@@ -21,6 +21,28 @@ from lp.services.database.sqlbase import (
21 )21 )
2222
2323
24def _py3ish_repr(value):
25 """Like `repr`, but uses Python 3 spelling of text.
26
27 This is a local helper for doctests.
28 """
29 if isinstance(value, six.text_type):
30 value = value.encode('unicode_escape').decode('ASCII')
31 if "'" in value and '"' not in value:
32 return '"%s"' % value
33 else:
34 return "'%s'" % value.replace("'", "\\'")
35 elif isinstance(value, tuple):
36 if len(value) == 1:
37 return '(' + _py3ish_repr(value[0]) + ',)'
38 else:
39 return '(' + ', '.join(_py3ish_repr(item) for item in value) + ')'
40 elif isinstance(value, list):
41 return '[' + ', '.join(_py3ish_repr(item) for item in value) + ']'
42 else:
43 return repr(value)
44
45
24def listReferences(cur, table, column, indirect=True, _state=None):46def listReferences(cur, table, column, indirect=True, _state=None):
25 """Return a list of all foreign key references to the given table column47 """Return a list of all foreign key references to the given table column
2648
@@ -43,11 +65,11 @@ def listReferences(cur, table, column, indirect=True, _state=None):
43 to change keys.65 to change keys.
4466
45 >>> for r in listReferences(cur, 'a', 'aid'):67 >>> for r in listReferences(cur, 'a', 'aid'):
46 ... print(repr(r))68 ... print(_py3ish_repr(r))
47 (u'a', u'selfref', u'a', u'aid', u'a', u'a')69 ('a', 'selfref', 'a', 'aid', 'a', 'a')
48 (u'b', u'aid', u'a', u'aid', u'c', u'c')70 ('b', 'aid', 'a', 'aid', 'c', 'c')
49 (u'c', u'aid', u'b', u'aid', u'a', u'a')71 ('c', 'aid', 'b', 'aid', 'a', 'a')
50 (u'd', u'aid', u'b', u'aid', u'a', u'a')72 ('d', 'aid', 'b', 'aid', 'a', 'a')
5173
52 Of course, there might not be any references74 Of course, there might not be any references
5375
@@ -115,27 +137,27 @@ def listUniques(cur, table, column):
115137
116 Simple UNIQUE index138 Simple UNIQUE index
117139
118 >>> listUniques(cur, 'b', 'aid')140 >>> print(_py3ish_repr(listUniques(cur, 'b', 'aid')))
119 [(u'aid',)]141 [('aid',)]
120142
121 Primary keys are UNIQUE indexes too143 Primary keys are UNIQUE indexes too
122144
123 >>> listUniques(cur, 'a', 'aid')145 >>> print(_py3ish_repr(listUniques(cur, 'a', 'aid')))
124 [(u'aid',)]146 [('aid',)]
125147
126 Compound indexes148 Compound indexes
127149
128 >>> listUniques(cur, 'c', 'aid')150 >>> print(_py3ish_repr(listUniques(cur, 'c', 'aid')))
129 [(u'aid', u'bid')]151 [('aid', 'bid')]
130 >>> listUniques(cur, 'c', 'bid')152 >>> print(_py3ish_repr(listUniques(cur, 'c', 'bid')))
131 [(u'aid', u'bid')]153 [('aid', 'bid')]
132154
133 And any combination155 And any combination
134156
135 >>> l = listUniques(cur, 'd', 'aid')157 >>> l = listUniques(cur, 'd', 'aid')
136 >>> l.sort()158 >>> l.sort()
137 >>> l159 >>> print(_py3ish_repr(l))
138 [(u'aid',), (u'aid', u'bid')]160 [('aid',), ('aid', 'bid')]
139161
140 If there are no UNIQUE indexes using the secified column162 If there are no UNIQUE indexes using the secified column
141163
@@ -196,9 +218,9 @@ def listSequences(cur):
196 standalone.218 standalone.
197219
198 >>> for r in listSequences(cur):220 >>> for r in listSequences(cur):
199 ... print(repr(r))221 ... print(_py3ish_repr(r))
200 (u'public', u'a_aid_seq', u'a', u'aid')222 ('public', 'a_aid_seq', 'a', 'aid')
201 (u'public', u'standalone', None, None)223 ('public', 'standalone', None, None)
202224
203 """225 """
204 sql = """226 sql = """

Subscribers

People subscribed via source and target branches

to status/vote changes: