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
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)