I believe this reduced the usefulness of these tests as a documentation
for submitSuggestion() method. And yet, you have added no documentation
whatsoever.
How does using these for loops improve readability of the test? FWIW,
what
does it bring other than making it harder to read the test? :)
At least the first for loop should be directly spelled-out so it's clear
what is tested.
> + def test_same_as_shared(self):
> + # A suggestion identical to a shared current translation is a
> + # repeated suggestion.
> + pofile, potmsgset = self._makePOFileAndPOTMsgSet()
> + translation = {0: self.factory.getUniqueString()}
> + shared_message = potmsgset.updateTranslation(
> + pofile, pofile.potemplate.owner, translation, True,
> + datetime.now(pytz.UTC), force_shared=True)
Any reason you are not using factory.makeSharedTranslationMessage here?
It will be of great help once we start getting rid of
updateTranslation()
calls (i.e. we'll only have to change behaviour in the factory).
> + def test_same_as_diverged(self):
> + # A suggestion identical to a diverged current translation
for
> + # the same template is a repeated suggestion.
> + pofile, potmsgset = self._makePOFileAndPOTMsgSet()
> + translation = {0: self.factory.getUniqueString()}
> + diverged_message = potmsgset.updateTranslation(
> + pofile, pofile.potemplate.owner, translation, True,
> + datetime.now(pytz.UTC), force_diverged=True)
Same as above, though use factory.makeTranslationMessage.
> === modified file 'lib/lp/ translations/ model/potmsgset .py' translations/ model/potmsgset .py 2010-03-23 15:39:12 translations/ model/potmsgset .py 2010-03-25 00:11:17 message. sync() n(self, pofile, submitter, new_translations): translation_ credit: nslations( new_translation s) lationMessage( plural_ forms)
> --- lib/lp/
+0000
> +++ lib/lp/
+0000
> @@ -888,6 +888,36 @@
> matching_
> return matching_message
>
> + def submitSuggestio
> + """See `IPOTMsgSet`."""
> + if self.is_
> + # We don't support suggestions on credits messages.
> + return None
> +
> + potranslations = self._findPOTra
> +
> + existing_message = self._findTrans
> + pofile, potranslations, pofile.
> + if existing_message is not None:
> + return existing_message
In the end you still included this logic as part of submitSuggestion? I
guess we can move it out later if it turns out that's what we want.
> === modified file 'lib/lp/ translations/ tests/test_ potmsgset. py' l(credits_ type, translation_ credits_ type)
> @@ -1267,5 +1271,274 @@
> self.assertEqua
credits.
>
>
> +class KarmaListener:
Any reason not to put this inside lib/lp/ registry/ tests/karma. py?
> +class TestPOTMsgSet_ submitSuggestio n(TestCaseWithF actory) : submitSuggestio n`.""" eLayer OTMsgSet( self, msgid=None, with_plural=False):
> + """Test `POTMsgSet.
> +
> + layer = ZopelessDatabas
> +
> + def _makePOFileAndP
In general, if you find that you need such a method, we might probably
need it in other cases as well. So, why not put it into the factory?
> + """Set up a `POFile` with `POTMsgSet`.""" makePOFile( 'nl') getUniqueString () getUniqueString () makePOTMsgSet( singular_ text,
> + pofile = self.factory.
> + if msgid is None:
> + singular_text = self.factory.
> + else:
> + singular_text = msgid
> + if with_plural:
> + plural_text = self.factory.
> + else:
> + plural_text = None
> + potmsgset = self.factory.
> + pofile.potemplate, singular=
plural=plural_text)
> +
Some extra whitespace here.
> + return pofile, potmsgset n.""" submitSuggestio n( potemplate. owner, translations)
> +
> + def _suggest(self, pofile, potmsgset, translations):
> + """Convenience shorthand for submitSuggestio
> + return potmsgset.
> + pofile, pofile.
I believe this reduced the usefulness of these tests as a documentation
for submitSuggestion() method. And yet, you have added no documentation
whatsoever.
> + def test_plural_ forms(self) : eAndPOTMsgSet( with_plural= True) getUniqueString (), getUniqueString (), pofile, potmsgset, translations) iteritems( ): tants.MAX_ PLURAL_ FORMS):
> + pofile, potmsgset =
self._makePOFil
> + translations = {
> + 0: self.factory.
> + 1: self.factory.
> + }
> +
> + suggestion = self._suggest(
> + for form, translation in translations.
> + self.assertEqual(
> + translation,
> + getattr(suggestion, 'msgstr%d' % form).translation)
> + for form in xrange(2, TranslationCons
> + self.assertIs(None, getattr(suggestion, 'msgstr%d' %
form))
How does using these for loops improve readability of the test? FWIW,
what
does it bring other than making it harder to read the test? :)
At least the first for loop should be directly spelled-out so it's clear
what is tested.
> + def test_same_ as_shared( self): eAndPOTMsgSet( ) getUniqueString ()} updateTranslati on( potemplate. owner, translation, True, now(pytz. UTC), force_shared=True)
> + # A suggestion identical to a shared current translation is a
> + # repeated suggestion.
> + pofile, potmsgset = self._makePOFil
> + translation = {0: self.factory.
> + shared_message = potmsgset.
> + pofile, pofile.
> + datetime.
Any reason you are not using factory. makeSharedTrans lationMessage here?
It will be of great help once we start getting rid of
updateTranslation()
calls (i.e. we'll only have to change behaviour in the factory).
> + def test_same_ as_diverged( self): eAndPOTMsgSet( ) getUniqueString ()} updateTranslati on( potemplate. owner, translation, True, now(pytz. UTC), force_diverged= True)
> + # A suggestion identical to a diverged current translation
for
> + # the same template is a repeated suggestion.
> + pofile, potmsgset = self._makePOFil
> + translation = {0: self.factory.
> + diverged_message = potmsgset.
> + pofile, pofile.
> + datetime.
Same as above, though use factory. makeTranslation Message.
> + def test_same_ as_diverged_ elsewhere( self):
> + def test_same_ as_hidden_ shared( self):
Replace updateTranslation usage, please.
> + def test_credits_ message( self): eAndPOTMsgSet( translator- credits' ) getUniqueString ()}
> + # Suggestions for translation-credits messages are ignored.
> + pofile, potmsgset = self._makePOFil
> + msgid='
> + translation = {0: self.factory.
It'd be nice to demonstrate that this message is_translation_ credit.
review needs-fixing code
Cheers,
Danilo