Exemple #1
0
    def test_translate_write_proj_file(self, mkdir_func):
        test_file = teststringio.TestStringIO(os.getcwd() +
                                              "/Resources/test/Sample.resx")
        csproj_file = teststringio.TestStringIO(
            os.getcwd() + "/Resources/test/Proj.csproj", RESXTests.test_csproj)
        files = {
            "Resources/test/Sample.it-IT.resx": test_file,
            "Resources/test/Proj.csproj": csproj_file
        }

        resx_parser = parser.RESX()
        vcs_class = mock.Mock()
        resx_parser._read_file = mock.Mock(return_value=RESXTests.sample_resx)

        resx_parser._open_file_for_writing = mock.Mock()

        def side_effect(arg):
            return files[arg]

        resx_parser._open_file_for_writing.side_effect = side_effect

        resx_parser._open_file_for_appending = mock.Mock(
            return_value=csproj_file)

        output_filename = resx_parser.translate(
            "Sample.resx", "Resources/test", {
                u"Translation for some string":
                u"Traduzione di Bablefish per questa stringa",
                u"Translation for the other string":
                u"Translation for the other string",
                u"Will not show up": u"Will not show up",
                u"A ToolTip String": u"Translated ToolTip String",
            }, "Italian", "it-IT", True, vcs_class,
            "Resources/test/Proj.csproj")
        self.assertEquals(csproj_file.getvalue(), RESXTests.expected_csproj)
Exemple #2
0
    def test_translate(self, mkdir_func):
        resx_parser = parser.RESX()
        vcs_class = mock.Mock()
        resx_parser._read_file = mock.Mock(return_value=RESXTests.sample_resx)
        test_file = teststringio.TestStringIO('test.it.resx')

        resx_parser._open_file_for_writing = mock.Mock(return_value=test_file)

        self.assertEquals(
            resx_parser.translate(
                "test.it-IT.resx", "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",
                    u"A ToolTip String": u"Translated ToolTip String",
                }, "Italian", "it-IT", True, vcs_class, None),
            "test.it-IT.resx")

        self.assertFalse(mkdir_func.called)
        self.assertFalse(resx_parser._open_file_for_writing.called)
        self.assertFalse(vcs_class.add_file.called)

        output_filename = resx_parser.translate(
            "Sample.resx", "Resources", {
                u"Translation for some string":
                u"Traduzione di Bablefish per questa stringa",
                u"Translation for the other string":
                u"Translation for the other string",
                u"Will not show up": u"Will not show up",
                u"A ToolTip String": u"Translated ToolTip String",
            }, "Italian", "it-IT", True, vcs_class, None)

        mkdir_func.assert_called_with("Resources")
        resx_parser._open_file_for_writing.assert_called_with(
            os.path.join("Resources", "Sample.it-IT.resx"))

        self.assertEquals(output_filename,
                          os.path.join("Resources", "Sample.it-IT.resx"))

        self.assertEquals(test_file.getvalue(),
                          RESXTests.sample_translated_resx)

        vcs_class.add_file.assert_called_with(
            os.path.join("Resources", "Sample.it-IT.resx"))
Exemple #3
0
    def test_extract_mapping_from_filename(self):
        extractor = parser.RESX()
        extractor._read_file = mock.Mock(return_value=RESXTests.sample_resx)

        string_mapping = extractor.extract_mapping_from_filename("some_file")

        self.assertEquals(
            string_mapping.string_mapping_dict, {
                u"SomeString.Text-some_file": u"Translation for some string",
                u"SomeOtherString-some_file":
                u"Translation for the other string",
                u"YetAnotherString.Text-some_file": u"Yet another translation",
                u"ToolTipString.ToolTipText-some_file": u"A ToolTip String",
            })

        for key, value in string_mapping.string_mapping_dict.iteritems():
            self.assertEquals(type(key), types.UnicodeType)
            self.assertEquals(type(value), types.UnicodeType)
Exemple #4
0
    def test_extract_strings_from_filename(self):
        extractor = parser.RESX()
        extractor._read_file = mock.Mock(return_value=RESXTests.sample_resx)

        extracted_strings = extractor.extract_strings_from_filename(
            "some_file")

        self.assertEquals(
            extracted_strings,
            set([
                u"SomeString.Text-some_file",
                u"SomeOtherString-some_file",
                u"YetAnotherString.Text-some_file",
                u"ToolTipString.ToolTipText-some_file",
            ]))

        for string in extracted_strings:
            self.assertEquals(type(string), types.UnicodeType)
Exemple #5
0
    def test_filter_filenames(self):
        extractor = parser.RESX()

        self.assertEquals(
            extractor._filter_filenames(
                ["suitcase.resx", "suitcase.jp-JP.resx"], ), ["suitcase.resx"])

        extractor._filter_filenames = mock.Mock(return_value=[])

        extractor.extract_strings_from_files(["test.resx", "test.jp-JP.resx"])

        extractor._filter_filenames.assert_called_with(
            ["test.resx", "test.jp-JP.resx"])

        extractor.extract_string_mapping_from_files(
            ["test.resx", "test.it-IT.resx"])

        extractor._filter_filenames.assert_called_with(
            ["test.resx", "test.it-IT.resx"])
Exemple #6
0
    def test_open_file_for_writing(self, open_func):
        extractor = parser.RESX()
        extractor._open_file_for_writing("filename")

        open_func.assert_called_with("filename", "w")
Exemple #7
0
    def test_read_file(self):
        extractor = parser.RESX()
        dir = os.path.dirname(__file__)
        file = os.path.join(dir, "test.resx")

        self.assertEquals(extractor._read_file(file), RESXTests.sample_resx)