jenkins-bot has submitted this change and it was merged.
Change subject: PEP8 fixes ......................................................................
PEP8 fixes
This commit adds some fixes to reduce the number of PEP8 warnings produced from each commit.
Change-Id: I3c2da53919fdaae34dc16dc012ae6589c4d7147a --- M tests/dry_site_tests.py M tests/i18n/test.py M tests/page_tests.py M tests/pwb/print_locals.py M tests/pwb_tests.py M tests/site_tests.py 6 files changed, 68 insertions(+), 56 deletions(-)
Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/dry_site_tests.py b/tests/dry_site_tests.py index affb8a9..27ca886 100644 --- a/tests/dry_site_tests.py +++ b/tests/dry_site_tests.py @@ -45,15 +45,17 @@ def test_must_be_user(self): x = SiteMock() wrapped_inner = pywikibot.site.must_be(group='user')(x.inner_fn) - self.assertEqual(wrapped_inner(x,1,2,3,a='a', b='b'), ((x,1,2,3), {'a': 'a', 'b': 'b'})) - self.assertEqual(x.last_fn_called, ((x,1,2,3), {'a': 'a', 'b': 'b'})) + self.assertEqual(wrapped_inner(x, 1, 2, 3, a='a', b='b'), ((x, 1, 2, 3), + {'a': 'a', 'b': 'b'})) + self.assertEqual(x.last_fn_called, ((x, 1, 2, 3), {'a': 'a', 'b': 'b'})) self.assertEqual(x.last_login, 'user')
def test_must_be_sysop(self): x = SiteMock() wrapped_inner = pywikibot.site.must_be(group='sysop')(x.inner_fn) - self.assertEqual(wrapped_inner(x,1,2,3,a='a', b='b'), ((x,1,2,3), {'a': 'a', 'b': 'b'})) - self.assertEqual(x.last_fn_called, ((x,1,2,3), {'a': 'a', 'b': 'b'})) + self.assertEqual(wrapped_inner(x, 1, 2, 3, a='a', b='b'), ((x, 1, 2, 3), + {'a': 'a', 'b': 'b'})) + self.assertEqual(x.last_fn_called, ((x, 1, 2, 3), {'a': 'a', 'b': 'b'})) self.assertEqual(x.last_login, 'sysop')
if __name__ == '__main__': diff --git a/tests/i18n/test.py b/tests/i18n/test.py index f93769a..e82bcd0 100644 --- a/tests/i18n/test.py +++ b/tests/i18n/test.py @@ -1,12 +1,18 @@ # -*- coding=utf-8 -*- msg = { - 'en': {'test-localized': u'test-localized EN', - 'test-semi-localized': u'test-semi-localized EN', - 'test-non-localized': u'test-non-localized EN' - }, - 'nl': {'test-localized': u'test-localized NL', - 'test-semi-localized': u'test-semi-localized NL', - }, - 'fy': {'test-localized': u'test-localized FY'}, - 'ja': {'test-no-english': u'test-no-english JA'} + 'en': { + 'test-localized': u'test-localized EN', + 'test-semi-localized': u'test-semi-localized EN', + 'test-non-localized': u'test-non-localized EN' + }, + 'nl': { + 'test-localized': u'test-localized NL', + 'test-semi-localized': u'test-semi-localized NL', + }, + 'fy': { + 'test-localized': u'test-localized FY' + }, + 'ja': { + 'test-no-english': u'test-no-english JA' } +} diff --git a/tests/page_tests.py b/tests/page_tests.py index 13289d8..f828c33 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -72,11 +72,11 @@ """Test that Link() normalizes namespace names""" for num in self.namespaces: for prefix in self.namespaces[num]: - l = pywikibot.page.Link(prefix+self.titles.keys()[0], + l = pywikibot.page.Link(prefix + self.titles.keys()[0], self.enwiki) self.assertEqual(l.namespace, num) # namespace prefixes are case-insensitive - m = pywikibot.page.Link(prefix.lower()+self.titles.keys()[1], + m = pywikibot.page.Link(prefix.lower() + self.titles.keys()[1], self.enwiki) self.assertEqual(m.namespace, num)
@@ -84,7 +84,7 @@ """Test that Link() normalizes titles""" for title in self.titles: for num in (0, 1): - l = pywikibot.page.Link(self.namespaces[num][0]+title) + l = pywikibot.page.Link(self.namespaces[num][0] + title) self.assertEqual(l.title, self.titles[title]) # prefixing name with ":" shouldn't change result m = pywikibot.page.Link(":" + self.namespaces[num][0] + title) diff --git a/tests/pwb/print_locals.py b/tests/pwb/print_locals.py index 1b84ac0..8bb8da2 100644 --- a/tests/pwb/print_locals.py +++ b/tests/pwb/print_locals.py @@ -1,4 +1,4 @@ """docstring"""
-for k,v in locals().copy().iteritems(): +for k, v in locals().copy().iteritems(): print repr(k), ":", repr(v) diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py index 506b02f..bd30b33 100644 --- a/tests/pwb_tests.py +++ b/tests/pwb_tests.py @@ -16,8 +16,9 @@
pypath = sys.executable basepath = os.path.split(os.path.split(__file__)[0])[0] -pwbpath = os.path.join(basepath, 'pwb.py') +pwbpath = os.path.join(basepath, 'pwb.py') testbasepath = os.path.join(basepath, 'tests', 'pwb') +
class TestPwb(unittest.TestCase): def setUp(self): @@ -35,8 +36,8 @@ test = os.path.join(testbasepath, 'print_locals.py')
direct = subprocess.check_output([pypath, test]) - vpwb = subprocess.check_output([pypath, pwbpath, test]) + vpwb = subprocess.check_output([pypath, pwbpath, test]) self.assertEqual(direct, vpwb)
-if __name__=="__main__": +if __name__ == "__main__": unittest.main(verbosity=10) diff --git a/tests/site_tests.py b/tests/site_tests.py index 0877653..01457ee 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -19,10 +19,12 @@ mainpage = None imagepage = None
+ class TestSiteObject(unittest.TestCase): """Test cases for Site methods.""" family = "wikipedia" code = "en" + @classmethod def setUpClass(cls): patch_request() @@ -92,21 +94,22 @@ def testNamespaceMethods(self): """Test cases for methods manipulating namespace names"""
- builtins = {'Talk': 1, # these should work in any MW wiki - 'User': 2, - 'User talk': 3, - 'Project': 4, - 'Project talk': 5, - 'Image': 6, - 'Image talk': 7, - 'MediaWiki': 8, - 'MediaWiki talk': 9, - 'Template': 10, - 'Template talk': 11, - 'Help': 12, - 'Help talk': 13, - 'Category': 14, - 'Category talk': 15, + builtins = { + 'Talk': 1, # these should work in any MW wiki + 'User': 2, + 'User talk': 3, + 'Project': 4, + 'Project talk': 5, + 'Image': 6, + 'Image talk': 7, + 'MediaWiki': 8, + 'MediaWiki talk': 9, + 'Template': 10, + 'Template talk': 11, + 'Help': 12, + 'Help talk': 13, + 'Category': 14, + 'Category talk': 15, } self.assertTrue(all(mysite.ns_index(b) == builtins[b] for b in builtins)) @@ -150,7 +153,7 @@ self.assertFalse(mysite.has_group("nonexistent_group", True)) except pywikibot.NoUsername: pywikibot.warning( - "Cannot test Site methods for sysop; no sysop account configured.") + "Cannot test Site methods for sysop; no sysop account configured.") for msg in ("1movedto2", "about", "aboutpage", "aboutsite", "accesskey-n-portal"): self.assertTrue(mysite.has_mediawiki_message(msg)) @@ -239,19 +242,19 @@ self.assertTrue(ref in backlinks or ref in embedded) # test embeddedin arguments self.assertTrue(embedded.issuperset( - set(mysite.page_embeddedin(mainpage, filterRedirects=True, - namespaces=[0])))) + set(mysite.page_embeddedin(mainpage, filterRedirects=True, + namespaces=[0])))) self.assertTrue(embedded.issuperset( - set(mysite.page_embeddedin(mainpage, filterRedirects=False, - namespaces=[0])))) + set(mysite.page_embeddedin(mainpage, filterRedirects=False, + namespaces=[0])))) self.assertTrue(embedded.issubset( - set(mysite.page_embeddedin(mainpage, namespaces=[0, 2])))) + set(mysite.page_embeddedin(mainpage, namespaces=[0, 2])))) links = set(mysite.pagelinks(mainpage)) for pl in links: self.assertType(pl, pywikibot.Page) # test links arguments self.assertTrue(links.issuperset( - set(mysite.pagelinks(mainpage, namespaces=[0, 1])))) + set(mysite.pagelinks(mainpage, namespaces=[0, 1])))) for target in mysite.preloadpages( mysite.pagelinks(mainpage, follow_redirects=True, total=5)): @@ -470,7 +473,7 @@ # timestamps should be in descending order timestamps = [block['timestamp'] for block in bl] for t in xrange(1, len(timestamps)): - self.assertTrue(timestamps[t] <= timestamps[t-1]) + self.assertTrue(timestamps[t] <= timestamps[t - 1])
b2 = list(mysite.blocks(total=10, reverse=True)) self.assertTrue(len(b2) <= 10) @@ -481,7 +484,7 @@ # timestamps should be in ascending order timestamps = [block['timestamp'] for block in b2] for t in xrange(1, len(timestamps)): - self.assertTrue(timestamps[t] >= timestamps[t-1]) + self.assertTrue(timestamps[t] >= timestamps[t - 1])
for block in mysite.blocks(starttime="2008-07-01T00:00:01Z", total=5): self.assertType(block, dict) @@ -534,7 +537,7 @@ self.assertTrue(len(iu) <= 10) self.assertTrue(all(isinstance(link, pywikibot.Page) for link in iu)) - for using in mysite.imageusage(imagepage, namespaces=[3,4], total=5): + for using in mysite.imageusage(imagepage, namespaces=[3, 4], total=5): self.assertType(using, pywikibot.Page) self.assertTrue(imagepage in list(using.imagelinks())) for using in mysite.imageusage(imagepage, filterredir=True, total=5): @@ -629,14 +632,14 @@ self.assertRaises(pywikibot.Error, mysite.recentchanges, start="2008-02-03T23:59:59Z", end="2008-02-03T00:00:01Z", reverse=True, total=5) - for change in mysite.recentchanges(namespaces=[6,7], total=5): + for change in mysite.recentchanges(namespaces=[6, 7], total=5): self.assertType(change, dict) self.assertTrue("title" in change and "ns" in change) title = change['title'] self.assertTrue(":" in title) prefix = title[ : title.index(":")] - self.assertTrue(mysite.ns_index(prefix) in [6,7]) - self.assertTrue(change["ns"] in [6,7]) + self.assertTrue(mysite.ns_index(prefix) in [6, 7]) + self.assertTrue(change["ns"] in [6, 7]) if mysite.versionnumber() <= 14: for change in mysite.recentchanges(pagelist=[mainpage, imagepage], total=5): @@ -691,12 +694,12 @@ for hit in mysite.search("common", namespaces=4, total=5): self.assertType(hit, pywikibot.Page) self.assertEqual(hit.namespace(), 4) - for hit in mysite.search("word", namespaces=[5,6,7], total=5): + for hit in mysite.search("word", namespaces=[5, 6, 7], total=5): self.assertType(hit, pywikibot.Page) - self.assertTrue(hit.namespace() in [5,6,7]) + self.assertTrue(hit.namespace() in [5, 6, 7]) for hit in mysite.search("another", namespaces="8|9|10", total=5): self.assertType(hit, pywikibot.Page) - self.assertTrue(hit.namespace() in [8,9,10]) + self.assertTrue(hit.namespace() in [8, 9, 10]) for hit in mysite.search("wiki", namespaces=0, total=10, getredirects=True): self.assertType(hit, pywikibot.Page) @@ -762,7 +765,7 @@ self.assertTrue("title" in contrib) self.assertTrue(contrib["title"].startswith(mysite.namespace(14))) for contrib in mysite.usercontribs(user=mysite.user(), - namespaces=[10,11], total=5): + namespaces=[10, 11], total=5): self.assertType(contrib, dict) self.assertTrue("title" in contrib) self.assertTrue(contrib["ns"] in (10, 11)) @@ -818,14 +821,14 @@ self.assertRaises(pywikibot.Error, mysite.watchlist_revs, start="2008-09-03T23:59:59Z", end="2008-09-03T00:00:01Z", reverse=True, total=5) - for rev in mysite.watchlist_revs(namespaces=[6,7], total=5): + for rev in mysite.watchlist_revs(namespaces=[6, 7], total=5): self.assertType(rev, dict) self.assertTrue("title" in rev and "ns" in rev) title = rev['title'] self.assertTrue(":" in title) prefix = title[ : title.index(":")] - self.assertTrue(mysite.ns_index(prefix) in [6,7]) - self.assertTrue(rev["ns"] in [6,7]) + self.assertTrue(mysite.ns_index(prefix) in [6, 7]) + self.assertTrue(rev["ns"] in [6, 7]) for rev in mysite.watchlist_revs(showMinor=True, total=5): self.assertType(rev, dict) self.assertTrue("minor" in rev) @@ -851,7 +854,7 @@ mysite.login(True) except pywikibot.NoUsername: pywikibot.warning( - "Cannot test Site.deleted_revs; no sysop account configured.") + "Cannot test Site.deleted_revs; no sysop account configured.") return dr = list(mysite.deletedrevs(total=10, page=mainpage)) self.assertTrue(len(dr) <= 10)
pywikibot-commits@lists.wikimedia.org