示例#1
0
 def test_strings_parser(self):
     """STRINGS parsing tests."""
     # Parsing STRINGS content
     files = ['test_utf_16.strings', 'test_utf_8.strings',
             'test_utf_8_with_BOM.strings',]
     for i in range(1, 9):
         files.append('bad%d.strings'%i)
     for file_ in files:
         handler = AppleStringsHandler()
         handler.bind_file(os.path.join(os.path.dirname(__file__), file_))
         handler.set_language(self.resource.source_language)
         if file_ in ['test_utf_16.strings', 'test_utf_8.strings',
                 'test_utf_8_with_BOM.strings']:
             handler.parse_file(is_source=True)
             self.stringset = handler.stringset
             entities = 0
             translations = 0
             for s in self.stringset:
                 entities += 1
                 if s.translation.strip() != '':
                     translations += 1
             if file_ == 'test_utf_8_with_BOM.strings':
                 count = 1
             else:
                 count = 4
             self.assertEqual(entities, count)
             self.assertEqual(translations, count)
         else:
             self.assertRaises(StringsParseError, handler.parse_file, is_source=True)
示例#2
0
    def _test_save2db(self):
        """Test saving Apple Strings files"""
        source_file = os.path.join(os.path.dirname(__file__),
                                   'test_utf_16.strings')
        trans_file = os.path.join(os.path.dirname(__file__),
                                  'test_translation.strings')
        handler = self._save_source(AppleStringsHandler(), self.resource,
                                    source_file, 4, 4)
        handler = self._save_translation(handler, self.resource,
                                         self.language_ar, trans_file, 2)

        self._mark_translation_as_reviewed(self.resource, ['key2'],
                                           self.language_ar, 1)

        return handler
示例#3
0
 def test_strings_parser(self):
     """STRINGS parsing tests."""
     # Parsing STRINGS content
     files = [
         'test_utf_16.strings',
         'test_utf_8.strings',
         'test_utf_8_with_BOM.strings',
     ]
     for i in range(1, 9):
         files.append('bad%d.strings' % i)
     for file_ in files:
         handler = AppleStringsHandler()
         handler.bind_file(os.path.join(os.path.dirname(__file__), file_))
         handler.set_language(self.resource.source_language)
         if file_ in [
                 'test_utf_16.strings', 'test_utf_8.strings',
                 'test_utf_8_with_BOM.strings'
         ]:
             handler.parse_file(is_source=True)
             self.stringset = handler.stringset
             entities = 0
             translations = 0
             for s in self.stringset:
                 entities += 1
                 if s.translation.strip() != '':
                     translations += 1
             if file_ == 'test_utf_8_with_BOM.strings':
                 count = 1
             else:
                 count = 4
             self.assertEqual(entities, count)
             self.assertEqual(translations, count)
         else:
             self.assertRaises(StringsParseError,
                               handler.parse_file,
                               is_source=True)
示例#4
0
    def test_strings_save2db(self):
        """Test creating source strings from a STRINGS file works"""
        source_file = 'test_utf_16.strings'
        trans_file = 'test_translation.strings'
        handler = AppleStringsHandler()
        handler.bind_file(os.path.join(os.path.dirname(__file__), source_file))

        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)

        r = self.resource
        l = r.source_language

        handler.bind_resource(r)

        handler.save2db(is_source=True)

        # Check that all 4 entities are created in the db
        self.assertEqual( SourceEntity.objects.filter(resource=r).count(), 4)

        # Check that all source translations are there
        self.assertEqual(
            len(Translation.objects.filter(source_entity__resource=r, language=l)), 4
        )

        # Import and save the finish translation
        handler.bind_file(os.path.join(os.path.dirname(__file__), trans_file))
        l = self.language_ar
        handler.set_language(l)
        handler.parse_file()

        entities = 0
        translations = 0
        for s in handler.stringset.strings:
            entities += 1
            if s.translation.strip() != '':
                translations += 1

        self.assertEqual(entities, 2)
        self.assertEqual(translations, 2)

        handler.save2db()
        # Check if all Source strings are untouched
        self.assertEqual(SourceEntity.objects.filter(resource=r).count(), 4)
        # Check that all translations are there
        self.assertEqual(len(Translation.objects.filter(source_entity__resource=r,
            language=l)), 2)

        r.delete()
示例#5
0
 def test_accept(self):
     """Test whether parser accepts STRINGS file format"""
     parser = AppleStringsHandler()
     self.assertTrue(parser.accepts(mime='text/x-strings'))