jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/817713 )
Change subject: [IMPR] do not test internal implementation in tests ......................................................................
[IMPR] do not test internal implementation in tests
Do not test internal implementation of methods, but only external behaviour: - tests.site_tests.TestSiteGenerators.test_unconnected - tests.pagegenerators_tests.TestUnconnectedPageGenerator
Change-Id: I16f830eea9c3adc84adeade8ff06fb57efd4d7c8 --- M tests/pagegenerators_tests.py M tests/site_tests.py 2 files changed, 25 insertions(+), 28 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 518c364..58df3a2 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -15,7 +15,11 @@
import pywikibot from pywikibot import date, pagegenerators -from pywikibot.exceptions import ServerError, UnknownExtensionError +from pywikibot.exceptions import ( + NoPageError, + ServerError, + UnknownExtensionError, +) from pywikibot.pagegenerators import ( CategorizedPageGenerator, PagesFromTitlesGenerator, @@ -1680,18 +1684,16 @@ """Test UnconnectedPageGenerator.""" if not self.site.data_repository(): self.skipTest('Site is not using a Wikibase repository') - upgen = pagegenerators.UnconnectedPageGenerator(self.site, 3) - self.assertDictEqual( - upgen.request._params, { - 'gqppage': ['UnconnectedPages'], - 'prop': ['info', 'imageinfo', 'categoryinfo'], - 'inprop': ['protection'], - 'iilimit': ['max'], - 'iiprop': ['timestamp', 'user', 'comment', 'url', 'size', - 'sha1', 'metadata'], - 'generator': ['querypage'], 'action': ['query'], - 'indexpageids': [True], 'continue': [True]}) - self.assertLessEqual(len(tuple(upgen)), 3) + pages = list(pagegenerators.UnconnectedPageGenerator(self.site, 3)) + self.assertLessEqual(len(pages), 3) + + site = self.site.data_repository() + pattern = (r'Page ' + r'[[({site.sitename}:|{site.code}:)-1]]' + r" doesn't exist.".format(site=site)) + for page in pages: + with self.assertRaisesRegex(NoPageError, pattern): + page.data_item()
def test_unconnected_without_repo(self): """Test that it raises a ValueError on sites without repository.""" diff --git a/tests/site_tests.py b/tests/site_tests.py index 4d70509..c3f488e 100755 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -896,21 +896,16 @@ """Test site.unconnected_pages method.""" if not self.site.data_repository(): self.skipTest('Site is not using a Wikibase repository') - upgen = self.site.unconnected_pages(total=3) - self.assertEqual( - upgen.request._params, - { - 'gqppage': ['UnconnectedPages'], - 'prop': ['info', 'imageinfo', 'categoryinfo'], - 'inprop': ['protection'], - 'iilimit': ['max'], - 'iiprop': ['timestamp', 'user', 'comment', 'url', 'size', - 'sha1', 'metadata'], - 'generator': ['querypage'], 'action': ['query'], - 'indexpageids': [True], 'continue': [True] - } - ) - self.assertLessEqual(len(tuple(upgen)), 3) + pages = list(self.site.unconnected_pages(total=3)) + self.assertLessEqual(len(pages), 3) + + site = self.site.data_repository() + pattern = (r'Page ' + r'[[({site.sitename}:|{site.code}:)-1]]' + r" doesn't exist.".format(site=site)) + for page in pages: + with self.assertRaisesRegex(NoPageError, pattern): + page.data_item()
def test_assert_valid_iter_params(self): """Test site.assert_valid_iter_params method."""
pywikibot-commits@lists.wikimedia.org