def test_open_file(self): extractor = parser.RC() dir = os.path.dirname(__file__) file = os.path.join(dir, "test.rc") self.assertEquals( extractor._open_file(file)[0].read(), RCTests.sample_rc)
def test_filter_filenames(self): extractor = parser.RC() self.assertEquals( extractor._filter_filenames( [ "suitcase.rc", "suitcase.jp-JP.rc" ], ), [ "suitcase.rc" ] ) extractor._filter_filenames = mock.Mock(return_value = []) extractor.extract_strings_from_files([ "test.rc", "test.jp-JP.rc" ]) extractor._filter_filenames.assert_called_with( [ "test.rc", "test.jp-JP.rc" ] ) extractor.extract_string_mapping_from_files( [ "test.rc", "test.it-IT.rc" ] ) extractor._filter_filenames.assert_called_with( [ "test.rc", "test.it-IT.rc" ] )
def test_translate(self, mkdir_func): rc_parser = parser.RC() vcs_class = mock.Mock() test_output_file = teststringio.TestStringIO() test_input_file = None def _get_input_file(self): test_input_file = teststringio.TestStringIO(RCTests.sample_rc) return test_input_file, "utf-8" rc_parser._open_file_for_writing = mock.Mock( return_value = test_output_file ) rc_parser._open_file = mock.Mock(side_effect = _get_input_file) output_filename = rc_parser.translate( "Sample.rc", "Resources", { u"Translation for \"some\" string" : u"Traduzione di Bablefish per \"questa\" stringa", u"Translation\\nfor the other string" : u"Translation\\nfor the other string", u"Will not show up" : u"Will not show up", }, "Italian", "it-IT", True, vcs_class ) mkdir_func.assert_called_with( "Resources" ) rc_parser._open_file_for_writing.assert_called_with( os.path.join("Resources", "Sample.it-IT.rc") ) self.assertEquals( output_filename, os.path.join("Resources", "Sample.it-IT.rc") ) self.assertEquals( test_output_file.getvalue(), RCTests.sample_translated_rc ) vcs_class.add_file.assert_called_with( os.path.join("Resources", "Sample.it-IT.rc") )
def test_extract_mapping_from_filename(self): extractor = parser.RC() extractor._open_file = mock.Mock(return_value=( teststringio.TestStringIO(RCTests.sample_rc), "utf_8", )) string_mapping = extractor.extract_mapping_from_filename("some_file") self.assertEquals( string_mapping.string_mapping_dict, { u"SomeString": u"Translation for \"some\" string", u"SomeOtherString": u"Translation\\nfor the other string", u"YetAnotherString": u"YetAnotherString", u"Activating fonts": u"Activating fonts", }) for key, value in string_mapping.string_mapping_dict.iteritems(): self.assertEquals(type(key), types.UnicodeType) self.assertEquals(type(value), types.UnicodeType)
def test_extract_strings_from_filename(self): extractor = parser.RC() extractor._open_file = mock.Mock(return_value=( teststringio.TestStringIO(RCTests.sample_rc), "iso-8859-1", )) extracted_strings = extractor.extract_strings_from_filename( "some_file") self.assertEquals( extracted_strings, set([ u"SomeString", u"SomeOtherString", u"YetAnotherString", u"Activating fonts", ])) for string in extracted_strings: self.assertEquals(type(string), types.UnicodeType)
def test_open_file_for_writing(self, open_func): rc_parser = parser.RC() rc_parser._open_file_for_writing("filename") open_func.assert_called_with("filename", "w", "utf_16")