launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #21897
[Merge] lp:~cjwatson/launchpad/code-bzr-tests-future-imports into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/code-bzr-tests-future-imports into lp:launchpad with lp:~cjwatson/launchpad/code-git-tests-future-imports as a prerequisite.
Commit message:
Convert closely-Bazaar-related tests under lp.code.model.tests to Launchpad's preferred __future__ imports.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/code-bzr-tests-future-imports/+merge/331762
We need to take some care to keep revision IDs and file texts as bytes.
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/code-bzr-tests-future-imports into lp:launchpad.
=== modified file 'lib/lp/code/model/tests/test_branch.py'
--- lib/lp/code/model/tests/test_branch.py 2016-10-15 02:28:10 +0000
+++ lib/lp/code/model/tests/test_branch.py 2017-10-04 01:52:47 +0000
@@ -1,8 +1,9 @@
-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for Branches."""
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
@@ -335,7 +336,7 @@
self.useBzrBranches()
db_branch, bzr_tree = self.create_branch_and_tree()
bzr_tree.commit(
- 'First commit', rev_id='rev1', committer='me@xxxxxxxxxxx')
+ 'First commit', rev_id=b'rev1', committer='me@xxxxxxxxxxx')
with person_logged_in(db_branch.owner):
db_branch.branchChanged(None, 'rev1', None, None, None)
with block_on_job():
@@ -347,7 +348,7 @@
self.useBzrBranches()
db_branch, bzr_tree = self.create_branch_and_tree()
bzr_tree.commit(
- 'First commit', rev_id='rev1', committer='me@xxxxxxxxxxx')
+ 'First commit', rev_id=b'rev1', committer='me@xxxxxxxxxxx')
with person_logged_in(db_branch.owner):
db_branch.branchChanged(None, 'rev1', None, None, None)
with monitor_celery() as responses:
@@ -1941,7 +1942,7 @@
def test_attributeAssignment(self):
"""Smoke test to make sure the assignments are there."""
- commit_message = u'Some commit message'
+ commit_message = 'Some commit message'
proposal = self.source.addLandingTarget(
self.user, self.target, self.prerequisite,
commit_message=commit_message)
=== modified file 'lib/lp/code/model/tests/test_branchjob.py'
--- lib/lp/code/model/tests/test_branchjob.py 2016-02-04 12:21:45 +0000
+++ lib/lp/code/model/tests/test_branchjob.py 2017-10-04 01:52:47 +0000
@@ -1,8 +1,10 @@
-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for BranchJobs."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
import datetime
@@ -147,9 +149,9 @@
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
# required to generate the revision-id.
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
- bzr_tree.commit('First commit', rev_id='rev1')
- bzr_tree.commit('Second commit', rev_id='rev2')
- bzr_tree.commit('Third commit', rev_id='rev3')
+ bzr_tree.commit('First commit', rev_id=b'rev1')
+ bzr_tree.commit('Second commit', rev_id=b'rev2')
+ bzr_tree.commit('Third commit', rev_id=b'rev3')
LaunchpadZopelessLayer.commit()
job = BranchScanJob.create(db_branch)
@@ -158,8 +160,8 @@
self.assertEqual(db_branch.revision_count, 3)
- bzr_tree.commit('Fourth commit', rev_id='rev4')
- bzr_tree.commit('Fifth commit', rev_id='rev5')
+ bzr_tree.commit('Fourth commit', rev_id=b'rev4')
+ bzr_tree.commit('Fifth commit', rev_id=b'rev5')
job = BranchScanJob.create(db_branch)
with dbuser("branchscanner"):
@@ -175,7 +177,7 @@
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
# required to generate the revision-id.
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
- bzr_tree.commit('First commit', rev_id='rev1')
+ bzr_tree.commit('First commit', rev_id=b'rev1')
LaunchpadZopelessLayer.commit()
expected_message = (
@@ -194,10 +196,10 @@
product = self.factory.makeProduct()
private_bug = self.factory.makeBug(
target=product, information_type=InformationType.USERDATA)
- bug_line = 'https://launchpad.net/bugs/%s fixed' % private_bug.id
+ bug_line = b'https://launchpad.net/bugs/%s fixed' % private_bug.id
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
bzr_tree.commit(
- 'First commit', rev_id='rev1', revprops={'bugs': bug_line})
+ 'First commit', rev_id=b'rev1', revprops={b'bugs': bug_line})
job = BranchScanJob.create(db_branch)
with dbuser("branchscanner"):
job.run()
@@ -435,12 +437,12 @@
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
# required to generate the revision-id.
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
- tree.commit('rev1', rev_id='rev1')
- tree.commit('rev2', rev_id='rev2')
- tree.commit('rev3', rev_id='rev3')
+ tree.commit('rev1', rev_id=b'rev1')
+ tree.commit('rev2', rev_id=b'rev2')
+ tree.commit('rev3', rev_id=b'rev3')
switch_dbuser('branchscanner')
self.updateDBRevisions(
- branch, tree.branch, ['rev1', 'rev2', 'rev3'])
+ branch, tree.branch, [b'rev1', b'rev2', b'rev3'])
finally:
tree.unlock()
return branch, tree
@@ -459,18 +461,18 @@
"""iterAddedMainline drops non-mainline revisions."""
self.useBzrBranches(direct_database=True)
branch, tree = self.create3CommitsBranch()
- tree.pull(tree.branch, overwrite=True, stop_revision='rev2')
- tree.add_parent_tree_id('rev3')
+ tree.pull(tree.branch, overwrite=True, stop_revision=b'rev2')
+ tree.add_parent_tree_id(b'rev3')
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
# required to generate the revision-id.
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
- tree.commit('rev3a', rev_id='rev3a')
- self.updateDBRevisions(branch, tree.branch, ['rev3', 'rev3a'])
+ tree.commit('rev3a', rev_id=b'rev3a')
+ self.updateDBRevisions(branch, tree.branch, [b'rev3', b'rev3a'])
job = RevisionsAddedJob.create(branch, 'rev1', 'rev3', '')
job.bzr_branch.lock_read()
self.addCleanup(job.bzr_branch.unlock)
out = [x.revision_id for x, y in job.iterAddedMainline()]
- self.assertEqual(['rev2'], out)
+ self.assertEqual([b'rev2'], out)
def test_iterAddedMainline_order(self):
"""iterAddedMainline iterates in commit order."""
@@ -481,9 +483,9 @@
self.addCleanup(job.bzr_branch.unlock)
# Since we've gone from rev1 to rev3, we've added rev2 and rev3.
[(rev2, revno2), (rev3, revno3)] = list(job.iterAddedMainline())
- self.assertEqual('rev2', rev2.revision_id)
+ self.assertEqual(b'rev2', rev2.revision_id)
self.assertEqual(2, revno2)
- self.assertEqual('rev3', rev3.revision_id)
+ self.assertEqual(b'rev3', rev3.revision_id)
self.assertEqual(3, revno3)
def makeBranchWithCommit(self):
@@ -506,7 +508,7 @@
# required to generate the revision-id.
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
tree.commit(
- 'rev1', rev_id='rev1', timestamp=1000, timezone=0,
+ 'rev1', rev_id=b'rev1', timestamp=1000, timezone=0,
committer='J. Random Hacker <jrandom@xxxxxxxxxxx>')
return branch, tree
@@ -526,16 +528,16 @@
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
tree.commit('rev1')
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
- tree2.commit('rev2a', rev_id='rev2a-id', committer='foo@')
- tree2.commit('rev3', rev_id='rev3-id',
+ tree2.commit('rev2a', rev_id=b'rev2a-id', committer='foo@')
+ tree2.commit('rev3', rev_id=b'rev3-id',
authors=['bar@', 'baz@xxxxxxxxxx'])
tree.merge_from_branch(tree2.branch)
tree3 = tree.bzrdir.sprout('tree3').open_workingtree()
- tree3.commit('rev2b', rev_id='rev2b-id', committer='qux@')
+ tree3.commit('rev2b', rev_id=b'rev2b-id', committer='qux@')
tree.merge_from_branch(tree3.branch, force=True)
if include_ghost:
- tree.add_parent_tree_id('rev2c-id')
- tree.commit('rev2d', rev_id='rev2d-id', timestamp=1000,
+ tree.add_parent_tree_id(b'rev2c-id')
+ tree.commit('rev2d', rev_id=b'rev2d-id', timestamp=1000,
timezone=0, authors=authors,
committer='J. Random Hacker <jrandom@xxxxxxxxxxx>')
return RevisionsAddedJob.create(branch, 'rev2d-id', 'rev2d-id', '')
@@ -546,8 +548,9 @@
job.bzr_branch.lock_write()
graph = job.bzr_branch.repository.get_graph()
self.addCleanup(job.bzr_branch.unlock)
- self.assertEqual(set(['rev2a-id', 'rev3-id', 'rev2b-id', 'rev2c-id']),
- job.getMergedRevisionIDs('rev2d-id', graph))
+ self.assertEqual(
+ set([b'rev2a-id', b'rev3-id', b'rev2b-id', b'rev2c-id']),
+ job.getMergedRevisionIDs('rev2d-id', graph))
def test_findRelatedBMP(self):
"""The related branch merge proposals can be identified."""
@@ -591,7 +594,7 @@
job.bzr_branch.lock_write()
self.addCleanup(job.bzr_branch.unlock)
graph = job.bzr_branch.repository.get_graph()
- revision_ids = ['rev2a-id', 'rev3-id', 'rev2b-id']
+ revision_ids = [b'rev2a-id', b'rev3-id', b'rev2b-id']
self.assertEqual(set(['foo@', 'bar@', 'baz@xxxxxxxxxx', 'qux@']),
job.getAuthors(revision_ids, graph))
@@ -601,7 +604,7 @@
job.bzr_branch.lock_write()
graph = job.bzr_branch.repository.get_graph()
self.addCleanup(job.bzr_branch.unlock)
- revision_ids = ['rev2a-id', 'rev3-id', 'rev2b-id', 'rev2c-id']
+ revision_ids = [b'rev2a-id', b'rev3-id', b'rev2b-id', b'rev2c-id']
self.assertEqual(set(['foo@', 'bar@', 'baz@xxxxxxxxxx', 'qux@']),
job.getAuthors(revision_ids, graph))
@@ -610,7 +613,7 @@
self.useBzrBranches(direct_database=True)
branch, tree = self.makeBranchWithCommit()
job = RevisionsAddedJob.create(branch, 'rev1', 'rev1', '')
- message = job.getRevisionMessage('rev1', 1)
+ message = job.getRevisionMessage(b'rev1', 1)
self.assertEqual(
'------------------------------------------------------------\n'
'revno: 1\n'
@@ -627,9 +630,9 @@
email='baz@xxxxxxxxxx',
email_address_status=EmailAddressStatus.VALIDATED)
job = self.makeRevisionsAddedWithMergeCommit()
- message = job.getRevisionMessage('rev2d-id', 1)
+ message = job.getRevisionMessage(b'rev2d-id', 1)
self.assertEqual(
- u'Merge authors:\n'
+ 'Merge authors:\n'
' bar@\n'
' Basil Blaine (baz)\n'
' foo@\n'
@@ -645,7 +648,7 @@
def test_getRevisionMessage_with_merge_authors_and_authors(self):
"""Merge authors are separate from normal authors."""
job = self.makeRevisionsAddedWithMergeCommit(authors=['quxx'])
- message = job.getRevisionMessage('rev2d-id', 1)
+ message = job.getRevisionMessage(b'rev2d-id', 1)
self.assertEqual(
'Merge authors:\n'
' bar@\n'
@@ -674,7 +677,7 @@
"""Information about related proposals is displayed."""
job, bmp = self.makeJobAndBMP()
with dbuser('send-branch-mail'):
- message = job.getRevisionMessage('rev2d-id', 1)
+ message = job.getRevisionMessage(b'rev2d-id', 1)
self.assertEqual(
'Merge authors:\n'
' bar@\n'
@@ -697,7 +700,7 @@
job, bmp = self.makeJobAndBMP()
bmp2 = bmp.resubmit(bmp.registrant)
with dbuser('send-branch-mail'):
- message = job.getRevisionMessage('rev2d-id', 1)
+ message = job.getRevisionMessage(b'rev2d-id', 1)
self.assertEqual(
'Merge authors:\n'
' bar@\n'
@@ -725,7 +728,7 @@
reviewer = self.factory.makePerson()
bmp.nominateReviewer(reviewer, bmp.registrant)
with dbuser('send-branch-mail'):
- message = job.getRevisionMessage('rev2d-id', 1)
+ message = job.getRevisionMessage(b'rev2d-id', 1)
self.assertEqual(
'Merge authors:\n'
' bar@\n'
@@ -755,7 +758,7 @@
registrant=hacker)
bmp.rejectBranch(reviewer, 'rev3-id')
bmp.source_branch.last_scanned_id = 'rev3-id'
- message = job.getRevisionMessage('rev2d-id', 1)
+ message = job.getRevisionMessage(b'rev2d-id', 1)
self.assertEqual(
'Merge authors:\n'
' bar@\n'
@@ -777,7 +780,7 @@
"""Contents of the email are as expected."""
self.useBzrBranches(direct_database=True)
db_branch, tree = self.create_branch_and_tree()
- first_revision = 'rev-1'
+ first_revision = b'rev-1'
tree.bzrdir.root_transport.put_bytes('hello.txt', 'Hello World\n')
tree.add('hello.txt')
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
@@ -789,7 +792,7 @@
timestamp=1000000000.0, timezone=0)
tree.bzrdir.root_transport.put_bytes(
'hello.txt', 'Hello World\n\nFoo Bar\n')
- second_revision = 'rev-2'
+ second_revision = b'rev-2'
tree.commit(
rev_id=second_revision, message="Extended contents",
committer="Joe Bloggs <joe@xxxxxxxxxxx>",
@@ -798,30 +801,30 @@
self.updateDBRevisions(db_branch, tree.branch,
branch_revision_history(tree.branch))
expected = (
- u"-" * 60 + '\n'
- "revno: 1" '\n'
- "committer: Joe Bloggs <joe@xxxxxxxxxxx>" '\n'
- "branch nick: %s" '\n'
- "timestamp: Sun 2001-09-09 01:46:40 +0000" '\n'
- "message:" '\n'
- " Log message" '\n'
- "added:" '\n'
- " hello.txt" '\n' % tree.branch.nick)
+ "-" * 60 + '\n'
+ "revno: 1\n"
+ "committer: Joe Bloggs <joe@xxxxxxxxxxx>\n"
+ "branch nick: %s\n"
+ "timestamp: Sun 2001-09-09 01:46:40 +0000\n"
+ "message:\n"
+ " Log message\n"
+ "added:\n"
+ " hello.txt\n" % tree.branch.nick)
job = RevisionsAddedJob.create(db_branch, '', '', '')
switch_dbuser(config.IRevisionsAddedJobSource.dbuser)
self.assertEqual(
job.getRevisionMessage(first_revision, 1), expected)
expected_message = (
- u"-" * 60 + '\n'
- "revno: 2" '\n'
- "committer: Joe Bloggs <joe@xxxxxxxxxxx>" '\n'
- "branch nick: %s" '\n'
- "timestamp: Mon 2001-09-10 05:33:20 +0000" '\n'
- "message:" '\n'
- " Extended contents" '\n'
- "modified:" '\n'
- " hello.txt" '\n' % tree.branch.nick)
+ "-" * 60 + '\n'
+ "revno: 2\n"
+ "committer: Joe Bloggs <joe@xxxxxxxxxxx>\n"
+ "branch nick: %s\n"
+ "timestamp: Mon 2001-09-10 05:33:20 +0000\n"
+ "message:\n"
+ " Extended contents\n"
+ "modified:\n"
+ " hello.txt\n" % tree.branch.nick)
tree.branch.lock_read()
tree.branch.unlock()
message = job.getRevisionMessage(second_revision, 2)
@@ -831,13 +834,13 @@
"""Test handling of non-ASCII commit messages."""
self.useBzrBranches(direct_database=True)
db_branch, tree = self.create_branch_and_tree()
- rev_id = 'rev-1'
+ rev_id = b'rev-1'
# XXX: AaronBentley 2010-08-06 bug=614404: a bzr username is
# required to generate the revision-id.
with override_environ(BZR_EMAIL='me@xxxxxxxxxxx'):
tree.commit(
- rev_id=rev_id, message=u"Non ASCII: \xe9",
- committer=u"Non ASCII: \xed", timestamp=1000000000.0,
+ rev_id=rev_id, message="Non ASCII: \xe9",
+ committer="Non ASCII: \xed", timestamp=1000000000.0,
timezone=0)
switch_dbuser('branchscanner')
self.updateDBRevisions(db_branch, tree.branch,
@@ -847,20 +850,20 @@
message = job.getRevisionMessage(rev_id, 1)
# The revision message must be a unicode object.
expected = (
- u'-' * 60 + '\n'
- u"revno: 1" '\n'
- u"committer: Non ASCII: \xed" '\n'
- u"branch nick: %s" '\n'
- u"timestamp: Sun 2001-09-09 01:46:40 +0000" '\n'
- u"message:" '\n'
- u" Non ASCII: \xe9" '\n' % tree.branch.nick)
+ '-' * 60 + '\n'
+ "revno: 1\n"
+ "committer: Non ASCII: \xed\n"
+ "branch nick: %s\n"
+ "timestamp: Sun 2001-09-09 01:46:40 +0000\n"
+ "message:\n"
+ " Non ASCII: \xe9\n" % tree.branch.nick)
self.assertEqual(message, expected)
def test_getMailerForRevision(self):
"""The mailer for the revision is as expected."""
self.useBzrBranches(direct_database=True)
branch, tree = self.makeBranchWithCommit()
- revision = tree.branch.repository.get_revision('rev1')
+ revision = tree.branch.repository.get_revision(b'rev1')
job = RevisionsAddedJob.create(branch, 'rev1', 'rev1', '')
mailer = job.getMailerForRevision(revision, 1, True)
subject = mailer.generateEmail(
@@ -1016,9 +1019,9 @@
# The method _init_translation_file_lists extracts all translation
# files from the branch but does not add changed directories to the
# template_files_changed and translation_files_changed lists .
- pot_path = u"subdir/foo.pot"
+ pot_path = "subdir/foo.pot"
pot_content = self.factory.getUniqueString()
- po_path = u"subdir/foo.po"
+ po_path = "subdir/foo.po"
po_content = self.factory.getUniqueString()
self._makeBranchWithTreeAndFiles(((pot_path, pot_content),
(po_path, po_content)))
=== modified file 'lib/lp/code/model/tests/test_diff.py'
--- lib/lp/code/model/tests/test_diff.py 2016-09-07 11:12:58 +0000
+++ lib/lp/code/model/tests/test_diff.py 2017-10-04 01:52:47 +0000
@@ -1,8 +1,10 @@
-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for Diff, etc."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from cStringIO import StringIO
@@ -90,10 +92,10 @@
test_case.factory.makeRevisionsForBranch(bmp.source_branch)
test_case.factory.makeRevisionsForBranch(bmp.target_branch)
bzr_target = test_case.createBzrBranch(bmp.target_branch)
- commit_file(bmp.target_branch, 'foo', 'a\n')
+ commit_file(bmp.target_branch, 'foo', b'a\n')
test_case.createBzrBranch(bmp.source_branch, bzr_target)
- source_rev_id = commit_file(bmp.source_branch, 'foo', 'd\na\nb\n')
- target_rev_id = commit_file(bmp.target_branch, 'foo', 'c\na\n')
+ source_rev_id = commit_file(bmp.source_branch, 'foo', b'd\na\nb\n')
+ target_rev_id = commit_file(bmp.target_branch, 'foo', b'c\na\n')
return bmp, source_rev_id, target_rev_id
@@ -128,14 +130,14 @@
source = bmp.source_branch
prerequisite = bmp.prerequisite_branch
target_bzr = self.createBzrBranch(target)
- commit_file(target, 'file', 'target text\n')
+ commit_file(target, 'file', b'target text\n')
prerequisite_bzr = self.createBzrBranch(prerequisite, target_bzr)
commit_file(
- prerequisite, 'file', 'target text\nprerequisite text\n')
+ prerequisite, 'file', b'target text\nprerequisite text\n')
source_bzr = self.createBzrBranch(source, prerequisite_bzr)
source_rev_id = commit_file(
source, 'file',
- 'target text\nprerequisite text\nsource text\n')
+ b'target text\nprerequisite text\nsource text\n')
return (source_bzr, source_rev_id, target_bzr, prerequisite_bzr,
prerequisite)
@@ -290,7 +292,7 @@
"-b\n"
" c\n"
"+d\n"
- "+e\n")
+ "+e\n").encode("UTF-8")
diff_bytes_2 = (
"--- bar\t2009-08-26 15:53:34.000000000 -0400\n"
@@ -312,7 +314,7 @@
" c\n"
"+d\n"
"+e\n"
- "+f\n")
+ "+f\n").encode("UTF-8")
def test_mergePreviewWithPrerequisite(self):
# Changes introduced in the prerequisite branch are ignored.
@@ -329,8 +331,7 @@
# affect the diff.
(source_bzr, source_rev_id, target_bzr, prerequisite_bzr,
prerequisite) = self.preparePrerequisiteMerge()
- commit_file(
- prerequisite, 'file', 'prerequisite text2\n')
+ commit_file(prerequisite, 'file', b'prerequisite text2\n')
diff, conflicts = Diff.mergePreviewFromBranches(
source_bzr, source_rev_id, target_bzr, prerequisite_bzr)
transaction.commit()
@@ -348,7 +349,7 @@
"--- foo\t2009-08-26 15:53:23.000000000 -0400\n"
"+++ foo\t2009-08-26 15:56:43.000000000 -0400\n"
"@@ -1,1 +1,1 @@\n"
- " a\r-b\r c\r+d\r+e\r+f\r")
+ " a\r-b\r c\r+d\r+e\r+f\r").encode("UTF-8")
self.assertEqual({'foo': (0, 0)}, Diff.generateDiffstat(diff_bytes))
def test_fromFileSetsDiffstat(self):
@@ -357,7 +358,7 @@
{'bar': (0, 3), 'baz': (2, 0), 'foo': (2, 1)}, diff.diffstat)
def test_fromFileAcceptsBinary(self):
- diff_bytes = "Binary files a\t and b\t differ\n"
+ diff_bytes = b"Binary files a\t and b\t differ\n"
diff = Diff.fromFile(StringIO(diff_bytes), len(diff_bytes))
self.assertEqual({}, diff.diffstat)
@@ -371,7 +372,7 @@
def test_fromFile_withError(self):
# If the diff is formatted such that generating the diffstat fails, we
# want to record an oops but continue.
- diff_bytes = "not a real diff"
+ diff_bytes = b"not a real diff"
diff = Diff.fromFile(StringIO(diff_bytes), len(diff_bytes))
oops = self.oopses[0]
self.assertEqual('MalformedPatchHeader', oops['type'])
@@ -394,11 +395,11 @@
if prerequisite_branch is None:
prerequisite_revision_id = None
else:
- prerequisite_revision_id = u'rev-c'
+ prerequisite_revision_id = 'rev-c'
if content is None:
content = ''.join(unified_diff('', 'content'))
mp.updatePreviewDiff(
- content, u'rev-a', u'rev-b',
+ content, 'rev-a', 'rev-b',
prerequisite_revision_id=prerequisite_revision_id)
# Make sure the librarian file is written.
transaction.commit()
@@ -412,11 +413,11 @@
if merge_prerequisite is None:
prerequisite_revision_id = None
else:
- prerequisite_revision_id = u"c" * 40
+ prerequisite_revision_id = "c" * 40
if content is None:
content = "".join(unified_diff("", "content"))
mp.updatePreviewDiff(
- content, u"a" * 40, u"b" * 40,
+ content, "a" * 40, "b" * 40,
prerequisite_revision_id=prerequisite_revision_id)
# Make sure the librarian file is written.
transaction.commit()
@@ -523,10 +524,10 @@
self.useBzrBranches(direct_database=True)
bmp = self.factory.makeBranchMergeProposal()
bzr_target = self.createBzrBranch(bmp.target_branch)
- commit_file(bmp.target_branch, 'foo', 'a\n')
+ commit_file(bmp.target_branch, 'foo', b'a\n')
self.createBzrBranch(bmp.source_branch, bzr_target)
- commit_file(bmp.source_branch, 'foo', 'a\nb\n')
- commit_file(bmp.target_branch, 'foo', 'c\na\n')
+ commit_file(bmp.source_branch, 'foo', b'a\nb\n')
+ commit_file(bmp.target_branch, 'foo', b'c\na\n')
diff = PreviewDiff.fromBranchMergeProposal(bmp)
self.assertEqual('', diff.conflicts)
self.assertFalse(diff.has_conflicts)
@@ -657,23 +658,23 @@
bmp = self.factory.makeBranchMergeProposal(
prerequisite_branch=prerequisite_branch)
target_branch = self.createBzrBranch(bmp.target_branch)
- old_revision_id = commit_file(bmp.target_branch, 'foo', 'a\nb\ne\n')
+ old_revision_id = commit_file(bmp.target_branch, 'foo', b'a\nb\ne\n')
old_revision = self.factory.makeRevision(rev_id=old_revision_id)
source_branch = self.createBzrBranch(
bmp.source_branch, target_branch)
- commit_file(bmp.source_branch, 'foo', 'a\nc\ne\n')
+ commit_file(bmp.source_branch, 'foo', b'a\nc\ne\n')
prerequisite = self.createBzrBranch(
bmp.prerequisite_branch, target_branch)
prerequisite_revision = commit_file(
- bmp.prerequisite_branch, 'foo', 'd\na\nb\ne\n')
- merge_parent = commit_file(bmp.target_branch, 'foo', 'a\nb\ne\nf\n')
+ bmp.prerequisite_branch, 'foo', b'd\na\nb\ne\n')
+ merge_parent = commit_file(bmp.target_branch, 'foo', b'a\nb\ne\nf\n')
source_branch.repository.fetch(target_branch.repository,
revision_id=merge_parent)
- commit_file(bmp.source_branch, 'foo', 'a\nc\ne\nf\n', [merge_parent])
+ commit_file(bmp.source_branch, 'foo', b'a\nc\ne\nf\n', [merge_parent])
source_branch.repository.fetch(prerequisite.repository,
revision_id=prerequisite_revision)
new_revision_id = commit_file(
- bmp.source_branch, 'foo', 'd\na\nc\ne\nf\n',
+ bmp.source_branch, 'foo', b'd\na\nc\ne\nf\n',
[prerequisite_revision])
new_revision = self.factory.makeRevision(rev_id=new_revision_id)
incremental_diff = bmp.generateIncrementalDiff(
=== modified file 'lib/lp/code/model/tests/test_revision.py'
--- lib/lp/code/model/tests/test_revision.py 2015-01-29 14:14:01 +0000
+++ lib/lp/code/model/tests/test_revision.py 2017-10-04 01:52:47 +0000
@@ -1,8 +1,10 @@
-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for Revisions."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from datetime import (
@@ -228,11 +230,11 @@
self.becomeDbUser('branchscanner')
bzr_revisions = [
self.factory.makeBzrRevision(
- 'rev-1',
+ b'rev-1',
props={
'prop1': 'foo', 'deb-pristine-delta': 'bar',
'deb-pristine-delta-xz': 'baz'}),
- self.factory.makeBzrRevision('rev-2', parent_ids=['rev-1'])
+ self.factory.makeBzrRevision(b'rev-2', parent_ids=[b'rev-1'])
]
with StormStatementRecorder() as recorder:
self.revision_set.newFromBazaarRevisions(bzr_revisions)
=== modified file 'lib/lp/code/tests/test_bzr.py'
--- lib/lp/code/tests/test_bzr.py 2012-06-28 01:14:33 +0000
+++ lib/lp/code/tests/test_bzr.py 2017-10-04 01:52:47 +0000
@@ -1,8 +1,10 @@
-# Copyright 2010 Canonical Ltd. This software is licensed under the
+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for lp.code.bzr."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from bzrlib.errors import NoSuchRevision
@@ -88,11 +90,11 @@
def test_some_commits(self):
branch = self.make_branch('test')
tree = branch.bzrdir.create_workingtree()
- tree.commit('acommit', rev_id='A')
- tree.commit('bcommit', rev_id='B')
- tree.commit('ccommit', rev_id='C')
+ tree.commit('acommit', rev_id=b'A')
+ tree.commit('bcommit', rev_id=b'B')
+ tree.commit('ccommit', rev_id=b'C')
self.assertEquals(
- ['A', 'B', 'C'], branch_revision_history(tree.branch))
+ [b'A', b'B', b'C'], branch_revision_history(tree.branch))
class TestGetAncestry(TestCaseWithTransport):
@@ -102,36 +104,36 @@
# If the revision does not exist, NoSuchRevision should be raised.
branch = self.make_branch('test')
self.assertRaises(
- NoSuchRevision, get_ancestry, branch.repository, 'orphan')
+ NoSuchRevision, get_ancestry, branch.repository, b'orphan')
def test_some(self):
# Verify ancestors are included.
branch = self.make_branch('test')
tree = branch.bzrdir.create_workingtree()
- tree.commit('msg a', rev_id='A')
- tree.commit('msg b', rev_id='B')
- tree.commit('msg c', rev_id='C')
- self.assertEqual(
- set(['A']), get_ancestry(branch.repository, 'A'))
- self.assertEqual(
- set(['A', 'B']), get_ancestry(branch.repository, 'B'))
- self.assertEqual(
- set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))
+ tree.commit('msg a', rev_id=b'A')
+ tree.commit('msg b', rev_id=b'B')
+ tree.commit('msg c', rev_id=b'C')
+ self.assertEqual(
+ set([b'A']), get_ancestry(branch.repository, b'A'))
+ self.assertEqual(
+ set([b'A', b'B']), get_ancestry(branch.repository, b'B'))
+ self.assertEqual(
+ set([b'A', b'B', b'C']), get_ancestry(branch.repository, b'C'))
def test_children(self):
# Verify non-mainline children are included.
branch = self.make_branch('test')
tree = branch.bzrdir.create_workingtree()
- tree.commit('msg a', rev_id='A')
+ tree.commit('msg a', rev_id=b'A')
branch.generate_revision_history(NULL_REVISION)
tree.set_parent_ids([])
- tree.commit('msg b', rev_id='B')
- branch.generate_revision_history('A')
- tree.set_parent_ids(['A', 'B'])
- tree.commit('msg c', rev_id='C')
- self.assertEqual(
- set(['A']), get_ancestry(branch.repository, 'A'))
- self.assertEqual(
- set(['B']), get_ancestry(branch.repository, 'B'))
- self.assertEqual(
- set(['A', 'B', 'C']), get_ancestry(branch.repository, 'C'))
+ tree.commit('msg b', rev_id=b'B')
+ branch.generate_revision_history(b'A')
+ tree.set_parent_ids([b'A', b'B'])
+ tree.commit('msg c', rev_id=b'C')
+ self.assertEqual(
+ set([b'A']), get_ancestry(branch.repository, b'A'))
+ self.assertEqual(
+ set([b'B']), get_ancestry(branch.repository, b'B'))
+ self.assertEqual(
+ set([b'A', b'B', b'C']), get_ancestry(branch.repository, b'C'))
=== modified file 'lib/lp/code/tests/test_directbranchcommit.py'
--- lib/lp/code/tests/test_directbranchcommit.py 2012-03-27 14:11:03 +0000
+++ lib/lp/code/tests/test_directbranchcommit.py 2017-10-04 01:52:47 +0000
@@ -1,8 +1,10 @@
-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for `DirectBranchCommit`."""
+from __future__ import absolute_import, print_function, unicode_literals
+
__metaclass__ = type
from testtools.testcase import ExpectedException
@@ -73,10 +75,10 @@
def test_DirectBranchCommit_empty_initial_commit_noop(self):
# An empty initial commit to a branch is a no-op.
- self.assertEqual('null:', self.tree.branch.last_revision())
+ self.assertEqual(b'null:', self.tree.branch.last_revision())
self.committer.commit('')
self.assertEqual({}, self._getContents())
- self.assertEqual('null:', self.tree.branch.last_revision())
+ self.assertEqual(b'null:', self.tree.branch.last_revision())
def _addInitialCommit(self):
self.committer._getDir('')
@@ -86,7 +88,7 @@
def test_DirectBranchCommit_commits_no_changes(self):
# Committing nothing to an empty branch leaves its tree empty.
- self.assertEqual('null:', self.tree.branch.last_revision())
+ self.assertEqual(b'null:', self.tree.branch.last_revision())
old_rev_id = self.tree.branch.last_revision()
self._addInitialCommit()
self.committer.commit('')
@@ -96,17 +98,17 @@
def test_DirectBranchCommit_rejects_change_after_commit(self):
# Changes are not accepted after commit.
self.committer.commit('')
- self.assertRaises(AssertionError, self.committer.writeFile, 'x', 'y')
+ self.assertRaises(AssertionError, self.committer.writeFile, 'x', b'y')
def test_DirectBranchCommit_adds_file(self):
# DirectBranchCommit can add a new file to the branch.
- self.committer.writeFile('file.txt', 'contents')
+ self.committer.writeFile('file.txt', b'contents')
self.committer.commit('')
- self.assertEqual({'file.txt': 'contents'}, self._getContents())
+ self.assertEqual({'file.txt': b'contents'}, self._getContents())
def test_commit_returns_revision_id(self):
# DirectBranchCommit.commit returns the new revision_id.
- self.committer.writeFile('file.txt', 'contents')
+ self.committer.writeFile('file.txt', b'contents')
revision_id = self.committer.commit('')
branch_revision_id = self.committer.bzrbranch.last_revision()
self.assertEqual(branch_revision_id, revision_id)
@@ -116,56 +118,56 @@
self._tearDownCommitter()
# Merge parents cannot be specified for initial commit, so do an
# empty commit.
- self.tree.commit('foo', committer='foo@bar', rev_id='foo')
+ self.tree.commit('foo', committer='foo@bar', rev_id=b'foo')
self.db_branch.last_mirrored_id = 'foo'
committer = DirectBranchCommit(
- self.db_branch, merge_parents=['parent-1', 'parent-2'])
+ self.db_branch, merge_parents=[b'parent-1', b'parent-2'])
committer.last_scanned_id = (
committer.bzrbranch.last_revision())
- committer.writeFile('file.txt', 'contents')
+ committer.writeFile('file.txt', b'contents')
committer.commit('')
branch_revision_id = committer.bzrbranch.last_revision()
branch_revision = committer.bzrbranch.repository.get_revision(
branch_revision_id)
self.assertEqual(
- ['parent-1', 'parent-2'], branch_revision.parent_ids[1:])
+ [b'parent-1', b'parent-2'], branch_revision.parent_ids[1:])
def test_DirectBranchCommit_aborts_cleanly(self):
# If a DirectBranchCommit is not committed, its changes do not
# go into the branch.
- self.committer.writeFile('oldfile.txt', 'already here')
+ self.committer.writeFile('oldfile.txt', b'already here')
self.committer.commit('')
self._setUpCommitter()
- self.committer.writeFile('newfile.txt', 'adding this')
+ self.committer.writeFile('newfile.txt', b'adding this')
self._setUpCommitter()
- self.assertEqual({'oldfile.txt': 'already here'}, self._getContents())
+ self.assertEqual({'oldfile.txt': b'already here'}, self._getContents())
self.committer.unlock()
def test_DirectBranchCommit_updates_file(self):
# DirectBranchCommit can replace a file in the branch.
- self.committer.writeFile('file.txt', 'contents')
+ self.committer.writeFile('file.txt', b'contents')
self.committer.commit('')
self._setUpCommitter()
- self.committer.writeFile('file.txt', 'changed')
+ self.committer.writeFile('file.txt', b'changed')
self.committer.commit('')
- self.assertEqual({'file.txt': 'changed'}, self._getContents())
+ self.assertEqual({'file.txt': b'changed'}, self._getContents())
def test_DirectBranchCommit_creates_directories(self):
# Files can be in subdirectories.
- self.committer.writeFile('a/b/c.txt', 'ctext')
+ self.committer.writeFile('a/b/c.txt', b'ctext')
self.committer.commit('')
- self.assertEqual({'a/b/c.txt': 'ctext'}, self._getContents())
+ self.assertEqual({'a/b/c.txt': b'ctext'}, self._getContents())
def test_DirectBranchCommit_adds_directories(self):
# Creating a subdirectory of an existing directory also works.
- self.committer.writeFile('a/n.txt', 'aa')
+ self.committer.writeFile('a/n.txt', b'aa')
self.committer.commit('')
self._setUpCommitter()
- self.committer.writeFile('a/b/m.txt', 'aa/bb')
+ self.committer.writeFile('a/b/m.txt', b'aa/bb')
self.committer.commit('')
expected = {
- 'a/n.txt': 'aa',
- 'a/b/m.txt': 'aa/bb',
+ 'a/n.txt': b'aa',
+ 'a/b/m.txt': b'aa/bb',
}
self.assertEqual(expected, self._getContents())
@@ -173,47 +175,47 @@
# If a directory doesn't exist in the committed branch, creating
# it twice would be an error. DirectBranchCommit doesn't do
# that.
- self.committer.writeFile('foo/x.txt', 'x')
- self.committer.writeFile('foo/y.txt', 'y')
+ self.committer.writeFile('foo/x.txt', b'x')
+ self.committer.writeFile('foo/y.txt', b'y')
self.committer.commit('')
expected = {
- 'foo/x.txt': 'x',
- 'foo/y.txt': 'y',
+ 'foo/x.txt': b'x',
+ 'foo/y.txt': b'y',
}
self.assertEqual(expected, self._getContents())
def test_DirectBranchCommit_writes_new_file_twice(self):
# If you write the same new file multiple times before
# committing, the original wins.
- self.committer.writeFile('x.txt', 'aaa')
- self.committer.writeFile('x.txt', 'bbb')
+ self.committer.writeFile('x.txt', b'aaa')
+ self.committer.writeFile('x.txt', b'bbb')
self.committer.commit('')
- self.assertEqual({'x.txt': 'aaa'}, self._getContents())
+ self.assertEqual({'x.txt': b'aaa'}, self._getContents())
def test_DirectBranchCommit_updates_file_twice(self):
# If you update the same file multiple times before committing,
# the original wins.
- self.committer.writeFile('y.txt', 'aaa')
+ self.committer.writeFile('y.txt', b'aaa')
self.committer.commit('')
self._setUpCommitter()
- self.committer.writeFile('y.txt', 'bbb')
- self.committer.writeFile('y.txt', 'ccc')
+ self.committer.writeFile('y.txt', b'bbb')
+ self.committer.writeFile('y.txt', b'ccc')
self.committer.commit('')
- self.assertEqual({'y.txt': 'bbb'}, self._getContents())
+ self.assertEqual({'y.txt': b'bbb'}, self._getContents())
def test_DirectBranchCommit_detects_race_condition(self):
# If the branch has been updated since it was last scanned,
# attempting to commit to it will raise ConcurrentUpdateError.
- self.committer.writeFile('hi.c', 'main(){puts("hi world");}')
+ self.committer.writeFile('hi.c', b'main(){puts("hi world");}')
self.committer.commit('')
self._setUpCommitter(False)
- self.committer.writeFile('hi.py', 'print "hi world"')
+ self.committer.writeFile('hi.py', b'print "hi world"')
self.assertRaises(ConcurrentUpdateError, self.committer.commit, '')
def test_DirectBranchCommit_records_committed_revision_id(self):
# commit() records the committed revision in the database record for
# the branch.
- self.committer.writeFile('hi.c', 'main(){puts("hi world");}')
+ self.committer.writeFile('hi.c', b'main(){puts("hi world");}')
revid = self.committer.commit('')
self.assertEqual(revid, self.db_branch.last_mirrored_id)
@@ -225,7 +227,7 @@
fake_commit = FakeMethod()
self.committer.transform_preview.commit = fake_commit
- self.committer.writeFile('x', 'y')
+ self.committer.writeFile('x', b'y')
self.committer.commit('')
commit_args, commit_kwargs = fake_commit.calls[-1]
Follow ups