|
14 | 14 |
|
15 | 15 | import pywikibot |
16 | 16 |
|
17 | | -from pywikitools.resourcesbot.bot import ResourcesBot, load_module |
| 17 | +from pywikitools.resourcesbot.bot import ( |
| 18 | + AVAILABLE_MODULES, |
| 19 | + ResourcesBot, |
| 20 | + build_module_choices, |
| 21 | + load_module, |
| 22 | + resolve_run_modules, |
| 23 | +) |
18 | 24 | from pywikitools.resourcesbot.data_structures import TranslationProgress, WorksheetInfo |
19 | 25 | from pywikitools.test.test_data_structures import TEST_PROGRESS, TEST_TIME, TEST_URL |
20 | 26 |
|
@@ -341,5 +347,53 @@ def factory(*args, **kwargs): |
341 | 347 | # TODO: test_run_with_limit_lang |
342 | 348 |
|
343 | 349 |
|
| 350 | +class TestResolveRunModules(unittest.TestCase): |
| 351 | + @classmethod |
| 352 | + def setUpClass(cls): |
| 353 | + cls.modules = build_module_choices() |
| 354 | + |
| 355 | + def _config_with_modules(self, modules_value: str) -> ConfigParser: |
| 356 | + config = ConfigParser() |
| 357 | + config.read_dict( |
| 358 | + { |
| 359 | + "resourcesbot": { |
| 360 | + "site": "test", |
| 361 | + "username": "TestBotName", |
| 362 | + "modules": modules_value, |
| 363 | + } |
| 364 | + } |
| 365 | + ) |
| 366 | + return config |
| 367 | + |
| 368 | + def test_default_is_all_modules(self): |
| 369 | + config = ConfigParser() |
| 370 | + config.read_dict({"resourcesbot": {"site": "test", "username": "TestBotName"}}) |
| 371 | + self.assertEqual(resolve_run_modules(self.modules, config), AVAILABLE_MODULES) |
| 372 | + |
| 373 | + def test_config_all(self): |
| 374 | + config = self._config_with_modules("all") |
| 375 | + self.assertEqual(resolve_run_modules(self.modules, config), AVAILABLE_MODULES) |
| 376 | + |
| 377 | + def test_config_specific_modules(self): |
| 378 | + config = self._config_with_modules("list report") |
| 379 | + self.assertEqual( |
| 380 | + resolve_run_modules(self.modules, config), |
| 381 | + ["write_lists", "write_report"], |
| 382 | + ) |
| 383 | + |
| 384 | + def test_cli_overrides_config(self): |
| 385 | + config = self._config_with_modules("list") |
| 386 | + self.assertEqual( |
| 387 | + resolve_run_modules(self.modules, config, cli_modules=["report"]), |
| 388 | + ["write_report"], |
| 389 | + ) |
| 390 | + |
| 391 | + def test_config_unknown_module_raises(self): |
| 392 | + config = self._config_with_modules("list unknown") |
| 393 | + with self.assertRaises(ValueError) as context: |
| 394 | + resolve_run_modules(self.modules, config) |
| 395 | + self.assertIn("unknown", str(context.exception)) |
| 396 | + |
| 397 | + |
344 | 398 | if __name__ == "__main__": |
345 | 399 | unittest.main() |
0 commit comments