def test_translate(self, mkdir_func): file = cStringIO.StringIO() translator = parser.StringsDict() test_file = teststringio.TestStringIO() vcs_class = mock.Mock() translator._open_file_for_writing = mock.Mock(return_value=test_file) translator._read_file = mock.Mock( return_value=StringsDictTests.sample_strings) self.assertEquals( translator.translate( "test.stringsdict", "Resources", { u'Activate %lu Fonts': u'Activate Plural', u'Activate %lu Font': u'Activate Singular', u'Deactivate %lu Fonts': u'Deactivate Plural', u'Deactivate %lu Font': u'Deactivate Singular' }, "French", "fr", True, vcs_class), os.path.join("Resources", "test.stringsdict")) self.assertEquals(test_file.getvalue(), StringsDictTests.translated_strings) mkdir_func.assert_called_with("Resources") translator._open_file_for_writing.assert_called_with( os.path.join("Resources", "test.stringsdict")) vcs_class.add_file.assert_called_with( os.path.join("Resources", "test.stringsdict")) file.close()
def test_read_file(self): extractor = parser.StringsDict() dir = os.path.dirname(__file__) file = os.path.join(dir, "test.stringsdict") self.assertEquals(extractor._read_file(file), StringsDictTests.sample_strings)
def test_translate(self, mkdir_func, listdir_func): listdir_func.return_value = [ "Localizable.strings", "Localizable.stringsdict" ] lproj_parser = parser.LPROJ() test_file = teststringio.TestStringIO() fake_strings_parser = parser.Strings() fake_stringsdict_parser = parser.StringsDict() vcs_class = mock.Mock() lproj_parser._open_file = mock.Mock(return_value=test_file) lproj_parser._create_strings_parser = mock.Mock( return_value=fake_strings_parser) lproj_parser._create_stringsdict_parser = mock.Mock( return_value=fake_stringsdict_parser) fake_stringsdict_parser.translate = mock.Mock() string_mapping = stringmapping.StringMapping() string_mapping.add_mapping('"SomeString"', u"Translation for some string") string_mapping.add_mapping('"NewString"', u"Untranslated string") string_mapping.add_mapping('InfoPlistVar', u"Untranslated string") fake_strings_parser.extract_mapping_from_filename = mock.Mock( return_value=string_mapping) translation_dict = { u"Translation for some string": u"Traduzione di Bablefish per questa stringa", u"Extra string": u"Not in file to localize", } output_filenames = lproj_parser.translate("en.lproj", "Resources", translation_dict, "Italian", "it", True, vcs_class) mkdir_func.assert_called_with(os.path.join("Resources", "it.lproj")) lproj_parser._open_file.assert_called_with( os.path.join("Resources", "it.lproj", "Localizable.strings")) self.assertEquals(output_filenames, os.path.join("Resources", "it.lproj")) self.assertEquals( test_file.getvalue(), """"NewString" = "Untranslated string"; "SomeString" = "Traduzione di Bablefish per questa stringa"; InfoPlistVar = "Untranslated string";\n""") fake_stringsdict_parser.translate.assert_called_with( os.path.join("en.lproj", "Localizable.stringsdict"), os.path.join("Resources", "it.lproj"), translation_dict, "Italian", "it", True, vcs_class) vcs_class.add_file.assert_called_with( os.path.join("Resources", "it.lproj", "Localizable.strings"))
def test_extract_strings_from_filename(self): extractor = parser.StringsDict() extractor._read_file = mock.Mock( return_value=StringsDictTests.sample_strings) strings = extractor.extract_strings_from_filename("some_file") self.assertEquals( strings, set([ u"Activate %lu Fonts", u"Activate %lu Font", u"Deactivate %lu Fonts", u"Deactivate %lu Font", ]))
def test_extract_mapping_from_filename(self): extractor = parser.StringsDict() extractor._read_file = mock.Mock( return_value=StringsDictTests.sample_strings) string_mapping = extractor.extract_mapping_from_filename("some_file") self.assertEquals( string_mapping.string_mapping_dict, { u"Activate %lu Fonts": "Activate %lu Fonts", u"Activate %lu Font": "Activate %lu Font", u"Deactivate %lu Fonts": "Deactivate %lu Fonts", u"Deactivate %lu Font": u"Deactivate %lu Font", }) for key, value in string_mapping.string_mapping_dict.iteritems(): self.assertEquals(type(key), types.UnicodeType) self.assertEquals(type(value), types.UnicodeType)