This test might not notice corner cases. Can you run getBugHeat()
before and after setting the date_last_updated and assert that
old_heat * 0.9 == new_heat
>+ self.assertEqual(
>+ expected, heat,
>+ "Expected bug heat did not match actual bug heat. "
>+ "Expected %s, got %s" % (expected, heat))
>+
>
> def test_suite():
> return unittest.TestLoader().loadTestsFromName(__name__)
>
Hi Tom,
This is a nice branch. I have a few comments below, and there are some
lint errors.
merge-conditional
-Edwin
== Pyflakes notices ==
lib/lp/ bugs/scripts/ bugheat. py
13: 'getUtility' imported but unused
14: 'implements' imported but unused
16: 'ITunableLoop' imported but unused
17: 'DBLoopTuner' imported but unused
lib/lp/ bugs/scripts/ tests/test_ bugheat. py
10: 'datetime' imported but unused
>=== modified file 'lib/lp/ bugs/scripts/ bugheat. py' bugs/scripts/ bugheat. py 2010-01-26 20:31:13 +0000 bugs/scripts/ bugheat. py 2010-02-26 21:30:36 +0000 tor', launchpad. interfaces. looptuner import ITunableLoop launchpad. utilities. looptuner import DBLoopTuner interfaces. bugtask import RESOLVED_ BUGTASK_ STATUSES subscribers) + len(subscribers _from_dupes) ) s.SUBSCRIBER self): BUGTASK_ STATUSES) lete(): omAffectedUsers (), omDuplicates( ), omSubscribers( ),
>--- lib/lp/
>+++ lib/lp/
>@@ -8,6 +8,7 @@
> 'BugHeatCalcula
> ]
>
>+from datetime import datetime
>
> from zope.component import getUtility
> from zope.interface import implements
>@@ -15,6 +16,8 @@
> from canonical.
> from canonical.
>
>+from lp.bugs.
>+
>
> class BugHeatConstants:
>
>@@ -63,8 +66,16 @@
> len(direct_
> return subscriber_count * BugHeatConstant
>
>+ def _bugIsComplete(
>+ """Are all the tasks for this bug resolved?"""
>+ return all([(task.status in RESOLVED_
>+ for task in self.bug.bugtasks])
>+
> def getBugHeat(self):
> """Return the total heat for the current bug."""
>+ if self._bugIsComp
>+ return 0
>+
> total_heat = sum([
> self._getHeatFr
> self._getHeatFr
>@@ -73,5 +84,15 @@
> self._getHeatFr
> ])
>
>+ # Bugs decay over time. Every month the bug isn't touched its heat
>+ # decreeses by 5%.
s/decreeses/ decreases/
The comment says 5%, but the test says 10%. Which is it?
>+ months = ( date_last_ updated. replace( tzinfo= None)). days / 30
>+ datetime.utcnow() -
>+ self.bug.
>+ for i in range(months):
>+ total_heat = total_heat * 0.95
This could be simplified as:
total_heat *= 0.95 ** months
>+ bugs/scripts/ tests/test_ bugheat. py' bugs/scripts/ tests/test_ bugheat. py 2010-01-12 16:41:23 +0000 bugs/scripts/ tests/test_ bugheat. py 2010-02-26 21:30:36 +0000 ssLayer interfaces. bugtask import BugTaskStatus scripts. bugheat import BugHeatCalculator, BugHeatConstants ulator( TestCaseWithFac tory): _complete_ bugs(self) : makeBug( ) or(complete_ bug).getBugHeat () qual( bug.bugtasks[ 0].transitionTo Status( INVALID, complete_bug.owner) or(complete_ bug).getBugHeat () _decay( self):
>+ total_heat = int(total_heat)
>+
> return total_heat
>
>
>=== modified file 'lib/lp/
>--- lib/lp/
>+++ lib/lp/
>@@ -1,4 +1,3 @@
>-
> # Copyright 2010 Canonical Ltd. This software is licensed under the
> # GNU Affero General Public License version 3 (see the file LICENSE).
>
>@@ -8,12 +7,14 @@
>
> import unittest
>
>+from datetime import datetime, timedelta
>+
> from canonical.testing import LaunchpadZopele
>
>+from lp.bugs.
> from lp.bugs.
> from lp.testing import TestCaseWithFactory
>
>-
> class TestBugHeatCalc
> """Tests for the BugHeatCalculator class."""
>
>@@ -177,6 +178,35 @@
> "Expected bug heat did not match actual bug heat. "
> "Expected %s, got %s" % (expected_heat, actual_heat))
>
>+ def test_getBugHeat
>+ # Bug which are in a resolved status don't have heat at all.
>+ complete_bug = self.factory.
>+ heat = BugHeatCalculat
>+ self.assertNotE
>+ 0, heat,
>+ "Expected bug heat did not match actual bug heat. "
>+ "Expected a positive value, got 0")
>+ complete_
>+ BugTaskStatus.
>+ heat = BugHeatCalculat
>+ self.assertEqual(
>+ 0, heat,
>+ "Expected bug heat did not match actual bug heat. "
>+ "Expected %s, got %s" % (0, heat))
>+
>+ def test_getBugHeat
>+ # Every month, a bug that wasn't touched has its heat reduced by 10%.
10% or 5% ?
>+ aging_bug = self.factory. makeBug( ) date_last_ updated = ( date_last_ updated - timedelta(days=32)) s.AFFECTED_ USER + BugHeatConstant s.SUBSCRIBER) * 0.9) or(aging_ bug).getBugHeat ()
>+ aging_bug.
>+ aging_bug.
>+ expected = int((
>+ BugHeatConstant
>+ heat = BugHeatCalculat
This test might not notice corner cases. Can you run getBugHeat()
before and after setting the date_last_updated and assert that
old_heat * 0.9 == new_heat
>+ self.assertEqual( TestLoader( ).loadTestsFrom Name(__ name__)
>+ expected, heat,
>+ "Expected bug heat did not match actual bug heat. "
>+ "Expected %s, got %s" % (expected, heat))
>+
>
> def test_suite():
> return unittest.
>