From d0bcad4fa8f732f688dbf7ec481299d44219a942 Mon Sep 17 00:00:00 2001 From: xqt Date: Sun, 21 Jul 2024 16:43:33 +0200 Subject: [PATCH] [tests] remove cached attribute from unconnectedPages tests Bug: T370596 Change-Id: Ib758190deae31e070a1a73b305a0e6a5e0508d44 --- pywikibot/site/_extensions.py | 2 ++ tests/pagegenerators_tests.py | 7 +++---- tests/site_generators_tests.py | 36 ++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py index aadf1b490b..46490fd565 100644 --- a/pywikibot/site/_extensions.py +++ b/pywikibot/site/_extensions.py @@ -262,6 +262,8 @@ class WikibaseClientMixin: def unconnected_pages(self, total=None): """Yield Page objects from Special:UnconnectedPages. + .. warning:: The retrieved pages may be connected in meantime. + :param total: number of pages to return """ return self.querypage('UnconnectedPages', total) diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index a705b4b844..7efd78f18f 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -1688,16 +1688,15 @@ class TestUnconnectedPageGenerator(DefaultSiteTestCase): """Test UnconnectedPageGenerator.""" - cached = True - def test_unconnected_with_repo(self): """Test UnconnectedPageGenerator.""" - if not self.site.data_repository(): + site = self.site.data_repository() + if not site: self.skipTest('Site is not using a Wikibase repository') + pages = list(pagegenerators.UnconnectedPageGenerator(self.site, 3)) self.assertLessEqual(len(pages), 3) - site = self.site.data_repository() pattern = (fr'Page \[\[({site.sitename}:|{site.code}:)-1\]\]' r" doesn't exist\.") for page in pages: diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py index 7596e6dbe5..86c98e0efb 100755 --- a/tests/site_generators_tests.py +++ b/tests/site_generators_tests.py @@ -650,21 +650,6 @@ def test_pages_with_property(self): self.fail( f'NotImplementedError not raised for {item}') - def test_unconnected(self): - """Test site.unconnected_pages method.""" - if not self.site.data_repository(): - self.skipTest('Site is not using a Wikibase repository') - pages = list(self.site.unconnected_pages(total=3)) - self.assertLessEqual(len(pages), 3) - - site = self.site.data_repository() - pattern = (r'Page ' - rf'\[\[({site.sitename}:|{site.code}:)-1\]\]' - r" doesn't exist\.") - 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.""" func = self.site.assert_valid_iter_params @@ -690,6 +675,27 @@ def test_assert_valid_iter_params(self): func('m', 2, 1, True, True) +class TestUnconnectedPages(DefaultSiteTestCase): + + """Test unconnected_pages method without cache enabled.""" + + def test_unconnected(self): + """Test site.unconnected_pages method.""" + site = self.site.data_repository() + if not site: + self.skipTest('Site is not using a Wikibase repository') + + pages = list(self.site.unconnected_pages(total=3)) + self.assertLessEqual(len(pages), 3) + + pattern = (fr'Page \[\[({site.sitename}:|{site.code}:)-1\]\]' + r" doesn't exist\.") + for page in pages: + with self.subTest(page=page), self.assertRaisesRegex( + NoPageError, pattern): + page.data_item() + + class TestSiteGeneratorsUsers(DefaultSiteTestCase): """Test cases for Site methods with users."""