XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/231774

Change subject: [FIX] Don't expect NoPage on unconnected pages
......................................................................

[FIX] Don't expect NoPage on unconnected pages

When an unconnected page gets connected it may still be reported as
unconnected. As this most likely only happens on pages in the main namespaces
we ignore it there.

Change-Id: I0831be6e3a541204610a03bfd07b442930555fd8
---
M tests/pagegenerators_tests.py
M tests/site_tests.py
2 files changed, 22 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/74/231774/1

diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index ce51bfc..4b7b260 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -914,10 +914,19 @@
         """Test that the ItemPage returned raises NoPage."""
         if not self.site.data_repository():
             raise unittest.SkipTest('Site is not using a Wikibase repository')
+        # Pages which have been connected recently may still be reported as
+        # unconnected. So expect NoPage only for non main namespace pages where
+        # it shouldn't happen as often.
         cnt = 0
         for page in pagegenerators.UnconnectedPageGenerator(self.site, 
total=5):
-            self.assertRaises(pywikibot.NoPage, pywikibot.ItemPage.fromPage,
-                              page)
+            try:
+                pywikibot.ItemPage.fromPage(page)
+            except pywikibot.NoPage:
+                pass
+            else:
+                if page.namespace() != 0:
+                    self.fail('Page "{0}" is connected to a Wikibase '
+                              'repository')
             cnt += 1
         self.assertLessEqual(cnt, 5)
 
diff --git a/tests/site_tests.py b/tests/site_tests.py
index 5946d3d..832812c 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -819,9 +819,18 @@
         if not self.site.data_repository():
             raise unittest.SkipTest('Site is not using a Wikibase repository')
         cnt = 0
+        # Pages which have been connected recently may still be reported as
+        # unconnected. So expect NoPage only for non main namespace pages where
+        # it shouldn't happen as often.
         for page in self.site.unconnected_pages(total=5):
-            self.assertRaises(pywikibot.NoPage, pywikibot.ItemPage.fromPage,
-                              page)
+            try:
+                pywikibot.ItemPage.fromPage(page)
+            except pywikibot.NoPage:
+                pass
+            else:
+                if page.namespace() != 0:
+                    self.fail('Page "{0}" is connected to a Wikibase '
+                              'repository')
             cnt += 1
         self.assertLessEqual(cnt, 5)
 

-- 
To view, visit https://gerrit.wikimedia.org/r/231774
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0831be6e3a541204610a03bfd07b442930555fd8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to