jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1325951?usp=email )

Change subject: site: Yield non-strict unconnected pages
......................................................................

site: Yield non-strict unconnected pages

Adding strict filtering made unconnected_pages a generator. Returning the
querypage generator therefore ended iteration without yielding its pages,
so the default non-strict path always appeared empty.

Delegate to querypage with yield from and cover the default path with an
offline regression test.

Change-Id: I2a56794df8c80639741dffafecb9fc46f09dcb6a
---
M pywikibot/site/_extensions.py
M tests/site_generators_tests.py
2 files changed, 17 insertions(+), 3 deletions(-)

Approvals:
  Xqt: Looks good to me, approved
  jenkins-bot: Verified




diff --git a/pywikibot/site/_extensions.py b/pywikibot/site/_extensions.py
index 821d77e..1a6cdaa 100644
--- a/pywikibot/site/_extensions.py
+++ b/pywikibot/site/_extensions.py
@@ -315,7 +315,8 @@
             return

         if not strict:
-            return self.querypage('UnconnectedPages', total)
+            yield from self.querypage('UnconnectedPages', total)
+            return

         count = 0
         for page in self.querypage('UnconnectedPages'):
diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py
index d0f5f8e..ed3611b 100755
--- a/tests/site_generators_tests.py
+++ b/tests/site_generators_tests.py
@@ -95,12 +95,25 @@
         self.assertEqual(references, [backlink_c, backlink_a, embedded_b])


-class TestWatchedPages(DefaultSiteTestCase):
+class TestDrySiteGenerators(DefaultSiteTestCase):

-    """Offline tests for Site.watched_pages."""
+    """Offline tests for site generators."""

     dry = True

+    def test_unconnected_non_strict(self) -> None:
+        """Test that the non-strict generator yields query pages."""
+        pages = [pywikibot.Page(self.site, title) for title in ('A', 'B')]
+        with (
+            patch.object(self.site, 'has_extension', return_value=True),
+            patch.object(self.site, 'querypage', return_value=iter(pages))
+            as querypage,
+        ):
+            result = list(self.site.unconnected_pages(total=2))
+
+        self.assertEqual(result, pages)
+        querypage.assert_called_once_with('UnconnectedPages', 2)
+
     def test_reuses_namespace(self) -> None:
         """Test that watchlist filtering retrieves the namespace once."""
         page = pywikibot.Page(self.site, 'Test page')

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1325951?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2a56794df8c80639741dffafecb9fc46f09dcb6a
Gerrit-Change-Number: 1325951
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to