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 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
1diff --git a/lib/lp/registry/browser/tests/karmacontext-views.txt b/lib/lp/registry/browser/tests/karmacontext-views.txt
2index 3546713..e412bba 100644
3--- a/lib/lp/registry/browser/tests/karmacontext-views.txt
4+++ b/lib/lp/registry/browser/tests/karmacontext-views.txt
5@@ -15,18 +15,25 @@ contributors on a given context and the top contributors by category.
6 >>> view = create_initialized_view(
7 ... product, '+topcontributors', principal=user)
8 >>> contributors = view._getTopContributorsWithLimit(limit=3)
9- >>> [(contrib.person.name, contrib.karmavalue)
10- ... for contrib in contributors]
11- [(u'name16', 175), (u'mark', 22), (u'carlos', 9)]
12+ >>> for contrib in contributors:
13+ ... print(contrib.person.name, contrib.karmavalue)
14+ name16 175
15+ mark 22
16+ carlos 9
17
18 >>> contributors = view.top_contributors_by_category
19 >>> categories = sorted(contributors.keys())
20 >>> for category in categories:
21- ... print(category, [(contrib.person.name, contrib.karmavalue)
22- ... for contrib in contributors[category]])
23- Bug Management [(u'name16', 11)]
24- Specification Tracking [(u'mark', 22)]
25- Translations in Rosetta [(u'name16', 164), (u'carlos', 9)]
26+ ... print(category)
27+ ... for contrib in contributors[category]:
28+ ... print(contrib.person.name, contrib.karmavalue)
29+ Bug Management
30+ name16 11
31+ Specification Tracking
32+ mark 22
33+ Translations in Rosetta
34+ name16 164
35+ carlos 9
36
37 The view renders summaries by category.
38
39diff --git a/lib/lp/services/database/postgresql.py b/lib/lp/services/database/postgresql.py
40index a3fae61..b735476 100644
41--- a/lib/lp/services/database/postgresql.py
42+++ b/lib/lp/services/database/postgresql.py
43@@ -21,6 +21,28 @@ from lp.services.database.sqlbase import (
44 )
45
46
47+def _py3ish_repr(value):
48+ """Like `repr`, but uses Python 3 spelling of text.
49+
50+ This is a local helper for doctests.
51+ """
52+ if isinstance(value, six.text_type):
53+ value = value.encode('unicode_escape').decode('ASCII')
54+ if "'" in value and '"' not in value:
55+ return '"%s"' % value
56+ else:
57+ return "'%s'" % value.replace("'", "\\'")
58+ elif isinstance(value, tuple):
59+ if len(value) == 1:
60+ return '(' + _py3ish_repr(value[0]) + ',)'
61+ else:
62+ return '(' + ', '.join(_py3ish_repr(item) for item in value) + ')'
63+ elif isinstance(value, list):
64+ return '[' + ', '.join(_py3ish_repr(item) for item in value) + ']'
65+ else:
66+ return repr(value)
67+
68+
69 def listReferences(cur, table, column, indirect=True, _state=None):
70 """Return a list of all foreign key references to the given table column
71
72@@ -43,11 +65,11 @@ def listReferences(cur, table, column, indirect=True, _state=None):
73 to change keys.
74
75 >>> for r in listReferences(cur, 'a', 'aid'):
76- ... print(repr(r))
77- (u'a', u'selfref', u'a', u'aid', u'a', u'a')
78- (u'b', u'aid', u'a', u'aid', u'c', u'c')
79- (u'c', u'aid', u'b', u'aid', u'a', u'a')
80- (u'd', u'aid', u'b', u'aid', u'a', u'a')
81+ ... print(_py3ish_repr(r))
82+ ('a', 'selfref', 'a', 'aid', 'a', 'a')
83+ ('b', 'aid', 'a', 'aid', 'c', 'c')
84+ ('c', 'aid', 'b', 'aid', 'a', 'a')
85+ ('d', 'aid', 'b', 'aid', 'a', 'a')
86
87 Of course, there might not be any references
88
89@@ -115,27 +137,27 @@ def listUniques(cur, table, column):
90
91 Simple UNIQUE index
92
93- >>> listUniques(cur, 'b', 'aid')
94- [(u'aid',)]
95+ >>> print(_py3ish_repr(listUniques(cur, 'b', 'aid')))
96+ [('aid',)]
97
98 Primary keys are UNIQUE indexes too
99
100- >>> listUniques(cur, 'a', 'aid')
101- [(u'aid',)]
102+ >>> print(_py3ish_repr(listUniques(cur, 'a', 'aid')))
103+ [('aid',)]
104
105 Compound indexes
106
107- >>> listUniques(cur, 'c', 'aid')
108- [(u'aid', u'bid')]
109- >>> listUniques(cur, 'c', 'bid')
110- [(u'aid', u'bid')]
111+ >>> print(_py3ish_repr(listUniques(cur, 'c', 'aid')))
112+ [('aid', 'bid')]
113+ >>> print(_py3ish_repr(listUniques(cur, 'c', 'bid')))
114+ [('aid', 'bid')]
115
116 And any combination
117
118 >>> l = listUniques(cur, 'd', 'aid')
119 >>> l.sort()
120- >>> l
121- [(u'aid',), (u'aid', u'bid')]
122+ >>> print(_py3ish_repr(l))
123+ [('aid',), ('aid', 'bid')]
124
125 If there are no UNIQUE indexes using the secified column
126
127@@ -196,9 +218,9 @@ def listSequences(cur):
128 standalone.
129
130 >>> for r in listSequences(cur):
131- ... print(repr(r))
132- (u'public', u'a_aid_seq', u'a', u'aid')
133- (u'public', u'standalone', None, None)
134+ ... print(_py3ish_repr(r))
135+ ('public', 'a_aid_seq', 'a', 'aid')
136+ ('public', 'standalone', None, None)
137
138 """
139 sql = """

Subscribers

People subscribed via source and target branches

to status/vote changes: