← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-test-repr-long into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-test-repr-long into launchpad:master.

Commit message:
Adjust tests for repr of (long) integers in Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397339
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-test-repr-long into launchpad:master.
diff --git a/lib/lp/bugs/doc/bugsummary.txt b/lib/lp/bugs/doc/bugsummary.txt
index 77299eb..1709e10 100644
--- a/lib/lp/bugs/doc/bugsummary.txt
+++ b/lib/lp/bugs/doc/bugsummary.txt
@@ -370,15 +370,15 @@ a sourcepackage, so we subtract this count from the total number of bugs
 targeted to the distribution:
 
     >>> from storm.expr import SQL
-    >>> store.find(
+    >>> print(store.find(
     ...     BugSummary,
     ...     BugSummary.distribution == distribution,
     ...     BugSummary.status == BugTaskStatus.CONFIRMED,
     ...     BugSummary.viewed_by == None,
     ...     BugSummary.tag == None).sum(SQL("""
     ...         CASE WHEN sourcepackagename IS NULL THEN count ELSE -count END
-    ...         """)) or 0
-    1L
+    ...         """)) or 0)
+    1
 
 
 DistroSeries Bug Counts
diff --git a/lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py b/lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py
index 7c246c1..b384550 100644
--- a/lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py
+++ b/lib/lp/bugs/scripts/tests/test_bugsummaryrebuild.py
@@ -3,6 +3,8 @@
 
 __metaclass__ = type
 
+import sys
+
 from testtools.content import text_content
 from testtools.matchers import MatchesRegex
 import transaction
@@ -139,10 +141,12 @@ class TestBugSummaryRebuild(TestCaseWithFactory):
             rebuild_bugsummary_for_target(product, log)
         self.assertEqual(1, get_bugsummary_rows(product).count())
         self.assertEqual(0, get_bugsummaryjournal_rows(product).count())
+        long_type = int if sys.version_info[0] >= 3 else long
         self.assertThat(
             log.getLogBufferAndClear(),
             MatchesRegex(
-                'DEBUG Rebuilding %s\nDEBUG Added {.*: 1L}' % product.name))
+                'DEBUG Rebuilding %s\nDEBUG Added {.*: %r}' %
+                (product.name, long_type(1))))
 
     def test_script(self):
         product = self.factory.makeProduct()
diff --git a/lib/lp/buildmaster/doc/builder.txt b/lib/lp/buildmaster/doc/builder.txt
index 51c039d..e3620e9 100644
--- a/lib/lp/buildmaster/doc/builder.txt
+++ b/lib/lp/buildmaster/doc/builder.txt
@@ -98,8 +98,11 @@ virtualization status, architecture, then name.
 Processor/virtualization.
 
     >>> queue_sizes = builderset.getBuildQueueSizes()
-    >>> queue_sizes['nonvirt']['386']
-    (1L, datetime.timedelta(0, 60))
+    >>> size, duration = queue_sizes['nonvirt']['386']
+    >>> print(size)
+    1
+    >>> print(duration)
+    0:01:00
 
 There are no 'amd64' build queue entries.
 
@@ -142,8 +145,11 @@ Let's re-enable the ubuntu primary archive.
 The build for the ubuntu primary archive shows up again.
 
     >>> queue_sizes = builderset.getBuildQueueSizes()
-    >>> queue_sizes['nonvirt']['386']
-    (1L, datetime.timedelta(0, 60))
+    >>> size, duration = queue_sizes['nonvirt']['386']
+    >>> print(size)
+    1
+    >>> print(duration)
+    0:01:00
 
 All job types are included. If we create a recipe build job, it will
 show up in the calculated queue size.
@@ -152,5 +158,8 @@ show up in the calculated queue size.
     ...     distroseries=ubuntu.currentseries).queueBuild()
     >>> transaction.commit()
     >>> queue_sizes = builderset.getBuildQueueSizes()
-    >>> print(queue_sizes['virt']['386'])
-    (1L, datetime.timedelta(0, 600))
+    >>> size, duration = queue_sizes['virt']['386']
+    >>> print(size)
+    1
+    >>> print(duration)
+    0:10:00
diff --git a/lib/lp/registry/browser/tests/poll-views_0.txt b/lib/lp/registry/browser/tests/poll-views_0.txt
index 47ab535..2048cb1 100644
--- a/lib/lp/registry/browser/tests/poll-views_0.txt
+++ b/lib/lp/registry/browser/tests/poll-views_0.txt
@@ -65,12 +65,12 @@ matrix as a python list, with the necessary headers (the option's names).
 
   >>> poll_results = getMultiAdapter((poll, TestRequest()), name="+index")
   >>> for row in poll_results.getPairwiseMatrixWithHeaders():
-  ...     print(row)
-  [None, u'A', u'B', u'C', u'D']
-  [u'A', None, 2L, 2L, 2L]
-  [u'B', 2L, None, 2L, 2L]
-  [u'C', 1L, 1L, None, 1L]
-  [u'D', 2L, 1L, 2L, None]
+  ...     print(pretty(row))
+  [None, 'A', 'B', 'C', 'D']
+  ['A', None, 2, 2, 2]
+  ['B', 2, None, 2, 2]
+  ['C', 1, 1, None, 1]
+  ['D', 2, 1, 2, None]
 
 == Voting on closed polls ==
 
diff --git a/lib/lp/registry/doc/poll.txt b/lib/lp/registry/doc/poll.txt
index 6ef79a1..b1ef334 100644
--- a/lib/lp/registry/doc/poll.txt
+++ b/lib/lp/registry/doc/poll.txt
@@ -131,10 +131,10 @@ people can start voting.
   >>> votes = poll2.storeCondorcetVote(member3, options, when=opendate)
   >>> options = {a: 1}
   >>> votes = poll2.storeCondorcetVote(member4, options, when=opendate)
+  >>> from zope.security.proxy import removeSecurityProxy
   >>> for row in poll2.getPairwiseMatrix():
-  ...     print row
-  [None, 2L, 2L, 2L]
-  [2L, None, 2L, 2L]
-  [1L, 1L, None, 1L]
-  [2L, 1L, 2L, None]
-
+  ...     print(pretty(removeSecurityProxy(row)))
+  [None, 2, 2, 2]
+  [2, None, 2, 2]
+  [1, 1, None, 1]
+  [2, 1, 2, None]
diff --git a/lib/lp/soyuz/browser/tests/archive-views.txt b/lib/lp/soyuz/browser/tests/archive-views.txt
index e27c6d6..ed0598a 100644
--- a/lib/lp/soyuz/browser/tests/archive-views.txt
+++ b/lib/lp/soyuz/browser/tests/archive-views.txt
@@ -60,8 +60,12 @@ The ArchiveView provides the html for the inline description editing widget.
 For convenience the ArchiveView also includes a build_counters property
 that returns a dict of the build count summary for the archive:
 
-    >>> print(ppa_archive_view.build_counters)
-    {'failed': 1L, 'superseded': 0, 'total': 4L, ...
+    >>> for key, value in sorted(ppa_archive_view.build_counters.items()):
+    ...     print('%s: %d' % (key, value))
+    failed: 1
+    ...
+    superseded: 0
+    total: 4
 
 An ArchiveView also includes an easy way to get any
 IPackageCopyRequest's associated with an archive:
@@ -381,8 +385,11 @@ We can optionally pass the number of days.
 The ArchiveView includes a helper to return the number of packages that
 are building as well as the number of packages waiting to build.
 
-    >>> print(view.num_pkgs_building)
-    {'building': 0, 'waiting': 0, 'total': 0}
+    >>> for key, value in sorted(view.num_pkgs_building.items()):
+    ...     print('%s: %d' % (key, value))
+    building: 0
+    total: 0
+    waiting: 0
 
 Let's set some builds appropriately to see the results.
 
@@ -410,22 +417,31 @@ Let's set some builds appropriately to see the results.
     >>> builds[2].updateStatus(
     ...     BuildStatus.BUILDING, force_invalid_transition=True)
 
-    >>> view.num_pkgs_building
-    {'building': 2, 'waiting': 1, 'total': 3}
+    >>> for key, value in sorted(view.num_pkgs_building.items()):
+    ...     print('%s: %d' % (key, value))
+    building: 2
+    total: 3
+    waiting: 1
 
 Adding a second waiting build for the cdrkit does not add to the number
 of packages that are currently building.
 
     >>> builds[4].updateStatus(BuildStatus.NEEDSBUILD)
-    >>> view.num_pkgs_building
-    {'building': 2, 'waiting': 1, 'total': 3}
+    >>> for key, value in sorted(view.num_pkgs_building.items()):
+    ...     print('%s: %d' % (key, value))
+    building: 2
+    total: 3
+    waiting: 1
 
 But as soon as one of cdrkit's builds start, the package is considered
 to be building:
 
     >>> builds[4].updateStatus(BuildStatus.BUILDING)
-    >>> view.num_pkgs_building
-    {'building': 3, 'waiting': 0, 'total': 3}
+    >>> for key, value in sorted(view.num_pkgs_building.items()):
+    ...     print('%s: %d' % (key, value))
+    building: 3
+    total: 3
+    waiting: 0
 
 The archive index view overrides the default series filter to use the
 distroseries from the browser's user-agent, when applicable.
diff --git a/lib/lp/soyuz/doc/publishing.txt b/lib/lp/soyuz/doc/publishing.txt
index bacb573..365028c 100644
--- a/lib/lp/soyuz/doc/publishing.txt
+++ b/lib/lp/soyuz/doc/publishing.txt
@@ -944,10 +944,14 @@ getDownloadCounts lets us filter by date.
 We can also get a dict of totals for each day. The keys are strings to
 work around lazr.restful's dict limitations. This too has a date filter.
 
-    >>> bpph.getDailyDownloadTotals()
-    {'2010-02-21': 14L, '2010-02-19': 2L}
-    >>> bpph.getDailyDownloadTotals(start_date=date(2010, 2, 20))
-    {'2010-02-21': 14L}
+    >>> for day, total in sorted(bpph.getDailyDownloadTotals().items()):
+    ...     print('%s: %d' % (day, total))
+    2010-02-19: 2
+    2010-02-21: 14
+    >>> for day, total in sorted(bpph.getDailyDownloadTotals(
+    ...         start_date=date(2010, 2, 20)).items()):
+    ...     print('%s: %d' % (day, total))
+    2010-02-21: 14
 
 
 IPublishingSet
diff --git a/lib/lp/testing/systemdocs.py b/lib/lp/testing/systemdocs.py
index 8b0e87c..3d42c6f 100644
--- a/lib/lp/testing/systemdocs.py
+++ b/lib/lp/testing/systemdocs.py
@@ -222,8 +222,9 @@ def stop():
 class PrettyPrinter(pprint.PrettyPrinter, object):
     """A pretty-printer that formats text in the Python 3 style.
 
-    This should only be used when the resulting ambiguity between str and
-    unicode representation on Python 2 is not a problem.
+    This should only be used when the resulting ambiguities between str and
+    unicode representation and between int and long representation on Python
+    2 are not a problem.
     """
 
     def format(self, obj, contexts, maxlevels, level):
@@ -233,6 +234,8 @@ class PrettyPrinter(pprint.PrettyPrinter, object):
                 return '"%s"' % obj, True, False
             else:
                 return "'%s'" % obj.replace("'", "\\'"), True, False
+        elif sys.version_info[0] < 3 and isinstance(obj, long):
+            return repr(int(obj)), True, False
         else:
             return super(PrettyPrinter, self).format(
                 obj, contexts, maxlevels, level)