def testMergeSuccess(self):
        arrays = []
        max_items = 10
        # create independend string arrays
        for lang in self.languages:
            array = StringArray('key', [lang])
            for index in range(0, max_items):
                array.add(lang, index, self.__build_test_string(lang, index))
            arrays.append(array)

        # check all items contain proper number of items for each language
        for array in arrays:
            for lang in array.languages:
                self.assertEqual(array.size(lang), max_items)

        # create empty string array
        merged = StringArray('key', [])

        # merge all arrays
        for array in arrays:
            merged.merge(array)

        # check if resulting array contains all languages from all merged items
        combined_languages = set()
        for array in arrays:
            combined_languages.update(array.languages)
        self.assertEqual(combined_languages, merged.languages)

        # check if merged item contain proper number of items for each language
        for lang in merged.languages:
            self.assertEqual(merged.size(lang), max_items)
 def testMergeWithDifferentKeysFail(self):
     array1 = StringArray('key a', ['en'])
     array2 = StringArray('key b', ['fr'])
     try:
         array1.merge(array2)
         self.fail('This operation should fail')
     except MstException:
         pass
 def testMergeWithSameLanguagesFail(self):
     array1 = StringArray('key', ['en', 'fr'])
     array2 = StringArray('key', ['en', 'de'])
     try:
         array1.merge(array2)
         self.fail('This operation should fail')
     except MstException:
         pass
 def testMergeWithDifferentKeysFail(self):
     array1 = StringArray('key a', ['en'])
     array2 = StringArray('key b', ['fr'])
     try:
         array1.merge(array2)
         self.fail('This operation should fail')
     except MstException:
         pass
 def testMergeWithSameLanguagesFail(self):
     array1 = StringArray('key', ['en', 'fr'] )
     array2 = StringArray('key', ['en', 'de'] )
     try:
         array1.merge(array2)
         self.fail('This operation should fail')
     except MstException:
         pass        
 def testAddWithValidLanguageSucceed(self):
     string_array = StringArray('key', self.valid_languages)
     for index in range(0,3):
         for lang in self.valid_languages:
             text = build_test_string(lang)
             string_array.add(lang, index, text )
             self.assertEqual( text, string_array.get(lang, index) )   # get added item
             self.assertEqual( string_array.size(lang), index+1)       # check array size
 def testKeyCanBeAssignedOnlyOne(self):
     key = "key"
     string_array = StringArray(key, [])
     self.assertEqual(string_array.key, key)
     try:
         string_array.key = "different key"
         self.fail("This operation should fail")
     except AttributeError:
         pass
 def testKeyCanBeAssignedOnlyOne(self):
     key = "key"
     string_array = StringArray(key, [])
     self.assertEqual(string_array.key, key)
     try:
         string_array.key = "different key"
         self.fail("This operation should fail")
     except AttributeError:
         pass
 def testAddWithInvalidLanguageFails(self):
     string_array = StringArray('key', self.valid_languages)
     for index in range(0, 3):
         for lang in self.invalid_languages:
             text = build_test_string(lang)
             try:
                 string_array.add(lang, index, text)
                 self.fail('Operation should fail for language %s' % lang)
             except MstException:
                 pass
 def testAddWithInvalidLanguageFails(self):
     string_array = StringArray('key', self.valid_languages)
     for index in range(0,3):
         for lang in self.invalid_languages:
             text = build_test_string(lang)
             try:
                 string_array.add(lang, index, text )
                 self.fail('Operation should fail for language %s' % lang)
             except MstException:
                 pass
 def testMergeSuccess(self):
     arrays = []
     max_items = 10
     # create independend string arrays
     for lang in self.languages:
         array = StringArray('key', [lang])
         for index in range(0,max_items):
             array.add(lang, index, self.__build_test_string(lang, index))
         arrays.append(array)
     
     # check all items contain proper number of items for each language
     for array in arrays:
         for lang in array.languages:
             self.assertEqual( array.size(lang), max_items )
     
     # create empty string array
     merged = StringArray('key', [])
     
     # merge all arrays
     for array in arrays:
         merged.merge(array)
     
     # check if resulting array contains all languages from all merged items
     combined_languages = set()
     for array in arrays:
         combined_languages.update( array.languages )
     self.assertEqual( combined_languages, merged.languages )
     
     # check if merged item contain proper number of items for each language        
     for lang in merged.languages:
         self.assertEqual( merged.size(lang), max_items ) 
 def testKeyMustBeAString(self):
     keys = [object(), [], {}, ()]
     for key in keys:
         try:
             string_array = StringArray(key, [])
             self.fail("This operation should fail")
         except ValueError:
             pass
 def testAddWithValidLanguageSucceed(self):
     string_array = StringArray('key', self.valid_languages)
     for index in range(0, 3):
         for lang in self.valid_languages:
             text = build_test_string(lang)
             string_array.add(lang, index, text)
             self.assertEqual(text,
                              string_array.get(lang,
                                               index))  # get added item
             self.assertEqual(string_array.size(lang),
                              index + 1)  # check array size
 def get_string_arrays(self):
     """Collect all StringArray resources and return a list"""
     resources = {}
     for row in self.data:
         if (self._get_row_type(row) == self.TYPE_STRING_ARRAY
                 and self._has_valid_key(row)):
             key_with_index = row[self.id_column]
             key, index = key_with_index.split(':')
             if (key in resources) == False:
                 resources[key] = StringArray(key, self.languages)
             sa = resources[key]
             for lang in self.languages:
                 col = self.language_column(lang)
                 text = row[col]
                 options = self._get_row_options(row)
                 sa.add(lang, int(index), ResourceText(
                     text, options))  #fixme: conversion not necessary
     return list(resources.values())
 def testArrayContainsProvidedLanguages(self):
     string_array = StringArray('key', self.valid_languages)
     self.assertEqual(self.valid_languages, string_array.languages)