launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26108
[Merge] ~cjwatson/launchpad:py3-getBlob-tests into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-getBlob-tests into launchpad:master.
Commit message:
Fix {Branch,GitRepository}.getBlob tests for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396916
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-getBlob-tests into launchpad:master.
diff --git a/lib/lp/code/model/tests/test_branch.py b/lib/lp/code/model/tests/test_branch.py
index 20c9ce7..a9ddb99 100644
--- a/lib/lp/code/model/tests/test_branch.py
+++ b/lib/lp/code/model/tests/test_branch.py
@@ -3310,7 +3310,7 @@ class TestBranchGetBlob(TestCaseWithFactory):
hosting_fixture = self.useFixture(BranchHostingFixture(
file_list={'README.txt': 'some-file-id'}, blob=b'Some text'))
blob = branch.getBlob('src/README.txt')
- self.assertEqual('Some text', blob)
+ self.assertEqual(b'Some text', blob)
self.assertEqual(
[((branch.id, 'src'), {'rev': None})],
hosting_fixture.getInventory.calls)
@@ -3325,7 +3325,7 @@ class TestBranchGetBlob(TestCaseWithFactory):
hosting_fixture = self.useFixture(BranchHostingFixture(
file_list={'README.txt': 'some-file-id'}, blob=b'Some text'))
blob = branch.getBlob('src/README.txt')
- self.assertEqual('Some text', blob)
+ self.assertEqual(b'Some text', blob)
self.assertEqual(
[((branch.id, 'src'), {'rev': 'scanned-id'})],
hosting_fixture.getInventory.calls)
@@ -3343,7 +3343,7 @@ class TestBranchGetBlob(TestCaseWithFactory):
hosting_fixture = self.useFixture(BranchHostingFixture(
file_list={'README.txt': 'some-file-id'}, blob=b'Some text'))
blob = branch.getBlob('src/README.txt', revision_id='some-rev')
- self.assertEqual('Some text', blob)
+ self.assertEqual(b'Some text', blob)
self.assertEqual(
[((branch.id, 'src'), {'rev': 'some-rev'})],
hosting_fixture.getInventory.calls)
@@ -3363,7 +3363,7 @@ class TestBranchGetBlob(TestCaseWithFactory):
getUtility(IMemcacheClient).set(
key.encode('UTF-8'), json.dumps({'README.txt': 'some-file-id'}))
blob = branch.getBlob('src/README.txt', revision_id='some-rev')
- self.assertEqual('Some text', blob)
+ self.assertEqual(b'Some text', blob)
self.assertEqual([], hosting_fixture.getInventory.calls)
self.assertEqual(
[((branch.id, 'some-file-id'), {'rev': 'some-rev'})],
@@ -3378,7 +3378,7 @@ class TestBranchGetBlob(TestCaseWithFactory):
key = 'bazaar.launchpad.test:bzr-file-list:%s:some-rev:src' % branch.id
getUtility(IMemcacheClient).set(key.encode('UTF-8'), '{}')
blob = branch.getBlob('src/README.txt', revision_id='some-rev')
- self.assertEqual('Some text', blob)
+ self.assertEqual(b'Some text', blob)
self.assertEqual(
[((branch.id, 'src'), {'rev': 'some-rev'})],
hosting_fixture.getInventory.calls)
@@ -3390,7 +3390,7 @@ class TestBranchGetBlob(TestCaseWithFactory):
hosting_fixture = self.useFixture(BranchHostingFixture(
file_list={'README.txt': 'some-file-id'}, blob=b'Some text'))
blob = branch.getBlob('README.txt', revision_id='some-rev')
- self.assertEqual('Some text', blob)
+ self.assertEqual(b'Some text', blob)
self.assertEqual(
[((branch.id, ''), {'rev': 'some-rev'})],
hosting_fixture.getInventory.calls)
diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
index a1ccd02..5ae164b 100644
--- a/lib/lp/code/model/tests/test_gitrepository.py
+++ b/lib/lp/code/model/tests/test_gitrepository.py
@@ -2933,15 +2933,15 @@ class TestGitRepositoryGetBlob(TestCaseWithFactory):
def test_getBlob_with_default_rev(self):
repository = self.factory.makeGitRepository()
- self.useFixture(GitHostingFixture(blob='Some text'))
+ self.useFixture(GitHostingFixture(blob=b'Some text'))
ret = repository.getBlob('src/README.txt')
- self.assertEqual('Some text', ret)
+ self.assertEqual(b'Some text', ret)
def test_getBlob_with_rev(self):
repository = self.factory.makeGitRepository()
- self.useFixture(GitHostingFixture(blob='Some text'))
+ self.useFixture(GitHostingFixture(blob=b'Some text'))
ret = repository.getBlob('src/README.txt', 'some-rev')
- self.assertEqual('Some text', ret)
+ self.assertEqual(b'Some text', ret)
class TestGitRepositoryRules(TestCaseWithFactory):
diff --git a/lib/lp/services/librarian/tests/test_client.py b/lib/lp/services/librarian/tests/test_client.py
index d7f3cba..a9475b2 100644
--- a/lib/lp/services/librarian/tests/test_client.py
+++ b/lib/lp/services/librarian/tests/test_client.py
@@ -20,6 +20,7 @@ from six.moves.urllib.error import (
URLError,
)
from six.moves.urllib.request import urlopen
+from testtools.testcase import ExpectedException
import transaction
from lp.services.config import config
@@ -171,8 +172,11 @@ class LibrarianFileWrapperTestCase(TestCase):
def test_unbounded_read_incorrect_length(self):
file = self.makeFile(extra_content_length=1)
- self.assertEqual(b"abcdef", file.read())
- self.assertRaises(http_client.IncompleteRead, file.read)
+ with ExpectedException(http_client.IncompleteRead):
+ # Python 3 notices the short response on the first read.
+ self.assertEqual(b"abcdef", file.read())
+ # Python 2 only notices the short response on the next read.
+ file.read()
def test_bounded_read_correct_length(self):
file = self.makeFile()