launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #18710
[Merge] lp:~blr/launchpad/dont-fear-the-repr into lp:launchpad
Bayard 'kit' Randel has proposed merging lp:~blr/launchpad/dont-fear-the-repr into lp:launchpad.
Commit message:
Add a repr for PackageDiffJob.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1461300 in Launchpad itself: "PackageDiffJob needs more informative repr"
https://bugs.launchpad.net/launchpad/+bug/1461300
For more details, see:
https://code.launchpad.net/~blr/launchpad/dont-fear-the-repr/+merge/261174
Adds a repr for PackageDiffJob in the form:
<PackageDiffJob from {from-sourcepkg-name} (id, version) to {to-sourcepkg-name} (id, version) for {requester}>
--
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~blr/launchpad/dont-fear-the-repr into lp:launchpad.
=== modified file 'lib/lp/soyuz/model/packagediffjob.py'
--- lib/lp/soyuz/model/packagediffjob.py 2013-07-24 10:48:00 +0000
+++ lib/lp/soyuz/model/packagediffjob.py 2015-06-05 04:51:04 +0000
@@ -66,6 +66,27 @@
implements(IPackageDiffJob)
classProvides(IPackageDiffJobSource)
+ def __repr__(self):
+ """Returns an informative representation of a PackageDiff job."""
+ parts = ['{cls}'.format(cls=self.__class__.__name__)]
+ diff = self.packagediff
+ if diff.from_source is not None:
+ parts.append((' from {src} '
+ '(id: {id}, version: {version})'.format(
+ src=diff.from_source.name,
+ id=diff.from_source.id,
+ version=diff.from_source.version)))
+ if diff.to_source is not None:
+ parts.append((' to {src} '
+ '(id: {id}, version: {version})'.format(
+ src=diff.to_source.name,
+ id=diff.to_source.id,
+ version=diff.to_source.version)))
+ if diff.requester is not None:
+ parts.append(' for {requestor}'.format(
+ requestor=diff.requester.name))
+ return '<{repr}>'.format(repr=''.join(parts))
+
@property
def packagediff_id(self):
return simplejson.loads(self.base_json_data)['packagediff']
=== modified file 'lib/lp/soyuz/tests/test_packagediffjob.py'
--- lib/lp/soyuz/tests/test_packagediffjob.py 2013-08-07 06:26:36 +0000
+++ lib/lp/soyuz/tests/test_packagediffjob.py 2015-06-05 04:51:04 +0000
@@ -64,6 +64,21 @@
jobs = list(PackageDiffJob.iterReady())
self.assertEqual(1, len(jobs))
+ def test___repr__(self):
+ _, job = self.makeJob()
+ expected_repr = ('<PackageDiffJob '
+ 'from {from_src} (id: {from_id}, version: {from_ver}) '
+ 'to {to_src} (id: {to_id}, version: {to_ver}) '
+ 'for {user}>'.format(
+ from_src=job.packagediff.from_source.name,
+ from_id=job.packagediff.from_source.id,
+ from_ver=job.packagediff.from_source.version,
+ to_src=job.packagediff.to_source.name,
+ to_id=job.packagediff.to_source.id,
+ to_ver=job.packagediff.to_source.version,
+ user=job.packagediff.requester.name))
+ self.assertEqual(expected_repr, repr(job))
+
def test_run(self):
diff, job = self.makeJob()
method = FakeMethod()
Follow ups