Merge lp:~jtv/launchpad/recife-pre-stats into lp:launchpad/db-devel

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 10015
Proposed branch: lp:~jtv/launchpad/recife-pre-stats
Merge into: lp:launchpad/db-devel
Diff against target: 164 lines (+38/-47)
4 files modified
lib/lp/translations/interfaces/pofile.py (+5/-2)
lib/lp/translations/model/pofile.py (+2/-3)
lib/lp/translations/model/potemplate.py (+5/-1)
lib/lp/translations/tests/test_pofile.py (+26/-41)
To merge this branch: bzr merge lp:~jtv/launchpad/recife-pre-stats
Reviewer Review Type Date Requested Status
Henning Eggers (community) code Approve
Review via email: mp+42079@code.launchpad.net

Commit message

[r=henninge][ui=none][no-qa] Pre-cleanups for Recife POFile stats.

Description of the change

= Cleanups before Recife statistics calculation =

The Translations application is moving over to its new "Recife" data model this cycle. One thing that still needs an overhaul is calculation of translation statistics for POFiles.

I'm working on that in other branches, but here's a small branch with some cleanups that can go in separately. The biggest change is a test that I've cleaned out a bit so that it no longer needs unusual privileges (or costly Launchpad layer setup) and runs in both old-model and new-model statistics calculation.

No lint. To exercise the test,
{{{
./bin/test -vvc lp.translations.tests.test_pofile
}}}

Jeroen

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

<henninge> jtv: very nice simplification of the test.
<henninge> jtv: I just don't see what you describe as "runs in both old-model and new-model statistics calculation."
<jtv> In all honesty, I did it to get the test to start up faster. :-)
<jtv> I clear both flags as an alternative to deleting the message.
<henninge> ah! so lines 148-151 could use a comment I think ;)
<henninge> jtv: but apart from that, r=me ;)
* jtv looks
<jtv> OK, I'll note that.
<henninge> thanks

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/interfaces/pofile.py'
2--- lib/lp/translations/interfaces/pofile.py 2010-11-21 20:46:19 +0000
3+++ lib/lp/translations/interfaces/pofile.py 2010-11-29 08:58:19 +0000
4@@ -386,11 +386,14 @@
5 if the end of the table has been reached.
6 """
7
8- def getPOFilesWithTranslationCredits():
9- """Get all POFiles with potential translation credits messages.
10+ def getPOFilesWithTranslationCredits(untranslated=False):
11+ """Get POFiles with potential translation credits messages.
12
13 Returns a ResultSet of (POFile, POTMsgSet) tuples, ordered by
14 POFile.id.
15+
16+ :param untranslated: Look only for `POFile`s with a credits
17+ message that is not translated.
18 """
19
20 def getPOFilesTouchedSince(date):
21
22=== modified file 'lib/lp/translations/model/pofile.py'
23--- lib/lp/translations/model/pofile.py 2010-11-26 05:10:27 +0000
24+++ lib/lp/translations/model/pofile.py 2010-11-29 08:58:19 +0000
25@@ -846,8 +846,6 @@
26 if new_header is None:
27 return
28
29- # XXX sabdfl 2005-05-27 should we also differentiate between
30- # washeaderfuzzy and isheaderfuzzy?
31 self.topcomment = new_header.comment
32 self.header = new_header.getRawContent()
33 self.fuzzyheader = new_header.is_fuzzy
34@@ -1424,7 +1422,8 @@
35 TranslationTemplateItem.potemplateID == POFile.potemplateID,
36 POTMsgSet.id == TranslationTemplateItem.potmsgsetID,
37 POTMsgSet.msgid_singular == POMsgID.id,
38- POMsgID.msgid.is_in(POTMsgSet.credits_message_ids)]
39+ POMsgID.msgid.is_in(POTMsgSet.credits_message_ids),
40+ ]
41 if untranslated:
42 message_select = Select(
43 True,
44
45=== modified file 'lib/lp/translations/model/potemplate.py'
46--- lib/lp/translations/model/potemplate.py 2010-11-21 20:46:19 +0000
47+++ lib/lp/translations/model/potemplate.py 2010-11-29 08:58:19 +0000
48@@ -533,6 +533,10 @@
49 """See `IRosettaStats`."""
50 return self.messagecount
51
52+ def updateMessageCount(self):
53+ """Update `self.messagecount`."""
54+ self.messagecount = self.getPOTMsgSetsCount()
55+
56 def currentCount(self, language=None):
57 """See `IRosettaStats`."""
58 if language is None:
59@@ -944,7 +948,7 @@
60 flush_database_updates()
61
62 # Update cached number of msgsets.
63- self.messagecount = self.getPOTMsgSetsCount()
64+ self.updateMessageCount()
65
66 # The upload affects the statistics for all translations of this
67 # template. Recalculate those as well. This takes time and
68
69=== modified file 'lib/lp/translations/tests/test_pofile.py'
70--- lib/lp/translations/tests/test_pofile.py 2010-11-26 05:10:27 +0000
71+++ lib/lp/translations/tests/test_pofile.py 2010-11-29 08:58:19 +0000
72@@ -20,10 +20,7 @@
73 from canonical.database.constants import UTC_NOW
74 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
75 from canonical.launchpad.webapp.publisher import canonical_url
76-from canonical.testing.layers import (
77- LaunchpadZopelessLayer,
78- ZopelessDatabaseLayer,
79- )
80+from canonical.testing.layers import ZopelessDatabaseLayer
81 from lp.app.enums import ServiceUsage
82 from lp.testing import TestCaseWithFactory
83 from lp.translations.interfaces.pofile import IPOFileSet
84@@ -1405,7 +1402,7 @@
85 class TestPOFileSet(TestCaseWithFactory):
86 """Test PO file set methods."""
87
88- layer = LaunchpadZopelessLayer
89+ layer = ZopelessDatabaseLayer
90
91 def setUp(self):
92 # Create a POFileSet to work with.
93@@ -1643,47 +1640,35 @@
94 self.pofileset.getPOFilesWithTranslationCredits()))
95
96 def test_getPOFilesWithTranslationCredits_untranslated(self):
97- # We need absolute DB access to be able to remove a translation
98- # message.
99- LaunchpadZopelessLayer.switchDbUser('postgres')
100+ # With "untranslated=True," getPOFilesWithTranslationCredits
101+ # looks for POFiles whose translation credits messages are
102+ # untranslated.
103
104- # Initially, we only get data from the sampledata, all of which
105- # are untranslated.
106- sampledata_pofiles = list(
107+ # The sample data may contain some matching POFiles, but we'll
108+ # ignore those.
109+ initial_matches = set(
110 self.pofileset.getPOFilesWithTranslationCredits(
111 untranslated=True))
112- total = len(sampledata_pofiles)
113- self.assertEquals(3, total)
114
115- # All POFiles with translation credits messages are
116- # returned along with relevant POTMsgSets.
117- potemplate1 = self.factory.makePOTemplate()
118+ potemplate = self.factory.makePOTemplate()
119 credits_potmsgset = self.factory.makePOTMsgSet(
120- potemplate1, singular=u'translator-credits', sequence=1)
121-
122- sr_pofile = self.factory.makePOFile('sr', potemplate=potemplate1)
123- pofiles_with_credits = (
124- self.pofileset.getPOFilesWithTranslationCredits(
125- untranslated=True))
126- self.assertNotIn((sr_pofile, credits_potmsgset),
127- list(pofiles_with_credits))
128- self.assertEquals(
129- total,
130- pofiles_with_credits.count())
131-
132- # Removing a translation for this message, removes it
133- # from a result set when untranslated=True is passed in.
134- message = credits_potmsgset.getSharedTranslationMessage(
135- sr_pofile.language)
136- message.destroySelf()
137- pofiles_with_credits = (
138- self.pofileset.getPOFilesWithTranslationCredits(
139- untranslated=True))
140- self.assertIn((sr_pofile, credits_potmsgset),
141- list(pofiles_with_credits))
142- self.assertEquals(
143- total + 1,
144- pofiles_with_credits.count())
145+ potemplate, singular=u'translator-credits', sequence=1)
146+ pofile = self.factory.makePOFile(potemplate=potemplate)
147+
148+ credits_translation = credits_potmsgset.getCurrentTranslation(
149+ potemplate, pofile.language, potemplate.translation_side)
150+ # Clearing is_current_upstream will make this an "untranslated"
151+ # credits message.
152+ # XXX JeroenVermeulen 2010-11-29: Also clearing
153+ # is_current_ubuntu to make this pass until
154+ # getPOFilesWithTranslationCredits is updated.
155+ credits_translation.is_current_ubuntu = False
156+ credits_translation.is_current_upstream = False
157+
158+ self.assertEqual(
159+ initial_matches.union([(pofile, credits_potmsgset)]),
160+ set(self.pofileset.getPOFilesWithTranslationCredits(
161+ untranslated=True)))
162
163 def test_getPOFilesByPathAndOrigin_path_mismatch(self):
164 # getPOFilesByPathAndOrigin matches on POFile path.

Subscribers

People subscribed via source and target branches

to status/vote changes: