Repository: MarketSquare/robotframework-robocop
Pull request #1349 (2025-03-24 16:12:30)

Fix language not loaded in formatter


Patch:
diff --git a/src/robocop/config.py b/src/robocop/config.py
index 783ccb9..53a8838 100644
--- a/src/robocop/config.py
+++ b/src/robocop/config.py
@@ -385,7 +385,6 @@ class FormatterConfig:
 
     def load_formatters(self):
         self._formatters = {}
-        self.load_languages()
         for formatter in self.selected_formatters():
             for container in formatters.import_formatter(formatter, self.combined_configure, self.skip_config):
                 if container.name in self.select or formatter in self.select:
@@ -612,6 +611,7 @@ class Config:
             self.formatter.whitespace_config.overwrite(overwrite_config.formatter.whitespace_config)
             self.formatter.skip_config.overwrite(overwrite_config.formatter.skip_config)
             self.formatter.language = self.language  # TODO
+            self.formatter.load_languages()
         self.file_filters.overwrite(overwrite_config.file_filters)
 
     def __str__(self):


Test patch:
diff --git a/tests/formatter/formatters/Translate/test_formatter.py b/tests/formatter/formatters/Translate/test_formatter.py
index 358a4bc..0cb8f25 100644
--- a/tests/formatter/formatters/Translate/test_formatter.py
+++ b/tests/formatter/formatters/Translate/test_formatter.py
@@ -1,33 +1,33 @@
+import pytest
+
 from tests.formatter import FormatterAcceptanceTest
 
 
 class TestTranslate(FormatterAcceptanceTest):
     FORMATTER_NAME = "Translate"
 
-    # FIXME After integrating, test is unstable - something wrong with language settings
-    # @pytest.mark.parametrize("source_lang", [["pl"], ["pl", "de"]])  # ["en"],
-    # @pytest.mark.parametrize("dest_lang", ["de", "en"])  # , "pl"
-    # def test_translation(self, source_lang, dest_lang):
-    #     configure = []
-    #     language = None
-    #     if dest_lang != "en":
-    #         configure.append(f"{self.FORMATTER_NAME}.language={dest_lang}")
-    #     if source_lang != ["en"]:
-    #         language = source_lang
-    #     source_file = "_and_".join(source_lang) + ".robot"
-    #     not_modified = source_lang == [dest_lang]
-    #     self.compare(
-    #         configure=configure,
-    #         language=language,
-    #         source=source_file,
-    #         expected=f"{dest_lang}.robot",
-    #         not_modified=not_modified,
-    #     )
+    @pytest.mark.parametrize("source_lang", [["en"], ["pl"], ["pl", "de"]])
+    @pytest.mark.parametrize("dest_lang", ["de", "en", "pl"])
+    def test_translation(self, source_lang, dest_lang):
+        configure = []
+        language = None
+        if dest_lang != "en":
+            configure.append(f"{self.FORMATTER_NAME}.language={dest_lang}")
+        if source_lang != ["en"]:
+            language = source_lang
+        source_file = "_and_".join(source_lang) + ".robot"
+        not_modified = source_lang == [dest_lang]
+        self.compare(
+            configure=configure,
+            language=language,
+            source=source_file,
+            expected=f"{dest_lang}.robot",
+            not_modified=not_modified,
+        )
 
-    def test_recognize_language_header(self):  # FIXME language header not recognized
+    def test_recognize_language_header(self):
         self.compare(
             configure=[f"{self.FORMATTER_NAME}.language=en"],
-            language=["pl"],
             source="pl_language_header.robot",
             expected="en_with_pl_header.robot",
         )