py3: port test-bugzilla.t to Python 3
Some assorted fixes required in the extension itself, all around
bytes/str issues.
Differential Revision: https://phab.mercurial-scm.org/D5680
--- a/contrib/python3-whitelist Sun Jan 20 21:49:58 2019 -0800
+++ b/contrib/python3-whitelist Thu Jan 24 13:54:45 2019 -0500
@@ -44,6 +44,7 @@
test-branch-option.t
test-branch-tag-confict.t
test-branches.t
+test-bugzilla.t
test-bundle-phases.t
test-bundle-r.t
test-bundle-type.t
--- a/hgext/bugzilla.py Sun Jan 20 21:49:58 2019 -0800
+++ b/hgext/bugzilla.py Thu Jan 24 13:54:45 2019 -0500
@@ -303,6 +303,7 @@
error,
logcmdutil,
mail,
+ pycompat,
registrar,
url,
util,
@@ -342,10 +343,10 @@
default='bugs',
)
configitem('bugzilla', 'fixregexp',
- default=(r'fix(?:es)?\s*(?:bugs?\s*)?,?\s*'
- r'(?:nos?\.?|num(?:ber)?s?)?\s*'
- r'(?P<ids>(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
- r'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?')
+ default=(br'fix(?:es)?\s*(?:bugs?\s*)?,?\s*'
+ br'(?:nos?\.?|num(?:ber)?s?)?\s*'
+ br'(?P<ids>(?:#?\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
+ br'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?')
)
configitem('bugzilla', 'fixresolution',
default='FIXED',
@@ -363,9 +364,9 @@
default=None,
)
configitem('bugzilla', 'regexp',
- default=(r'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*'
- r'(?P<ids>(?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
- r'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?')
+ default=(br'bugs?\s*,?\s*(?:#|nos?\.?|num(?:ber)?s?)?\s*'
+ br'(?P<ids>(?:\d+\s*(?:,?\s*(?:and)?)?\s*)+)'
+ br'\.?\s*(?:h(?:ours?)?\s*(?P<hours>\d*(?:\.\d+)?))?')
)
configitem('bugzilla', 'strip',
default=0,
@@ -733,7 +734,7 @@
c = self.bzproxy.Bug.comments({'ids': [id],
'include_fields': ['text'],
'token': self.bztoken})
- return ''.join([t['text'] for t in c['bugs'][str(id)]['comments']])
+ return ''.join([t['text'] for t in c['bugs']['%d' % id]['comments']])
def filter_real_bug_ids(self, bugs):
probe = self.bzproxy.Bug.get({'ids': sorted(bugs.keys()),
@@ -804,11 +805,11 @@
def makecommandline(self, fieldname, value):
if self.bzvermajor >= 4:
- return "@%s %s" % (fieldname, str(value))
+ return "@%s %s" % (fieldname, pycompat.bytestr(value))
else:
if fieldname == "id":
fieldname = "bug_id"
- return "@%s = %s" % (fieldname, str(value))
+ return "@%s = %s" % (fieldname, pycompat.bytestr(value))
def send_bug_modify_email(self, bugid, commands, comment, committer):
'''send modification message to Bugzilla bug via email.
@@ -873,7 +874,7 @@
self.fixresolution = self.ui.config('bugzilla', 'fixresolution')
def apiurl(self, targets, include_fields=None):
- url = '/'.join([self.bzroot] + [str(t) for t in targets])
+ url = '/'.join([self.bzroot] + [pycompat.bytestr(t) for t in targets])
qv = {}
if self.apikey:
qv['api_key'] = self.apikey
@@ -938,7 +939,7 @@
for bugid in bugs.keys():
burl = self.apiurl(('bug', bugid, 'comment'), include_fields='text')
result = self._fetch(burl)
- comments = result['bugs'][str(bugid)]['comments']
+ comments = result['bugs'][pycompat.bytestr(bugid)]['comments']
if any(sn in c['text'] for c in comments):
self.ui.status(_('bug %d already knows about changeset %s\n') %
(bugid, sn))
@@ -1011,7 +1012,7 @@
self.ui.config('bugzilla', 'regexp'), re.IGNORECASE)
self.fix_re = re.compile(
self.ui.config('bugzilla', 'fixregexp'), re.IGNORECASE)
- self.split_re = re.compile(r'\D+')
+ self.split_re = re.compile(br'\D+')
def find_bugs(self, ctx):
'''return bugs dictionary created from commit comment.
@@ -1098,7 +1099,7 @@
t = logcmdutil.changesettemplater(self.ui, self.repo, spec)
self.ui.pushbuffer()
t.show(ctx, changes=ctx.changeset(),
- bug=str(bugid),
+ bug=pycompat.bytestr(bugid),
hgweb=self.ui.config('web', 'baseurl'),
root=self.repo.root,
webroot=webroot(self.repo.root))
--- a/tests/test-bugzilla.t Sun Jan 20 21:49:58 2019 -0800
+++ b/tests/test-bugzilla.t Thu Jan 24 13:54:45 2019 -0500
@@ -3,7 +3,9 @@
$ cat <<EOF > bzmock.py
> from __future__ import absolute_import
> from mercurial import extensions
+ > from mercurial import pycompat
> from mercurial import registrar
+ > from mercurial.utils import stringutil
>
> configtable = {}
> configitem = registrar.configitem(configtable)
@@ -18,14 +20,17 @@
> super(bzmock, self).__init__(ui)
> self._logfile = ui.config(b'bugzilla', b'mocklog')
> def updatebug(self, bugid, newstate, text, committer):
- > with open(self._logfile, 'a') as f:
- > f.write('update bugid=%r, newstate=%r, committer=%r\n'
- > % (bugid, newstate, committer))
- > f.write('----\n' + text + '\n----\n')
+ > with open(pycompat.fsdecode(self._logfile), 'ab') as f:
+ > f.write(b'update bugid=%s, newstate=%s, committer=%s\n'
+ > % (stringutil.pprint(bugid),
+ > stringutil.pprint(newstate),
+ > stringutil.pprint(committer)))
+ > f.write(b'----\n' + text + b'\n----\n')
> def notify(self, bugs, committer):
- > with open(self._logfile, 'a') as f:
- > f.write('notify bugs=%r, committer=%r\n'
- > % (bugs, committer))
+ > with open(pycompat.fsdecode(self._logfile), 'ab') as f:
+ > f.write(b'notify bugs=%s, committer=%s\n'
+ > % (stringutil.pprint(bugs),
+ > stringutil.pprint(committer)))
> bugzilla.bugzilla._versions[b'mock'] = bzmock
> EOF