Henning Eggers has proposed merging lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-2 into lp:launchpad/db-devel with lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-1 as a prerequisite.
Requested reviews: Launchpad code reviewers (launchpad-reviewers) Related bugs: #611668 getPOTMsgSetWithNewSuggestions upstream https://bugs.launchpad.net/bugs/611668 == Details == This branch continues the quest for the transformation of the messsage filter methods to the new translations model. It contains the following changes: * Create TestUpstreamFilters and TestUbuntuFilters from the scenario created in the previous branch. * Rename getPOTMsgSetChangedInUbuntu to getPOTMsgSetDifferentTranslations because the old name was specific to the old model. * Make the getPOTMsgSet* methods side-aware, i.e. convert them to the new model. * Convert all of test_pofile.py to the new model (i.e. use makeCurrentTranslationMessage). Part of this was needed to make the tests pass again. == Tests == bin/test -vvcm lp.translations.tests.test_pofile pofile.txt ist still failng that will be fixed in the next branch. -- https://code.launchpad.net/~henninge/launchpad/db-devel-bug-611668-filtermethods-2/+merge/42293 Your team Launchpad code reviewers is requested to review the proposed merge of lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-2 into lp:launchpad/db-devel.
=== modified file 'lib/lp/translations/browser/pofile.py' --- lib/lp/translations/browser/pofile.py 2010-11-27 01:29:40 +0000 +++ lib/lp/translations/browser/pofile.py 2010-11-30 19:32:18 +0000 @@ -428,7 +428,7 @@ 'untranslated': self.context.getPOTMsgSetUntranslated, 'new_suggestions': self.context.getPOTMsgSetWithNewSuggestions, 'changed_in_ubuntu': - self.context.getPOTMsgSetChangedInUbuntu, + self.context.getPOTMsgSetDifferentTranslations, } if self.show not in get_functions: @@ -947,7 +947,7 @@ 'untranslated': self.context.getPOTMsgSetUntranslated, 'new_suggestions': self.context.getPOTMsgSetWithNewSuggestions, 'changed_in_ubuntu': - self.context.getPOTMsgSetChangedInUbuntu, + self.context.getPOTMsgSetDifferentTranslations, } if self.show not in get_functions: === modified file 'lib/lp/translations/doc/pofile.txt' --- lib/lp/translations/doc/pofile.txt 2010-11-30 19:32:17 +0000 +++ lib/lp/translations/doc/pofile.txt 2010-11-30 19:32:18 +0000 @@ -46,7 +46,7 @@ >>> dummy_pofile.getPOTMsgSetTranslated().count() 0 - >>> dummy_pofile.getPOTMsgSetChangedInUbuntu().count() + >>> dummy_pofile.getPOTMsgSetDifferentTranslations().count() 0 >>> dummy_pofile.getPOTMsgSetWithNewSuggestions().count() === modified file 'lib/lp/translations/interfaces/pofile.py' --- lib/lp/translations/interfaces/pofile.py 2010-11-29 07:12:01 +0000 +++ lib/lp/translations/interfaces/pofile.py 2010-11-30 19:32:18 +0000 @@ -184,12 +184,8 @@ """Get pot message sets with suggestions submitted after last review. """ - def getPOTMsgSetChangedInUbuntu(): - """Get pot message sets changed through Launchpad in this PO file. - - 'Changed in Ubuntu' are only those which were translated when - initially imported, but then got overridden in Ubuntu translations - through Launchpad. + def getPOTMsgSetDifferentTranslations(): + """Get pot message sets with different translations on both sides. """ def getTranslationsFilteredBy(person): === modified file 'lib/lp/translations/model/pofile.py' --- lib/lp/translations/model/pofile.py 2010-11-30 19:32:17 +0000 +++ lib/lp/translations/model/pofile.py 2010-11-30 19:32:18 +0000 @@ -558,9 +558,11 @@ Return a tuple of SQL (clauses, clause_tables) to be used with POTMsgSet.select(). """ + flag_name = getUtility(ITranslationSideTraitsSet).getForTemplate( + self.potemplate).flag_name clause_tables = ['TranslationTemplateItem', 'TranslationMessage'] clauses = self._getClausesForPOFileMessages() - clauses.append('TranslationMessage.is_current_ubuntu IS TRUE') + clauses.append('TranslationMessage.%s IS TRUE' % flag_name) self._appendCompletePluralFormsConditions(clauses) # A message is current in this pofile if: @@ -579,11 +581,15 @@ SELECT * FROM TranslationMessage AS diverged WHERE diverged.potemplate=%(potemplate)s AND - diverged.is_current_ubuntu IS TRUE AND + diverged.%(flag_name)s IS TRUE AND diverged.language = %(language)s AND diverged.potmsgset=TranslationMessage.potmsgset)''' % ( - dict(language=quote(self.language), - potemplate=quote(self.potemplate))), + dict( + flag_name=flag_name, + language=quote(self.language), + potemplate=quote(self.potemplate), + ) + ), ] shared_translation_query = ' AND '.join(shared_translation_clauses) @@ -635,23 +641,26 @@ def getPOTMsgSetWithNewSuggestions(self): """See `IPOFile`.""" + flag_name = getUtility(ITranslationSideTraitsSet).getForTemplate( + self.potemplate).flag_name clauses = self._getClausesForPOFileMessages() msgstr_clause = make_plurals_sql_fragment( "TranslationMessage.msgstr%(form)d IS NOT NULL", "OR") clauses.extend([ 'TranslationTemplateItem.potmsgset = POTMsgSet.id', - 'TranslationMessage.is_current_ubuntu IS NOT TRUE', - "(%s)" % msgstr_clause, + 'TranslationMessage.%s IS NOT TRUE' % flag_name, + "(%s)" % msgstr_clause ]) diverged_translation_query = ( '''(SELECT COALESCE(diverged.date_reviewed, diverged.date_created) FROM TranslationMessage AS diverged WHERE - diverged.is_current_ubuntu IS TRUE AND + diverged.%(flag_name)s IS TRUE AND diverged.potemplate = %(potemplate)s AND diverged.language = %(language)s AND diverged.potmsgset=POTMsgSet.id)''' % dict( + flag_name=flag_name, potemplate=quote(self.potemplate), language=quote(self.language))) @@ -659,10 +668,11 @@ '''(SELECT COALESCE(shared.date_reviewed, shared.date_created) FROM TranslationMessage AS shared WHERE - shared.is_current_ubuntu IS TRUE AND + shared.%(flag_name)s IS TRUE AND shared.potemplate IS NULL AND shared.language = %(language)s AND shared.potmsgset=POTMsgSet.id)''' % dict( + flag_name=flag_name, language=quote(self.language))) beginning_of_time = "TIMESTAMP '1970-01-01 00:00:00'" newer_than_query = ( @@ -685,7 +695,7 @@ return self._getOrderedPOTMsgSets( [POTMsgSet, TranslationTemplateItem], query) - def getPOTMsgSetChangedInUbuntu(self): + def getPOTMsgSetDifferentTranslations(self): """See `IPOFile`.""" # POT set has been changed in Launchpad if it contains active # translations which didn't come from an upstream package @@ -699,28 +709,33 @@ # exists imported (is_current_upstream AND not empty AND ( # diverged OR shared)) clauses, clause_tables = self._getTranslatedMessagesQuery() + other_side_flag_name = getUtility( + ITranslationSideTraitsSet).getForTemplate( + self.potemplate).other_side_traits.flag_name clauses.extend([ 'TranslationTemplateItem.potmsgset = POTMsgSet.id', - 'TranslationMessage.is_current_upstream IS FALSE', + 'TranslationMessage.%s IS FALSE' % other_side_flag_name, ]) imported_no_diverged = ( '''NOT EXISTS ( SELECT * FROM TranslationMessage AS diverged WHERE - diverged.is_current_upstream IS TRUE AND + diverged.%(flag_name)s IS TRUE AND diverged.id <> imported.id AND diverged.potemplate = %(potemplate)s AND diverged.language = %(language)s AND diverged.potmsgset=TranslationMessage.potmsgset)''' % ( - dict(potemplate=quote(self.potemplate), - language=quote(self.language)))) - + dict( + flag_name=other_side_flag_name, + potemplate=quote(self.potemplate), + language=quote(self.language)) + )) imported_clauses = [ 'imported.id <> TranslationMessage.id', 'imported.potmsgset = POTMsgSet.id', 'imported.language = %s' % sqlvalues(self.language), - 'imported.is_current_upstream IS TRUE', + 'imported.%s IS TRUE' % other_side_flag_name, '(imported.potemplate=%s OR ' % sqlvalues(self.potemplate) + ' (imported.potemplate IS NULL AND ' + imported_no_diverged + ' ))', @@ -1308,7 +1323,7 @@ """See `IPOFile`.""" return EmptyResultSet() - def getPOTMsgSetChangedInUbuntu(self): + def getPOTMsgSetDifferentTranslations(self): """See `IPOFile`.""" return EmptyResultSet() === modified file 'lib/lp/translations/tests/test_pofile.py' --- lib/lp/translations/tests/test_pofile.py 2010-11-30 19:32:17 +0000 +++ lib/lp/translations/tests/test_pofile.py 2010-11-30 19:32:18 +0000 @@ -185,9 +185,10 @@ # When a diverged translation is added after the shared suggestion, # there are no unreviewed suggestions. diverged_date = suggestion_date + timedelta(1) - diverged_translation_2 = self.factory.makeTranslationMessage( + diverged_translation_2 = self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"], date_updated=diverged_date) + translations=[u"Translation"], date_created=diverged_date, + date_reviewed=diverged_date, diverged=True) diverged_translation.is_current_ubuntu = False diverged_translation_2.potemplate = self.devel_potemplate diverged_translation_2.is_current_ubuntu = True @@ -296,7 +297,7 @@ self.assertEquals(found_potmsgsets, [plural_potmsgset]) # Search translations as well. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=potmsgset, translations=[u"One translation message"]) found_potmsgsets = list( @@ -304,7 +305,7 @@ self.assertEquals(found_potmsgsets, [potmsgset]) # Search matches all plural forms. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=plural_potmsgset, translations=[u"One translation message", u"Plural translation message", @@ -345,7 +346,7 @@ self.assertEquals(found_translations, []) # If 'submitter' provides a translation, it's returned in a list. - translation = self.factory.makeTranslationMessage( + translation = self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=potmsgset, translations=[u"Translation message"], translator=submitter) @@ -356,7 +357,7 @@ # If somebody else provides a translation, it's not added to the # list of submitter's translations. someone_else = self.factory.makePerson() - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=potmsgset, translations=[u"Another translation"], translator=someone_else) @@ -372,7 +373,7 @@ self.devel_sr_latin_pofile = self.factory.makePOFile( 's...@latin', potemplate=self.devel_potemplate) - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_sr_latin_pofile, potmsgset=potmsgset, translations=[u"Yet another translation"], translator=submitter) @@ -400,17 +401,17 @@ self.assertEquals(found_translations, []) # When a diverged translation is added, the potmsgset is returned. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"]) + translations=[u"Translation"], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetTranslated()) self.assertEquals(found_translations, [self.potmsgset]) # If diverged translation is empty, POTMsgSet is not listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u""]) + translations=[u""], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetTranslated()) self.assertEquals(found_translations, []) @@ -420,7 +421,7 @@ # translation for the POTMsgSet as well. # We create a shared translation first. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, translations=[u"Shared translation"]) @@ -430,17 +431,17 @@ self.assertEquals(found_translations, [self.potmsgset]) # When an empty diverged translation is added, nothing is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u""]) + translations=[u""], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetTranslated()) self.assertEquals(found_translations, []) # If diverged translation is non-empty, POTMsgSet is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"]) + translations=[u"Translation"], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetTranslated()) self.assertEquals(found_translations, [self.potmsgset]) @@ -450,7 +451,7 @@ # empty shared translation for the POTMsgSet as well. # We create an empty shared translation first. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, translations=[u""]) @@ -461,17 +462,17 @@ self.assertEquals(found_translations, []) # When an empty diverged translation is added, nothing is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u""]) + translations=[u""], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetTranslated()) self.assertEquals(found_translations, []) # If diverged translation is non-empty, POTMsgSet is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"]) + translations=[u"Translation"], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetTranslated()) self.assertEquals(found_translations, [self.potmsgset]) @@ -481,16 +482,16 @@ # translated message. # Add a diverged translation on the included POTMsgSet... - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Diverged translation"]) + translations=[u"Diverged translation"], diverged=True) # and a shared translation on newly added POTMsgSet... potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate, u"Translated text") potmsgset.setSequence(self.devel_potemplate, 2) - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=potmsgset, translations=[u"Shared translation"]) @@ -509,17 +510,17 @@ self.assertEquals(found_translations, [self.potmsgset]) # When a diverged translation is added, the potmsgset is returned. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"]) + translations=[u"Translation"], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetUntranslated()) self.assertEquals(found_translations, []) # If diverged translation is empty, POTMsgSet is not listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u""]) + translations=[u""], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetUntranslated()) self.assertEquals(found_translations, [self.potmsgset]) @@ -529,7 +530,7 @@ # translation for the POTMsgSet as well. # We create a shared translation first. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, translations=[u"Shared translation"]) @@ -539,17 +540,17 @@ self.assertEquals(found_translations, []) # When an empty diverged translation is added, nothing is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u""]) + translations=[u""], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetUntranslated()) self.assertEquals(found_translations, [self.potmsgset]) # If diverged translation is non-empty, POTMsgSet is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"]) + translations=[u"Translation"], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetUntranslated()) self.assertEquals(found_translations, []) @@ -559,7 +560,7 @@ # empty shared translation for the POTMsgSet as well. # We create an empty shared translation first. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, translations=[u""]) @@ -570,17 +571,17 @@ self.assertEquals(found_translations, [self.potmsgset]) # When an empty diverged translation is added, nothing is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u""]) + translations=[u""], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetUntranslated()) self.assertEquals(found_translations, [self.potmsgset]) # If diverged translation is non-empty, POTMsgSet is listed. - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"]) + translations=[u"Translation"], diverged=True) found_translations = list( self.devel_pofile.getPOTMsgSetUntranslated()) self.assertEquals(found_translations, []) @@ -590,7 +591,7 @@ # untranslated message. # Add an empty translation to the included POTMsgSet... - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, translations=[u""]) @@ -635,9 +636,10 @@ u"Translated text") potmsgset.setSequence(self.devel_potemplate, 2) date_created = datetime.now(pytz.UTC) - timedelta(5) - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Translation"], date_updated=date_created) + translations=[u"Translation"], + date_created=date_created, date_reviewed=date_created) suggestion_date = date_created + timedelta(1) self.factory.makeSuggestion( pofile=self.devel_pofile, potmsgset=potmsgset, @@ -681,136 +683,53 @@ self.devel_pofile.getPOTMsgSetWithNewSuggestions()) self.assertEquals([], found_translations) - def test_getPOTMsgSetChangedInUbuntu(self): + def test_getPOTMsgSetDifferentTranslations(self): # Test listing of POTMsgSets which contain changes from imports. - - # If there are no translations in Ubuntu, nothing is listed. - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, []) - - # Adding a non-imported current translation doesn't change anything. - translation = self.factory.makeSharedTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Non-imported translation"]) - self.assertEquals(translation.is_current_upstream, False) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, []) - - # Adding an imported translation which is also current indicates - # that there are no changes. - translation = self.factory.makeSharedTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Imported translation"], is_current_upstream=True) - self.assertEquals(translation.is_current_upstream, True) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, []) - - # However, changing current translation to a non-imported one - # makes this a changed in Ubuntu translation. - translation = self.factory.makeSharedTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Changed translation"], is_current_upstream=False) - self.assertEquals(translation.is_current_upstream, False) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, [self.potmsgset]) - - # Adding a diverged, non-imported translation, still lists - # it as a changed translation. - translation = self.factory.makeTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Diverged translation"], is_current_upstream=False) - self.assertEquals(translation.is_current_upstream, False) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, [self.potmsgset]) - - # But adding a diverged current and imported translation means - # that it's not changed anymore. - translation = self.factory.makeTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Diverged imported"], is_current_upstream=True, - force_diverged=True) - self.assertEquals(translation.is_current_upstream, True) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, []) - - # Changing from a diverged, imported translation is correctly - # detected. - translation = self.factory.makeTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Diverged changed"], is_current_upstream=False) - self.assertEquals(translation.is_current_upstream, False) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, [self.potmsgset]) - - def test_getPOTMsgSetChangedInUbuntu_diverged_imported(self): - # If there is a diverged imported (but non-current) message - # and a shared current message, it should not be listed as changed. - # Even though that is generally incorrect, this is a situation - # we can't come to with new code and is a residue of old data - # (see bug #455680 for details). - - # To hit the bug, we need: - # 1) Shared imported and current translation. - # 2) Diverged, imported, non-current message. - shared = self.factory.makeSharedTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Shared imported current"], - is_current_upstream=True) - diverged = self.factory.makeTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Diverged imported non-current"], - is_current_upstream=True, force_diverged=True) - # As we can't come to this situation using existing code, - # we modify the is_current_ubuntu flag directly. - diverged.is_current_ubuntu = False - - self.assertEquals(shared.is_current_upstream, True) - self.assertEquals(shared.is_current_ubuntu, True) - self.assertIs(shared.potemplate, None) - self.assertEquals(diverged.is_current_upstream, True) - self.assertEquals(diverged.is_current_ubuntu, False) - self.assertEquals(diverged.potemplate, self.devel_potemplate) - - # Such POTMsgSet is not considered changed in this PO file. - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, []) - - def test_getPOTMsgSetChangedInUbuntu_SharedDiverged(self): - # Test listing of changed in Ubuntu for shared/diverged messages. - - # Adding an imported translation which is also current indicates - # that there are no changes. - translation = self.factory.makeSharedTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Imported translation"], is_current_upstream=True) - self.assertEquals(translation.is_current_upstream, True) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) - self.assertEquals(found_translations, []) - - # Adding a diverged, non-imported translation makes it appear - # as changed. - translation = self.factory.makeTranslationMessage( - pofile=self.devel_pofile, potmsgset=self.potmsgset, - translations=[u"Changed translation"], is_current_upstream=False) - self.assertEquals(translation.is_current_upstream, False) - self.assertEquals(translation.is_current_ubuntu, True) - found_translations = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) + # The factory assumes upstream as "this side". + + # If there are no translations on this side, nothing is listed. + found_translations = list( + self.devel_pofile.getPOTMsgSetDifferentTranslations()) + self.assertEquals(found_translations, []) + + # Adding a current translation on one side doesn't change anything. + translation = self.factory.makeCurrentTranslationMessage( + pofile=self.devel_pofile, potmsgset=self.potmsgset, + translations=[u"This side translation"]) + self.assertEquals(translation.is_current_ubuntu, False) + found_translations = list( + self.devel_pofile.getPOTMsgSetDifferentTranslations()) + self.assertEquals(found_translations, []) + + # Adding a translation on both sides does not introduce a difference. + translation = self.factory.makeCurrentTranslationMessage( + pofile=self.devel_pofile, potmsgset=self.potmsgset, + translations=[u"Imported translation"], current_other=True) + self.assertEquals(translation.is_current_upstream, True) + self.assertEquals(translation.is_current_ubuntu, True) + found_translations = list( + self.devel_pofile.getPOTMsgSetDifferentTranslations()) + self.assertEquals(found_translations, []) + + # Changing the translation on one side makes them different. + translation = self.factory.makeCurrentTranslationMessage( + pofile=self.devel_pofile, potmsgset=self.potmsgset, + translations=[u"Changed translation"]) + self.assertEquals(translation.is_current_upstream, True) + self.assertEquals(translation.is_current_ubuntu, False) + found_translations = list( + self.devel_pofile.getPOTMsgSetDifferentTranslations()) + self.assertEquals(found_translations, [self.potmsgset]) + + # Adding a diverged translation, still lists it as a changed + # translation. + translation = self.factory.makeCurrentTranslationMessage( + pofile=self.devel_pofile, potmsgset=self.potmsgset, + translations=[u"Diverged translation"], diverged=True) + self.assertEquals(translation.is_current_upstream, True) + self.assertEquals(translation.is_current_ubuntu, False) + found_translations = list( + self.devel_pofile.getPOTMsgSetDifferentTranslations()) self.assertEquals(found_translations, [self.potmsgset]) def test_messageCount(self): @@ -1260,11 +1179,11 @@ def test_getPOTMsgSetTranslated_ordering(self): # Translate both POTMsgSets in devel_pofile, so # they are returned with getPOTMsgSetTranslated() call. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset1, translations=["Shared translation"]) - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset2, translations=["Another shared translation"]) @@ -1315,32 +1234,30 @@ self.assertEquals( [self.potmsgset1, self.potmsgset2], untranslated_potmsgsets) - def test_getPOTMsgSetChangedInUbuntu_ordering(self): + def test_getPOTMsgSetDifferentTranslations_ordering(self): # Suggest a translation on both POTMsgSets in devel_pofile, # so they are returned with getPOTMsgSetWithNewSuggestions() call. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset1, translations=["Imported"], - is_current_upstream=True) - self.factory.makeSharedTranslationMessage( + current_other=True) + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset1, - translations=["Changed"], - is_current_upstream=False) - self.factory.makeSharedTranslationMessage( + translations=["Changed"]) + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset2, translations=["Another imported"], - is_current_upstream=True) - self.factory.makeSharedTranslationMessage( + current_other=True) + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset2, - translations=["Another changed"], - is_current_upstream=False) + translations=["Another changed"]) potmsgsets = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) + self.devel_pofile.getPOTMsgSetDifferentTranslations()) self.assertEquals( [self.potmsgset1, self.potmsgset2], potmsgsets) @@ -1351,13 +1268,13 @@ # And they are returned in the new order as desired. potmsgsets = list( - self.stable_pofile.getPOTMsgSetChangedInUbuntu()) + self.stable_pofile.getPOTMsgSetDifferentTranslations()) self.assertEquals( [self.potmsgset2, self.potmsgset1], potmsgsets) # Order is unchanged for the previous template. potmsgsets = list( - self.devel_pofile.getPOTMsgSetChangedInUbuntu()) + self.devel_pofile.getPOTMsgSetDifferentTranslations()) self.assertEquals( [self.potmsgset1, self.potmsgset2], potmsgsets) @@ -1391,11 +1308,11 @@ # This test will go away when potmsgset.sequence goes away. # Give the method something to search for. - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset1, translations=["Shared translation"]) - self.factory.makeSharedTranslationMessage( + self.factory.makeCurrentTranslationMessage( pofile=self.devel_pofile, potmsgset=self.potmsgset2, translations=["Another shared translation"]) @@ -2030,23 +1947,23 @@ def test_getTranslationMessages_current_shared(self): # A shared message is included in this POFile's messages. - message = self.factory.makeTranslationMessage( - potmsgset=self.potmsgset, pofile=self.pofile, force_shared=True) + message = self.factory.makeCurrentTranslationMessage( + potmsgset=self.potmsgset, pofile=self.pofile) self.assertEqual( [message], list(self.pofile.getTranslationMessages())) def test_getTranslationMessages_current_diverged(self): # A diverged message is included in this POFile's messages. - message = self.factory.makeTranslationMessage( - potmsgset=self.potmsgset, pofile=self.pofile, force_diverged=True) + message = self.factory.makeCurrentTranslationMessage( + potmsgset=self.potmsgset, pofile=self.pofile, diverged=True) self.assertEqual( [message], list(self.pofile.getTranslationMessages())) def test_getTranslationMessages_suggestion(self): # A suggestion is included in this POFile's messages. - message = self.factory.makeTranslationMessage( + message = self.factory.makeSuggestion( potmsgset=self.potmsgset, pofile=self.pofile) self.assertEqual( @@ -2056,8 +1973,8 @@ # A message on an obsolete POTMsgSEt is included in this # POFile's messages. potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0) - message = self.factory.makeTranslationMessage( - potmsgset=potmsgset, pofile=self.pofile, force_shared=True) + message = self.factory.makeCurrentTranslationMessage( + potmsgset=potmsgset, pofile=self.pofile) self.assertEqual( [message], list(self.pofile.getTranslationMessages())) @@ -2065,7 +1982,7 @@ def test_getTranslationMessages_other_pofile(self): # A message from another POFiles is not included. other_pofile = self.factory.makePOFile('de') - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( potmsgset=self.potmsgset, pofile=other_pofile) self.assertEqual([], list(self.pofile.getTranslationMessages())) @@ -2073,8 +1990,8 @@ def test_getTranslationMessages_condition_matches(self): # A message matching the given condition is included. # Diverged messages are linked to a specific POTemplate. - message = self.factory.makeTranslationMessage( - potmsgset=self.potmsgset, pofile=self.pofile, force_diverged=True) + message = self.factory.makeCurrentTranslationMessage( + potmsgset=self.potmsgset, pofile=self.pofile, diverged=True) self.assertContentEqual( [message], @@ -2084,8 +2001,8 @@ def test_getTranslationMessages_condition_matches_not(self): # A message not matching the given condition is excluded. # Shared messages are not linked to a POTemplate. - self.factory.makeTranslationMessage( - potmsgset=self.potmsgset, pofile=self.pofile, force_shared=True) + self.factory.makeCurrentTranslationMessage( + potmsgset=self.potmsgset, pofile=self.pofile) self.assertContentEqual( [], @@ -2096,9 +2013,9 @@ # A message matching given condition but located in another POFile # is not included. other_pofile = self.factory.makePOFile('de') - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( potmsgset=self.potmsgset, pofile=other_pofile, - force_diverged=True) + diverged=True) self.assertContentEqual( [], @@ -2116,9 +2033,9 @@ other_pofile = other_template.getPOFileByLang( self.pofile.language.code) self.potmsgset.setSequence(other_template, 1) - self.factory.makeTranslationMessage( + self.factory.makeCurrentTranslationMessage( potmsgset=self.potmsgset, pofile=other_pofile, - force_diverged=True) + diverged=True) self.assertEqual([], list(self.pofile.getTranslationMessages())) @@ -2863,3 +2780,48 @@ potemplate=self.factory.makePOTemplate( distroseries=package.distroseries, sourcepackagename=package.sourcepackagename)) + + +class StatistcsFiltersTestScenario(StatisticsTestScenario): + """Test the filter functions in `POFile`s compared to statistics.""" + + def exerciseFunction(self, pofile): + """Run the function under test.""" + pofile.updateStatistics() + + def getCurrentCount(self, pofile): + return pofile.currentCount() + + def getRosettaCount(self, pofile): + return pofile.rosettaCount() + + def getTranslatedCount(self, pofile): + return pofile.getPOTMsgSetTranslated().count() + + def getUnreviewedCount(self, pofile): + return pofile.getPOTMsgSetWithNewSuggestions().count() + + def getUntranslatedCount(self, pofile): + return pofile.getPOTMsgSetUntranslated().count() + + def getUpdatesCount(self, pofile): + return pofile.getPOTMsgSetDifferentTranslations().count() + + +class TestUpstreamFilters(StatistcsFiltersTestScenario, TestCaseWithFactory): + """Test filters on upstream `POFile`s.""" + + def makePOFile(self): + return self.factory.makePOFile() + + +class TestUbuntuFilters(StatistcsFiltersTestScenario, TestCaseWithFactory): + """Test filters on Ubuntu `POFile`s.""" + + def makePOFile(self): + package = self.factory.makeSourcePackage() + return self.factory.makePOFile( + potemplate=self.factory.makePOTemplate( + distroseries=package.distroseries, + sourcepackagename=package.sourcepackagename)) +
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp