예제 #1
0
    def testSemiIdenticalCliques(self):
        messages = [
            tclib.Message(
                text='Hello USERNAME',
                placeholders=[tclib.Placeholder('USERNAME', '$1', 'Joi')]),
            tclib.Message(
                text='Hello USERNAME',
                placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi')]),
        ]
        self.failUnless(messages[0].GetId() == messages[1].GetId())

        # Both of the above would share a translation.
        translation = tclib.Translation(
            id=messages[0].GetId(),
            text='Bonjour USERNAME',
            placeholders=[tclib.Placeholder('USERNAME', '$1', 'Joi')])

        factory = clique.UberClique()
        cliques = [factory.MakeClique(msg) for msg in messages]

        for clq in cliques:
            clq.AddTranslation(translation, 'fr')

        self.failUnless(cliques[0].MessageForLanguage('fr').GetRealContent() ==
                        'Bonjour $1')
        self.failUnless(cliques[1].MessageForLanguage('fr').GetRealContent() ==
                        'Bonjour %s')
예제 #2
0
    def testBestClique(self):
        factory = clique.UberClique()
        factory.MakeClique(tclib.Message(text='Alfur', description='alfaholl'))
        factory.MakeClique(tclib.Message(text='Alfur', description=''))
        factory.MakeClique(tclib.Message(text='Vaettur', description=''))
        factory.MakeClique(tclib.Message(text='Vaettur', description=''))
        factory.MakeClique(tclib.Message(text='Troll', description=''))
        factory.MakeClique(
            tclib.Message(text='Gryla', description='ID: IDS_GRYLA'))
        factory.MakeClique(
            tclib.Message(text='Gryla', description='vondakerling'))
        factory.MakeClique(
            tclib.Message(text='Leppaludi', description='ID: IDS_LL'))
        factory.MakeClique(tclib.Message(text='Leppaludi', description=''))

        count_best_cliques = 0
        for c in factory.BestCliquePerId():
            count_best_cliques += 1
            msg = c.GetMessage()
            text = msg.GetRealContent()
            description = msg.GetDescription()
            if text == 'Alfur':
                self.failUnless(description == 'alfaholl')
            elif text == 'Gryla':
                self.failUnless(description == 'vondakerling')
            elif text == 'Leppaludi':
                self.failUnless(description == 'ID: IDS_LL')
        self.failUnless(count_best_cliques == 5)
예제 #3
0
    def testBestCliqueSortIsStable(self):
        factory = clique.UberClique()
        text = 'hello'
        msg_no_description = tclib.Message(text=text)
        msg_id_description_a = tclib.Message(text=text, description='ID: a')
        msg_id_description_b = tclib.Message(text=text, description='ID: b')
        msg_description_x = tclib.Message(text=text, description='x')
        msg_description_y = tclib.Message(text=text, description='y')
        clique_id = msg_no_description.GetId()

        # Insert in an order that tests all outcomes.
        clique_no_description = factory.MakeClique(msg_no_description,
                                                   translateable=True)
        self.failUnless(factory.BestClique(clique_id) == clique_no_description)
        clique_id_description_b = factory.MakeClique(msg_id_description_b,
                                                     translateable=True)
        self.failUnless(
            factory.BestClique(clique_id) == clique_id_description_b)
        clique_id_description_a = factory.MakeClique(msg_id_description_a,
                                                     translateable=True)
        self.failUnless(
            factory.BestClique(clique_id) == clique_id_description_a)
        clique_description_y = factory.MakeClique(msg_description_y,
                                                  translateable=True)
        self.failUnless(factory.BestClique(clique_id) == clique_description_y)
        clique_description_x = factory.MakeClique(msg_description_x,
                                                  translateable=True)
        self.failUnless(factory.BestClique(clique_id) == clique_description_x)
예제 #4
0
    def __init__(self,
                 rc_file,
                 extkey=None,
                 encoding='cp1252',
                 is_skeleton=False):
        '''Initializes the gatherer object's attributes, but does not attempt to
    read the input file.

    Args:
      rc_file: The 'file' attribute of the <structure> node (usually the
               relative path to the source file).
      extkey: e.g. 'ID_MY_DIALOG'
      encoding: e.g. 'utf-8'
      is_skeleton: Indicates whether this gatherer is a skeleton gatherer, in
                   which case we should not do some types of processing on the
                   translateable bits.
    '''
        self.rc_file = rc_file
        self.extkey = extkey
        self.encoding = encoding
        # A default uberclique that is local to this object.  Users can override
        # this with the uberclique they are using.
        self.uberclique = clique.UberClique()
        # Indicates whether this gatherer is a skeleton gatherer, in which case
        # we should not do some types of processing on the translateable bits.
        self.is_skeleton = is_skeleton
        # Stores the grd node on which this gatherer is running. This allows
        # evaluating expressions.
        self.grd_node = None
예제 #5
0
 def __init__(self):
     # A default uberclique that is local to this object.  Users can override
     # this with the uberclique they are using.
     self.uberclique = clique.UberClique()
     # Indicates whether this gatherer is a skeleton gatherer, in which case
     # we should not do some types of processing on the translateable bits.
     self.is_skeleton = False
예제 #6
0
 def testValidate(self):
   factory = clique.UberClique()
   msg = tclib.Message(text='Bingo bongo')
   c = factory.MakeClique(msg)
   c.SetCustomType(filename.WindowsFilename())
   translation = tclib.Translation(id=msg.GetId(), text='Bilingo bolongo:')
   c.AddTranslation(translation, 'fr')
   self.failUnless(c.MessageForLanguage('fr').GetRealContent() == 'Bilingo bolongo ')
예제 #7
0
 def UberClique(self):
     '''Returns the uberclique that should be used for messages originating in
 a given node.  If the node itself has its uberclique set, that is what we
 use, otherwise we search upwards until we find one.  If we do not find one
 even at the root node, we set the root node's uberclique to a new
 uberclique instance.
 '''
     node = self
     while not node.uberclique and node.parent:
         node = node.parent
     if not node.uberclique:
         node.uberclique = clique.UberClique()
     return node.uberclique
예제 #8
0
 def testEachCliqueKeptSorted(self):
     factory = clique.UberClique()
     msg_a = tclib.Message(text='hello', description='a')
     msg_b = tclib.Message(text='hello', description='b')
     msg_c = tclib.Message(text='hello', description='c')
     # Insert out of order
     clique_b = factory.MakeClique(msg_b, translateable=True)
     clique_a = factory.MakeClique(msg_a, translateable=True)
     clique_c = factory.MakeClique(msg_c, translateable=True)
     clique_list = factory.cliques_[clique_a.GetId()]
     self.failUnless(len(clique_list) == 3)
     self.failUnless(clique_list[0] == clique_a)
     self.failUnless(clique_list[1] == clique_b)
     self.failUnless(clique_list[2] == clique_c)
예제 #9
0
    def testWhitespaceMessagesAreNontranslateable(self):
        factory = clique.UberClique()

        message = tclib.Message(text=' \t')
        c = factory.MakeClique(message, translateable=True)
        self.failIf(c.IsTranslateable())

        message = tclib.Message(text='\n \n ')
        c = factory.MakeClique(message, translateable=True)
        self.failIf(c.IsTranslateable())

        message = tclib.Message(text='\n hello')
        c = factory.MakeClique(message, translateable=True)
        self.failUnless(c.IsTranslateable())
예제 #10
0
  def testCustomTypes(self):
    factory = clique.UberClique()
    message = tclib.Message(text='Bingo bongo')
    c = factory.MakeClique(message)
    try:
      c.SetCustomType(DummyCustomType())
      self.fail()
    except:
      pass  # expected case - 'Bingo bongo' does not start with 'jjj'

    message = tclib.Message(text='jjjBingo bongo')
    c = factory.MakeClique(message)
    c.SetCustomType(util.NewClassInstance(
      'grit.clique_unittest.DummyCustomType', clique.CustomType))
    translation = tclib.Translation(id=message.GetId(), text='Bilingo bolongo')
    c.AddTranslation(translation, 'fr')
    self.failUnless(c.MessageForLanguage('fr').GetRealContent().startswith('jjj'))
예제 #11
0
    def testMissingTranslations(self):
        messages = [tclib.Message(text='Hello'), tclib.Message(text='Goodbye')]
        factory = clique.UberClique()
        cliques = [factory.MakeClique(msg) for msg in messages]

        cliques[1].MessageForLanguage('fr', False, True)

        self.failUnless(not factory.HasMissingTranslations())

        cliques[0].MessageForLanguage('de', False, False)

        self.failUnless(factory.HasMissingTranslations())

        report = factory.MissingTranslationsReport()
        self.failUnless(report.count('WARNING') == 1)
        self.failUnless(report.count('8053599568341804890 "Goodbye" fr') == 1)
        self.failUnless(report.count('ERROR') == 1)
        self.failUnless(report.count('800120468867715734 "Hello" de') == 1)
예제 #12
0
    def testClique(self):
        factory = clique.UberClique()
        msg = tclib.Message(
            text='Hello USERNAME, how are you?',
            placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi')])
        c = factory.MakeClique(msg)

        self.failUnless(c.GetMessage() == msg)
        self.failUnless(c.GetId() == msg.GetId())

        msg_fr = tclib.Translation(
            text='Bonjour USERNAME, comment ca va?',
            id=msg.GetId(),
            placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi')])
        msg_de = tclib.Translation(
            text='Guten tag USERNAME, wie geht es dir?',
            id=msg.GetId(),
            placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi')])

        c.AddTranslation(msg_fr, 'fr')
        factory.FindCliqueAndAddTranslation(msg_de, 'de')

        # sort() sorts lists in-place and does not return them
        for lang in ('en', 'fr', 'de'):
            self.failUnless(lang in c.clique)

        self.failUnless(
            c.MessageForLanguage('fr').GetRealContent() ==
            msg_fr.GetRealContent())

        try:
            c.MessageForLanguage('zh-CN', False)
            self.fail('Should have gotten exception')
        except:
            pass

        self.failUnless(c.MessageForLanguage('zh-CN', True) != None)

        rex = re.compile('fr|de|bingo')
        self.failUnless(len(c.AllMessagesThatMatch(rex, False)) == 2)
        self.failUnless(
            c.AllMessagesThatMatch(rex, True)[pseudo.PSEUDO_LANG] is not None)
예제 #13
0
 def setUp(self):
     self.uq = clique.UberClique()