http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11263
Revision: 11263 Author: legoktm Date: 2013-03-25 12:09:14 +0000 (Mon, 25 Mar 2013) Log Message: ----------- Update unit tests, remove deprecated test
Modified Paths: -------------- branches/rewrite/tests/page_tests.py branches/rewrite/tests/site_tests.py
Modified: branches/rewrite/tests/page_tests.py =================================================================== --- branches/rewrite/tests/page_tests.py 2013-03-25 12:07:37 UTC (rev 11262) +++ branches/rewrite/tests/page_tests.py 2013-03-25 12:09:14 UTC (rev 11263) @@ -115,7 +115,6 @@ def testSite(self): """Test site() method""" self.assertEqual(mainpage.site, site) - self.assertEqual(mainpage.encoding(), site.encoding())
def testNamespace(self): """Test namespace() method""" @@ -227,13 +226,14 @@
def testReferences(self): count = 0 - for p in mainpage.getReferences(): + #Ignore redirects for time considerations + for p in mainpage.getReferences(follow_redirects=False): count += 1 self.assertTrue(isinstance(p, pywikibot.Page)) if count >= 10: break count = 0 - for p in mainpage.backlinks(): + for p in mainpage.backlinks(followRedirects=False): count += 1 self.assertTrue(isinstance(p, pywikibot.Page)) if count >= 10:
Modified: branches/rewrite/tests/site_tests.py =================================================================== --- branches/rewrite/tests/site_tests.py 2013-03-25 12:07:37 UTC (rev 11262) +++ branches/rewrite/tests/site_tests.py 2013-03-25 12:09:14 UTC (rev 11263) @@ -530,7 +530,7 @@ for using in mysite.imageusage(imagepage, filterredir=True, total=5): self.assertType(using, pywikibot.Page) self.assertTrue(using.isRedirectPage()) - for using in mysite.imageusage(imagepage, filterredir=True, total=5): + for using in mysite.imageusage(imagepage, filterredir=False, total=5): self.assertType(using, pywikibot.Page) self.assertFalse(using.isRedirectPage())
@@ -539,35 +539,33 @@
le = list(mysite.logevents(total=10)) self.assertTrue(len(le) <= 10) - self.assertTrue(all(isinstance(entry, dict) and "type" in entry + self.assertTrue(all(isinstance(entry, pywikibot.data.logentries.LogEntry) for entry in le)) for typ in ("block", "protect", "rights", "delete", "upload", "move", "import", "patrol", "merge"): for entry in mysite.logevents(logtype=typ, total=3): - self.assertEqual(entry["type"], typ) + self.assertEqual(entry.type(), typ) for entry in mysite.logevents(page=mainpage, total=3): - self.assertTrue("title" in entry - and entry["title"] == mainpage.title()) + self.assertTrue(entry.title().title() == mainpage.title()) for entry in mysite.logevents(user=mysite.user(), total=3): - self.assertTrue("user" in entry - and entry["user"] == mysite.user()) + self.assertTrue(entry.user() == mysite.user()) for entry in mysite.logevents(start="2008-09-01T00:00:01Z", total=5): - self.assertType(entry, dict) - self.assertTrue(entry['timestamp'] <= "2008-09-01T00:00:01Z") + self.assertType(entry, pywikibot.data.logentries.LogEntry) + self.assertTrue(str(entry.timestamp()) <= "2008-09-01T00:00:01Z") for entry in mysite.logevents(end="2008-09-02T23:59:59Z", total=5): - self.assertType(entry, dict) - self.assertTrue(entry['timestamp'] >= "2008-09-02T23:59:59Z") + self.assertType(entry, pywikibot.data.logentries.LogEntry) + self.assertTrue(str(entry.timestamp()) >= "2008-09-02T23:59:59Z") for entry in mysite.logevents(start="2008-02-02T00:00:01Z", end="2008-02-02T23:59:59Z", reverse=True, total=5): - self.assertType(entry, dict) - self.assertTrue("2008-02-02T00:00:01Z" <= entry['timestamp'] + self.assertType(entry, pywikibot.data.logentries.LogEntry) + self.assertTrue("2008-02-02T00:00:01Z" <= str(entry.timestamp()) <= "2008-02-02T23:59:59Z") for entry in mysite.logevents(start="2008-02-03T23:59:59Z", end="2008-02-03T00:00:01Z", total=5): - self.assertType(entry, dict) - self.assertTrue("2008-02-03T00:00:01Z" <= entry['timestamp'] + self.assertType(entry, pywikibot.data.logentries.LogEntry) + self.assertTrue("2008-02-03T00:00:01Z" <= str(entry.timestamp()) <= "2008-02-03T23:59:59Z") # starttime earlier than endtime self.assertRaises(pywikibot.Error, mysite.logevents, @@ -629,12 +627,13 @@ prefix = title[ : title.index(":")] self.assertTrue(mysite.ns_index(prefix) in [6,7]) self.assertTrue(change["ns"] in [6,7]) - for change in mysite.recentchanges(pagelist=[mainpage, imagepage], - total=5): - self.assertType(change, dict) - self.assertTrue("title" in change) - self.assertTrue(change["title"] in (mainpage.title(), - imagepage.title())) + if mysite.versionnumber() <= 14: + for change in mysite.recentchanges(pagelist=[mainpage, imagepage], + total=5): + self.assertType(change, dict) + self.assertTrue("title" in change) + self.assertTrue(change["title"] in (mainpage.title(), + imagepage.title())) for typ in ("edit", "new", "log"): for change in mysite.recentchanges(changetype=typ, total=5): self.assertType(change, dict)
pywikipedia-svn@lists.wikimedia.org