jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/811911 )
Change subject: [tests] Add harvest_templates_tests ......................................................................
[tests] Add harvest_templates_tests
Change-Id: I74905df161e4a6ea18c8a0f023df680443de64ff --- A docs/tests_ref/harvest_templates_tests.rst M docs/tests_ref/index.rst M tests/__init__.py A tests/harvest_templates_tests.py 4 files changed, 63 insertions(+), 0 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/docs/tests_ref/harvest_templates_tests.rst b/docs/tests_ref/harvest_templates_tests.rst new file mode 100644 index 0000000..873c7a3 --- /dev/null +++ b/docs/tests_ref/harvest_templates_tests.rst @@ -0,0 +1,7 @@ +tests.harvest_templates_tests module +====================================== + +.. automodule:: tests.harvest_templates_tests + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/tests_ref/index.rst b/docs/tests_ref/index.rst index 695a506..457b2c5 100644 --- a/docs/tests_ref/index.rst +++ b/docs/tests_ref/index.rst @@ -102,6 +102,7 @@ fixing_redirects<./fixing_redirects_tests> generate_family_file<./generate_family_file_tests> generate_user_files<./generate_user_files_tests> + harvest_templates<./harvest_templates_tests> interwikidata<./interwikidata_tests> noreferences<./noreferences_tests> patrolbot<./patrolbot_tests> diff --git a/tests/__init__.py b/tests/__init__.py index 28835bf..854a029 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -148,6 +148,7 @@ 'fixing_redirects', 'generate_family_file', 'generate_user_files', + 'harvest_templates', 'interwikidata', 'l10n', 'patrolbot', diff --git a/tests/harvest_templates_tests.py b/tests/harvest_templates_tests.py new file mode 100644 index 0000000..b0804ee --- /dev/null +++ b/tests/harvest_templates_tests.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +"""Tests for scripts/harvest_template.py.""" +# +# (C) Pywikibot team, 2022 +# +# Distributed under the terms of the MIT license. +# +import unittest +from contextlib import suppress + +from pywikibot import ItemPage +from scripts.harvest_template import HarvestRobot + +from tests.aspects import ScriptMainTestCase + + +class DummyBot: + + """Dummy HarvestRobot.""" + + class current_page: # noqa: D106, N801 + pass + + def __init__(self, site): # noqa: D107 + """Add a site object to current_page attribute.""" + self.current_page.site = site + + +class TestHarvestRobot(ScriptMainTestCase): + + """Test HarvestRobot.""" + + family = 'wikipedia' + code = 'cs' + + def test_template_link_target(self): + """Test template_link_target static method.""" + tests = [ + ('Pes', 'Q144'), + ('Imaginární číslo', 'Q9165172'), + ('Sequana', 'Q472766'), + ] + for link, item in tests: + with self.subTest(link=link, item=item): + dummy_item = ItemPage(self.site.data_repository(), 'Q1') + target = HarvestRobot.template_link_target( + DummyBot(self.site), dummy_item, link) + self.assertIsInstance(target, ItemPage) + self.assertEqual(target.title(), item) + + +if __name__ == '__main__': # pragma: no cover + with suppress(SystemExit): + unittest.main()
pywikibot-commits@lists.wikimedia.org