Skip to content

Commit

Permalink
[tests] remove cached attribute from unconnectedPages tests
Browse files Browse the repository at this point in the history
Bug: T370596
Change-Id: Ib758190deae31e070a1a73b305a0e6a5e0508d44
  • Loading branch information
xqt committed Jul 21, 2024
1 parent c2a9500 commit d0bcad4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
2 changes: 2 additions & 0 deletions pywikibot/site/_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions tests/pagegenerators_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 21 additions & 15 deletions tests/site_generators_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."""

Expand Down

0 comments on commit d0bcad4

Please sign in to comment.