jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1334091?usp=email )

Change subject: make_i18n_dict: Fix script attribute lookup
......................................................................

make_i18n_dict: Fix script attribute lookup

import_module() returns the requested script module, unlike __import__(),
which returned the top-level scripts package. Skip the already imported
script name when traversing class and attribute components.

Change-Id: Idfc38d42da468426939d0814e8772f12646cf30f
---
M scripts/maintenance/make_i18n_dict.py
M tests/make_i18n_dict_tests.py
2 files changed, 16 insertions(+), 1 deletion(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/scripts/maintenance/make_i18n_dict.py 
b/scripts/maintenance/make_i18n_dict.py
index 65877ee..5e24e9b 100755
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -52,7 +52,7 @@
         modules = script.split('.')
         self.scriptname = modules[0]
         self.script = import_module('scripts.' + self.scriptname)
-        for m in modules:
+        for m in modules[1:]:
             self.script = getattr(self.script, m)
         self.messages = {}
         # setup the message dict
diff --git a/tests/make_i18n_dict_tests.py b/tests/make_i18n_dict_tests.py
index 204ef6f..47041d7 100755
--- a/tests/make_i18n_dict_tests.py
+++ b/tests/make_i18n_dict_tests.py
@@ -11,6 +11,7 @@
 import unittest
 from pathlib import Path
 from tempfile import TemporaryDirectory
+from types import SimpleNamespace
 from unittest.mock import patch

 from scripts.maintenance import make_i18n_dict
@@ -23,6 +24,20 @@

     net = False

+    def test_init_with_class(self) -> None:
+        """Test initializing the bot with a class from a script."""
+        script_class = SimpleNamespace(message={})
+        script_module = SimpleNamespace(ScriptClass=script_class)
+
+        with patch.object(make_i18n_dict, 'import_module',
+                          return_value=script_module) as import_module:
+            bot = make_i18n_dict.i18nBot(
+                'sample.ScriptClass', 'message')
+
+        import_module.assert_called_once_with('scripts.sample')
+        self.assertIs(bot.script, script_class)
+        self.assertEqual(bot.messages, {'message': 'message'})
+
     def test_to_json_creates_and_updates_file(self) -> None:
         """Test creating directories and updating an existing JSON file."""
         bot = object.__new__(make_i18n_dict.i18nBot)

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1334091?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idfc38d42da468426939d0814e8772f12646cf30f
Gerrit-Change-Number: 1334091
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to