jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[cleanup] cleanup tests/[script_tests.py-tests_tests.py]

- use str.format(...) instead of modulo for type specifier arguments
- use single quotes for string literals
- remove preleading "u" fron strings
- indentation to make sure code lines are less than 79 characters

Change-Id: I97d24fa834e3f875a8547fc0e38f5a240f93907e
---
M tests/script_tests.py
M tests/site_detect_tests.py
M tests/site_tests.py
M tests/sparql_tests.py
4 files changed, 282 insertions(+), 267 deletions(-)

diff --git a/tests/script_tests.py b/tests/script_tests.py
index 5e821a6..af9e37b 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -181,8 +181,8 @@

if not enable_autorun_tests:
unittest_print('Skipping execution of auto-run scripts '
- '(set PYWIKIBOT_TEST_AUTORUN=1 to enable):\n %r'
- % auto_run_script_list)
+ '(set PYWIKIBOT_TEST_AUTORUN=1 to enable):\n {!r}'
+ .format(auto_run_script_list))

tests = (['test__login'] +
['test_' + name
@@ -297,14 +297,14 @@

if (not result['stdout'] and not result['stderr']):
unittest_print(' auto-run script unresponsive after '
- '%d seconds' % timeout, end=' ')
+ '{} seconds'.format(timeout), end=' ')
elif 'SIMULATION: edit action blocked' in result['stderr']:
unittest_print(' auto-run script simulated edit '
'blocked', end=' ')
else:
unittest_print(
- ' auto-run script stderr within %d seconds: %r'
- % (timeout, result['stderr']), end=' ')
+ ' auto-run script stderr within {} seconds: {!r}'
+ .format(timeout, result['stderr']), end=' ')

self.assertNotIn('Traceback (most recent call last)',
result['stderr'])
@@ -345,7 +345,8 @@

cls.add_method(dct, test_name,
test_execution(script_name, [argument]),
- 'Test running %s %s.' % (script_name, argument))
+ 'Test running {} {}.'
+ .format(script_name, argument))

if script_name in dct['_expected_failures']:
dct[test_name] = unittest.expectedFailure(dct[test_name])
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index bdf0d47..076393f 100644
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -71,8 +71,8 @@
def test_wikichristian(self):
"""Test detection of MediaWiki sites for www.wikichristian.org.

- Server that hosts www.wikichristian.org is unreliable - it occasionally
- responding with 500 error (see: T151368).
+ Server that hosts www.wikichristian.org is unreliable - it
+ occasionally responding with 500 error (see: T151368).
"""
self.assertSite('http://www.wikichristian.org/index.php?title=$1')

diff --git a/tests/site_tests.py b/tests/site_tests.py
index 837364e..3fe987e 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -119,9 +119,9 @@
self.assertIn('time', old)
self.assertEqual(old, self.site.siteinfo['general'])
self.assertEqual(self.site.siteinfo('general'), old)
- # Siteinfo always returns copies so it's not possible to directly check
- # if they are the same dict or if they have been rerequested unless the
- # content also changes so force that the content changes
+ # Siteinfo always returns copies so it's not possible to directly
+ # check if they are the same dict or if they have been rerequested
+ # unless the content also changes so force that the content changes
self.assertNotIn('DUMMY', old)
self.site.siteinfo._cache['general'][0]['DUMMY'] = 42
old = self.site.siteinfo('general')
@@ -298,23 +298,23 @@
else:
self.assertIsInstance(dabcat, pywikibot.Category)

- foo = unicode(pywikibot.Link("foo", source=mysite))
+ foo = unicode(pywikibot.Link('foo', source=mysite))
if self.site.namespaces[0].case == 'case-sensitive':
self.assertEqual(foo, '[[foo]]')
else:
self.assertEqual(foo, '[[Foo]]')

- self.assertFalse(mysite.isInterwikiLink("foo"))
+ self.assertFalse(mysite.isInterwikiLink('foo'))
self.assertIsInstance(mysite.redirectRegex().pattern, basestring)
self.assertIsInstance(mysite.category_on_one_line(), bool)
- self.assertTrue(mysite.sametitle("Template:Test", "Template:Test"))
- self.assertTrue(mysite.sametitle("Template: Test", "Template: Test"))
+ self.assertTrue(mysite.sametitle('Template:Test', 'Template:Test'))
+ self.assertTrue(mysite.sametitle('Template: Test', 'Template: Test'))
self.assertTrue(mysite.sametitle('Test name', 'Test name'))
self.assertFalse(mysite.sametitle('Test name', 'Test Name'))
# User, MediaWiki (both since 1.16) and Special are always
# first-letter (== only first non-namespace letter is case insensitive)
# See also: https://www.mediawiki.org/wiki/Manual:$wgCapitalLinks
- self.assertTrue(mysite.sametitle("Special:Always", "Special:always"))
+ self.assertTrue(mysite.sametitle('Special:Always', 'Special:always'))
if mysite.mw_version >= '1.16':
self.assertTrue(mysite.sametitle('User:Always', 'User:always'))
self.assertTrue(mysite.sametitle('MediaWiki:Always',
@@ -369,7 +369,7 @@
self.assertIsInstance(ns, Mapping)
self.assertTrue(all(x in ns for x in range(0, 16)))
# built-in namespaces always present
- self.assertIsInstance(mysite.ns_normalize("project"), basestring)
+ self.assertIsInstance(mysite.ns_normalize('project'), basestring)
self.assertTrue(all(isinstance(key, int)
for key in ns))
self.assertTrue(all(isinstance(val, Iterable)
@@ -398,8 +398,8 @@
for msg in ('about', 'aboutpage', 'aboutsite', 'accesskey-n-portal'):
self.assertTrue(mysite.has_mediawiki_message(msg))
self.assertIsInstance(mysite.mediawiki_message(msg), basestring)
- self.assertFalse(mysite.has_mediawiki_message("nosuchmessage"))
- self.assertRaises(KeyError, mysite.mediawiki_message, "nosuchmessage")
+ self.assertFalse(mysite.has_mediawiki_message('nosuchmessage'))
+ self.assertRaises(KeyError, mysite.mediawiki_message, 'nosuchmessage')

msg = ('about', 'aboutpage')
about_msgs = self.site.mediawiki_messages(msg)
@@ -411,7 +411,7 @@
# mediawiki_messages must be given a list; using a string will split it
self.assertRaises(KeyError, self.site.mediawiki_messages, 'about')

- msg = ("nosuchmessage1", "about", "aboutpage", "nosuchmessage")
+ msg = ('nosuchmessage1', 'about', 'aboutpage', 'nosuchmessage')
self.assertFalse(mysite.has_all_mediawiki_messages(msg))
self.assertRaises(KeyError, mysite.mediawiki_messages, msg)

@@ -434,9 +434,9 @@
mysite = self.get_site()
if mysite.lang != 'en':
raise unittest.SkipTest(
- 'English-specific tests not valid on %s' % mysite)
+ 'English-specific tests not valid on {}'.format(mysite))

- self.assertEqual(mysite.months_names[4], (u'May', u'May'))
+ self.assertEqual(mysite.months_names[4], ('May', 'May'))
self.assertEqual(mysite.list_to_text(('Pride', 'Prejudice')),
'Pride and Prejudice')
self.assertEqual(mysite.list_to_text(('This', 'that', 'the other')),
@@ -635,23 +635,23 @@
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
self.assertEqual(page.namespace(), 0)
- rev = list(mysite.allpages(reverse=True, start="Aa", total=12))
+ rev = list(mysite.allpages(reverse=True, start='Aa', total=12))
self.assertLessEqual(len(rev), 12)
for page in rev:
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
self.assertEqual(page.namespace(), 0)
- self.assertLessEqual(page.title(), "Aa")
- for page in mysite.allpages(start="Py", total=5):
+ self.assertLessEqual(page.title(), 'Aa')
+ for page in mysite.allpages(start='Py', total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
self.assertEqual(page.namespace(), 0)
- self.assertGreaterEqual(page.title(), "Py")
- for page in mysite.allpages(prefix="Pre", total=5):
+ self.assertGreaterEqual(page.title(), 'Py')
+ for page in mysite.allpages(prefix='Pre', total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
self.assertEqual(page.namespace(), 0)
- self.assertTrue(page.title().startswith("Pre"))
+ self.assertTrue(page.title().startswith('Pre'))
for page in mysite.allpages(namespace=1, total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
@@ -710,16 +710,16 @@
def test_allpages_protection(self):
"""Test allpages with protect_type parameter."""
mysite = self.get_site()
- for page in mysite.allpages(protect_type="edit", total=5):
+ for page in mysite.allpages(protect_type='edit', total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
- self.assertIn("edit", page._protection)
- for page in mysite.allpages(protect_type="edit",
- protect_level="sysop", total=5):
+ self.assertIn('edit', page._protection)
+ for page in mysite.allpages(protect_type='edit',
+ protect_level='sysop', total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
- self.assertIn("edit", page._protection)
- self.assertIn("sysop", page._protection["edit"])
+ self.assertIn('edit', page._protection)
+ self.assertIn('sysop', page._protection['edit'])

def test_all_links(self):
"""Test the site.alllinks() method."""
@@ -732,22 +732,22 @@
self.assertTrue(all(isinstance(link, pywikibot.Page) for link in fwd))
uniq = list(mysite.alllinks(total=10, unique=True))
self.assertTrue(all(link in uniq for link in fwd))
- for page in mysite.alllinks(start="Link", total=5):
+ for page in mysite.alllinks(start='Link', total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertEqual(page.namespace(), 0)
- self.assertGreaterEqual(page.title(), "Link")
- for page in mysite.alllinks(prefix="Fix", total=5):
+ self.assertGreaterEqual(page.title(), 'Link')
+ for page in mysite.alllinks(prefix='Fix', total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertEqual(page.namespace(), 0)
- self.assertTrue(page.title().startswith("Fix"))
+ self.assertTrue(page.title().startswith('Fix'))
for page in mysite.alllinks(namespace=1, total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertEqual(page.namespace(), 1)
- for page in mysite.alllinks(start="From", namespace=4, fromids=True,
+ for page in mysite.alllinks(start='From', namespace=4, fromids=True,
total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertGreaterEqual(page.title(with_ns=False), 'From')
- self.assertTrue(hasattr(page, "_fromid"))
+ self.assertTrue(hasattr(page, '_fromid'))
errgen = mysite.alllinks(unique=True, fromids=True)
self.assertRaises(pywikibot.Error, next, errgen)

@@ -758,14 +758,14 @@
self.assertLessEqual(len(ac), 10)
self.assertTrue(all(isinstance(cat, pywikibot.Category)
for cat in ac))
- for cat in mysite.allcategories(total=5, start="Abc"):
+ for cat in mysite.allcategories(total=5, start='Abc'):
self.assertIsInstance(cat, pywikibot.Category)
self.assertGreaterEqual(cat.title(with_ns=False), 'Abc')
- for cat in mysite.allcategories(total=5, prefix="Def"):
+ for cat in mysite.allcategories(total=5, prefix='Def'):
self.assertIsInstance(cat, pywikibot.Category)
self.assertTrue(cat.title(with_ns=False).startswith('Def'))
# Bug T17985 - reverse and start combined; fixed in v 1.14
- for cat in mysite.allcategories(total=5, start="Hij", reverse=True):
+ for cat in mysite.allcategories(total=5, start='Hij', reverse=True):
self.assertIsInstance(cat, pywikibot.Category)
self.assertLessEqual(cat.title(with_ns=False), 'Hij')

@@ -789,40 +789,40 @@
self.assertLessEqual(len(au), 10)
for user in au:
self.assertIsInstance(user, dict)
- self.assertIn("name", user)
- self.assertIn("editcount", user)
- self.assertIn("registration", user)
+ self.assertIn('name', user)
+ self.assertIn('editcount', user)
+ self.assertIn('registration', user)
self.assertIn('user', user['groups'])

def test_allusers_with_start(self):
"""Test the site.allusers(start=..) method."""
mysite = self.get_site()
- for user in mysite.allusers(start="B", total=5):
+ for user in mysite.allusers(start='B', total=5):
self.assertIsInstance(user, dict)
- self.assertIn("name", user)
- self.assertGreaterEqual(user["name"], "B")
- self.assertIn("editcount", user)
- self.assertIn("registration", user)
+ self.assertIn('name', user)
+ self.assertGreaterEqual(user['name'], 'B')
+ self.assertIn('editcount', user)
+ self.assertIn('registration', user)

def test_allusers_with_prefix(self):
"""Test the site.allusers(prefix=..) method."""
mysite = self.get_site()
- for user in mysite.allusers(prefix="C", total=5):
+ for user in mysite.allusers(prefix='C', total=5):
self.assertIsInstance(user, dict)
- self.assertIn("name", user)
- self.assertTrue(user["name"].startswith("C"))
- self.assertIn("editcount", user)
- self.assertIn("registration", user)
+ self.assertIn('name', user)
+ self.assertTrue(user['name'].startswith('C'))
+ self.assertIn('editcount', user)
+ self.assertIn('registration', user)

def _test_allusers_with_group(self):
"""Test the site.allusers(group=..) method."""
mysite = self.get_site()
- for user in mysite.allusers(prefix="D", group="bot", total=5):
+ for user in mysite.allusers(prefix='D', group='bot', total=5):
self.assertIsInstance(user, dict)
- self.assertIn("name", user)
- self.assertTrue(user["name"].startswith("D"))
- self.assertIn("editcount", user)
- self.assertIn("registration", user)
+ self.assertIn('name', user)
+ self.assertTrue(user['name'].startswith('D'))
+ self.assertIn('editcount', user)
+ self.assertIn('registration', user)
self.assertIn('groups' in user)
self.assertIn('sysop' in user['groups'])

@@ -833,27 +833,27 @@
self.assertLessEqual(len(ai), 10)
self.assertTrue(all(isinstance(image, pywikibot.FilePage)
for image in ai))
- for impage in mysite.allimages(start="Ba", total=5):
+ for impage in mysite.allimages(start='Ba', total=5):
self.assertIsInstance(impage, pywikibot.FilePage)
self.assertTrue(impage.exists())
self.assertGreaterEqual(impage.title(with_ns=False), 'Ba')
# Bug T17985 - reverse and start combined; fixed in v 1.14
- for impage in mysite.allimages(start="Da", reverse=True, total=5):
+ for impage in mysite.allimages(start='Da', reverse=True, total=5):
self.assertIsInstance(impage, pywikibot.FilePage)
self.assertTrue(impage.exists())
self.assertLessEqual(impage.title(with_ns=False), 'Da')
- for impage in mysite.allimages(prefix="Ch", total=5):
+ for impage in mysite.allimages(prefix='Ch', total=5):
self.assertIsInstance(impage, pywikibot.FilePage)
self.assertTrue(impage.exists())
self.assertTrue(impage.title(with_ns=False).startswith('Ch'))
for impage in mysite.allimages(minsize=100, total=5):
self.assertIsInstance(impage, pywikibot.FilePage)
self.assertTrue(impage.exists())
- self.assertGreaterEqual(impage.latest_file_info["size"], 100)
+ self.assertGreaterEqual(impage.latest_file_info['size'], 100)
for impage in mysite.allimages(maxsize=2000, total=5):
self.assertIsInstance(impage, pywikibot.FilePage)
self.assertTrue(impage.exists())
- self.assertLessEqual(impage.latest_file_info["size"], 2000)
+ self.assertLessEqual(impage.latest_file_info['size'], 2000)

def test_newfiles(self):
"""Test the site.newfiles() method."""
@@ -930,7 +930,7 @@
def test_blocks(self):
"""Test the site.blocks() method."""
mysite = self.get_site()
- props = ("id", "by", "timestamp", "expiry", "reason")
+ props = ('id', 'by', 'timestamp', 'expiry', 'reason')
bl = list(mysite.blocks(total=10))
self.assertLessEqual(len(bl), 10)
for block in bl:
@@ -1005,7 +1005,7 @@
def test_exturl_usage(self):
"""Test the site.exturlusage() method."""
mysite = self.get_site()
- url = "www.google.com"
+ url = 'www.google.com'
eu = list(mysite.exturlusage(url, total=10))
self.assertLessEqual(len(eu), 10)
self.assertTrue(all(isinstance(link, pywikibot.Page)
@@ -1017,7 +1017,7 @@
def test_lock_page(self):
"""Test the site.lock_page() and site.unlock_page() method."""
site = self.get_site()
- p1 = pywikibot.Page(site, u'Foo')
+ p1 = pywikibot.Page(site, 'Foo')

site.lock_page(page=p1, block=True)
self.assertRaises(pywikibot.site.PageInUse, site.lock_page, page=p1,
@@ -1158,8 +1158,8 @@
raise unittest.SkipTest(
'No images on the main page of site {0!r}'.format(mysite))

- pywikibot.output(u'site_tests.TestImageUsage found %s on %s'
- % (imagepage, page))
+ pywikibot.output('site_tests.TestImageUsage found {} on {}'
+ .format(imagepage, page))

self.__class__._image_page = imagepage
return imagepage
@@ -1214,14 +1214,14 @@
mysite = self.get_site()
self.assertIsInstance(mysite.is_blocked(), bool)
self.assertIsInstance(mysite.messages(), bool)
- self.assertIsInstance(mysite.has_right("edit"), bool)
- self.assertFalse(mysite.has_right("nonexistent_right"))
- self.assertIsInstance(mysite.has_group("bots"), bool)
- self.assertFalse(mysite.has_group("nonexistent_group"))
- for grp in ("user", "autoconfirmed", "bot", "sysop", "nosuchgroup"):
+ self.assertIsInstance(mysite.has_right('edit'), bool)
+ self.assertFalse(mysite.has_right('nonexistent_right'))
+ self.assertIsInstance(mysite.has_group('bots'), bool)
+ self.assertFalse(mysite.has_group('nonexistent_group'))
+ for grp in ('user', 'autoconfirmed', 'bot', 'sysop', 'nosuchgroup'):
self.assertIsInstance(mysite.has_group(grp), bool)
- for rgt in ("read", "edit", "move", "delete", "rollback", "block",
- "nosuchright"):
+ for rgt in ('read', 'edit', 'move', 'delete', 'rollback', 'block',
+ 'nosuchright'):
self.assertIsInstance(mysite.has_right(rgt), bool)

def test_logevents(self):
@@ -1242,8 +1242,8 @@
self.assertLessEqual(len(le), 10)
self.assertTrue(all(isinstance(entry, pywikibot.logentries.LogEntry)
for entry in le))
- for typ in ("block", "protect", "rights", "delete", "upload",
- "move", "import", "patrol", "merge"):
+ 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)

@@ -1273,7 +1273,7 @@
for entry in mysite.logevents(
start=pywikibot.Timestamp.fromISOformat(
'2008-02-02T00:00:01Z'),
- end=pywikibot.Timestamp.fromISOformat("2008-02-02T23:59:59Z"),
+ end=pywikibot.Timestamp.fromISOformat('2008-02-02T23:59:59Z'),
reverse=True, total=5):
self.assertIsInstance(entry, pywikibot.logentries.LogEntry)
self.assertTrue(
@@ -1282,11 +1282,12 @@
for entry in mysite.logevents(
start=pywikibot.Timestamp.fromISOformat(
'2008-02-03T23:59:59Z'),
- end=pywikibot.Timestamp.fromISOformat("2008-02-03T00:00:01Z"),
+ end=pywikibot.Timestamp.fromISOformat('2008-02-03T00:00:01Z'),
total=5):
self.assertIsInstance(entry, pywikibot.logentries.LogEntry)
self.assertTrue(
- "2008-02-03T00:00:01Z" <= str(entry.timestamp()) <= "2008-02-03T23:59:59Z")
+ '2008-02-03T00:00:01Z' <= str(entry.timestamp())
+ <= '2008-02-03T23:59:59Z')
# starttime earlier than endtime
self.assertRaises(pywikibot.Error, mysite.logevents,
start=pywikibot.Timestamp.fromISOformat(
@@ -1373,7 +1374,7 @@
'2008-10-01T01:02:03Z'),
total=5):
self.assertIsInstance(change, dict)
- self.assertLessEqual(change['timestamp'], "2008-10-01T01:02:03Z")
+ self.assertLessEqual(change['timestamp'], '2008-10-01T01:02:03Z')
for change in mysite.recentchanges(
end=pywikibot.Timestamp.fromISOformat('2008-04-01T02:03:04Z'),
total=5):
@@ -1391,11 +1392,11 @@
end=pywikibot.Timestamp.fromISOformat('2008-10-01T04:06:08Z'),
total=5, reverse=True):
self.assertIsInstance(change, dict)
- self.assertLessEqual(change['timestamp'], "2008-10-01T04:06:08Z")
+ self.assertLessEqual(change['timestamp'], '2008-10-01T04:06:08Z')
for change in mysite.recentchanges(
start=pywikibot.Timestamp.fromISOformat(
'2008-10-03T11:59:59Z'),
- end=pywikibot.Timestamp.fromISOformat("2008-10-03T00:00:01Z"),
+ end=pywikibot.Timestamp.fromISOformat('2008-10-03T00:00:01Z'),
total=5):
self.assertIsInstance(change, dict)
self.assertTrue(
@@ -1404,7 +1405,7 @@
for change in mysite.recentchanges(
start=pywikibot.Timestamp.fromISOformat(
'2008-10-05T06:00:01Z'),
- end=pywikibot.Timestamp.fromISOformat("2008-10-05T23:59:59Z"),
+ end=pywikibot.Timestamp.fromISOformat('2008-10-05T23:59:59Z'),
reverse=True, total=5):
self.assertIsInstance(change, dict)
self.assertTrue(
@@ -1412,8 +1413,8 @@
<= '2008-10-05T23:59:59Z')
# start earlier than end
self.assertRaises(pywikibot.Error, mysite.recentchanges,
- start="2008-02-03T00:00:01Z",
- end="2008-02-03T23:59:59Z", total=5)
+ start='2008-02-03T00:00:01Z',
+ end='2008-02-03T23:59:59Z', total=5)
# reverse: end earlier than start
self.assertRaises(pywikibot.Error, mysite.recentchanges,
start=pywikibot.Timestamp.fromISOformat(
@@ -1433,8 +1434,8 @@
self.assertIn('title', change)
self.assertIn('ns', change)
title = change['title']
- self.assertIn(":", title)
- prefix = title[:title.index(":")]
+ self.assertIn(':', title)
+ prefix = title[:title.index(':')]
self.assertIn(self.site.namespaces.lookup_name(prefix).id, [6, 7])
self.assertIn(change["ns"], [6, 7])

@@ -1451,43 +1452,43 @@
for change in mysite.recentchanges(pagelist=pagelist,
total=5):
self.assertIsInstance(change, dict)
- self.assertIn("title", change)
- self.assertIn(change["title"], titlelist)
+ self.assertIn('title', change)
+ self.assertIn(change['title'], titlelist)

def test_changetype(self):
"""Test the site.recentchanges() with changetype."""
mysite = self.site
- for typ in ("edit", "new", "log"):
+ for typ in ('edit', 'new', 'log'):
for change in mysite.recentchanges(changetype=typ, total=5):
self.assertIsInstance(change, dict)
- self.assertIn("type", change)
- self.assertEqual(change["type"], typ)
+ self.assertIn('type', change)
+ self.assertEqual(change['type'], typ)

def test_flags(self):
"""Test the site.recentchanges() with boolean flags."""
mysite = self.site
for change in mysite.recentchanges(minor=True, total=5):
self.assertIsInstance(change, dict)
- self.assertIn("minor", change)
+ self.assertIn('minor', change)
for change in mysite.recentchanges(minor=False, total=5):
self.assertIsInstance(change, dict)
- self.assertNotIn("minor", change)
+ self.assertNotIn('minor', change)
for change in mysite.recentchanges(bot=True, total=5):
self.assertIsInstance(change, dict)
- self.assertIn("bot", change)
+ self.assertIn('bot', change)
for change in mysite.recentchanges(bot=False, total=5):
self.assertIsInstance(change, dict)
- self.assertNotIn("bot", change)
+ self.assertNotIn('bot', change)
for change in mysite.recentchanges(anon=True, total=5):
self.assertIsInstance(change, dict)
for change in mysite.recentchanges(anon=False, total=5):
self.assertIsInstance(change, dict)
for change in mysite.recentchanges(redirect=True, total=5):
self.assertIsInstance(change, dict)
- self.assertIn("redirect", change)
+ self.assertIn('redirect', change)
for change in mysite.recentchanges(redirect=False, total=5):
self.assertIsInstance(change, dict)
- self.assertNotIn("redirect", change)
+ self.assertNotIn('redirect', change)

def test_tag_filter(self):
"""Test the site.recentchanges() with tag filter."""
@@ -1512,11 +1513,11 @@
for change in mysite.recentchanges(patrolled=True, total=5):
self.assertIsInstance(change, dict)
if mysite.has_right('patrol'):
- self.assertIn("patrolled", change)
+ self.assertIn('patrolled', change)
for change in mysite.recentchanges(patrolled=False, total=5):
self.assertIsInstance(change, dict)
if mysite.has_right('patrol'):
- self.assertNotIn("patrolled", change)
+ self.assertNotIn('patrolled', change)


class TestUserWatchedPages(DefaultSiteTestCase):
@@ -1555,34 +1556,36 @@
super(SearchTestCase, self).setUp()
if self.site.has_extension('Wikia Search'):
raise unittest.SkipTest(
- 'The site %r does not use MediaWiki search' % self.site)
+ 'The site {!r} does not use MediaWiki search'
+ .format(self.site))

def test_search(self):
"""Test the site.search() method."""
mysite = self.site
try:
- se = list(mysite.search("wiki", total=100, namespaces=0))
+ se = list(mysite.search('wiki', total=100, namespaces=0))
self.assertLessEqual(len(se), 100)
self.assertTrue(all(isinstance(hit, pywikibot.Page)
for hit in se))
self.assertTrue(all(hit.namespace() == 0 for hit in se))
- for hit in mysite.search("common", namespaces=4, total=5):
+ for hit in mysite.search('common', namespaces=4, total=5):
self.assertIsInstance(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.assertIsInstance(hit, pywikibot.Page)
self.assertIn(hit.namespace(), [5, 6, 7])
- for hit in mysite.search("another", namespaces="8|9|10", total=5):
+ for hit in mysite.search('another', namespaces='8|9|10', total=5):
self.assertIsInstance(hit, pywikibot.Page)
self.assertIn(hit.namespace(), [8, 9, 10])
- for hit in mysite.search("wiki", namespaces=0, total=10,
+ for hit in mysite.search('wiki', namespaces=0, total=10,
get_redirects=True):
self.assertIsInstance(hit, pywikibot.Page)
self.assertEqual(hit.namespace(), 0)
except pywikibot.data.api.APIError as e:
- if e.code == "gsrsearch-error" and "timed out" in e.info:
+ if e.code == 'gsrsearch-error' and 'timed out' in e.info:
raise unittest.SkipTest(
- 'gsrsearch returned timeout on site: %r' % e)
+ 'gsrsearch returned timeout on site: {!r}'
+ .format(e))
raise

@suppress_warnings("where='title' is deprecated", DeprecationWarning)
@@ -1639,14 +1642,14 @@
for contrib in mysite.usercontribs(user=mysite.user(),
namespaces=14, total=5):
self.assertIsInstance(contrib, dict)
- self.assertIn("title", contrib)
- self.assertTrue(contrib["title"].startswith(mysite.namespace(14)))
+ self.assertIn('title', contrib)
+ self.assertTrue(contrib['title'].startswith(mysite.namespace(14)))

for contrib in mysite.usercontribs(user=mysite.user(),
namespaces=[10, 11], total=5):
self.assertIsInstance(contrib, dict)
- self.assertIn("title", contrib)
- self.assertIn(contrib["ns"], (10, 11))
+ self.assertIn('title', contrib)
+ self.assertIn(contrib['ns'], (10, 11))

def test_show_minor(self):
"""Test the site.usercontribs() method using showMinor."""
@@ -1654,12 +1657,12 @@
for contrib in mysite.usercontribs(user=mysite.user(),
minor=True, total=5):
self.assertIsInstance(contrib, dict)
- self.assertIn("minor", contrib)
+ self.assertIn('minor', contrib)

for contrib in mysite.usercontribs(user=mysite.user(),
minor=False, total=5):
self.assertIsInstance(contrib, dict)
- self.assertNotIn("minor", contrib)
+ self.assertNotIn('minor', contrib)


class TestUserContribsWithoutUser(DefaultSiteTestCase):
@@ -1669,11 +1672,11 @@
def test_user_prefix(self):
"""Test the site.usercontribs() method with userprefix."""
mysite = self.get_site()
- for contrib in mysite.usercontribs(userprefix="John", total=5):
+ for contrib in mysite.usercontribs(userprefix='John', total=5):
self.assertIsInstance(contrib, dict)
- for key in ("user", "title", "ns", "pageid", "revid"):
+ for key in ('user', 'title', 'ns', 'pageid', 'revid'):
self.assertIn(key, contrib)
- self.assertTrue(contrib["user"].startswith("John"))
+ self.assertTrue(contrib['user'].startswith('John'))

def test_user_prefix_range(self):
"""Test the site.usercontribs() method."""
@@ -1713,9 +1716,9 @@

for contrib in mysite.usercontribs(
userprefix='Brion',
- end=pywikibot.Timestamp.fromISOformat("2008-10-09T04:06:08Z"),
+ end=pywikibot.Timestamp.fromISOformat('2008-10-09T04:06:08Z'),
total=5, reverse=True):
- self.assertLessEqual(contrib['timestamp'], "2008-10-09T04:06:08Z")
+ self.assertLessEqual(contrib['timestamp'], '2008-10-09T04:06:08Z')

start = '2008-10-11T06:00:01Z'
end = '2008-10-11T23:59:59Z'
@@ -1731,14 +1734,14 @@
mysite = self.get_site()
# start earlier than end
self.assertRaises(pywikibot.Error, mysite.usercontribs,
- userprefix="Jim",
- start="2008-10-03T00:00:01Z",
- end="2008-10-03T23:59:59Z", total=5)
+ userprefix='Jim',
+ start='2008-10-03T00:00:01Z',
+ end='2008-10-03T23:59:59Z', total=5)
# reverse: end earlier than start
self.assertRaises(pywikibot.Error, mysite.usercontribs,
- userprefix="Jim",
- start="2008-10-03T23:59:59Z",
- end="2008-10-03T00:00:01Z", reverse=True, total=5)
+ userprefix='Jim',
+ start='2008-10-03T23:59:59Z',
+ end='2008-10-03T00:00:01Z', reverse=True, total=5)


class SiteWatchlistRevsTestCase(DefaultSiteTestCase):
@@ -1754,31 +1757,31 @@
self.assertLessEqual(len(wl), 10)
self.assertTrue(all(isinstance(rev, dict)
for rev in wl))
- for rev in mysite.watchlist_revs(start="2008-10-11T01:02:03Z",
+ for rev in mysite.watchlist_revs(start='2008-10-11T01:02:03Z',
total=5):
self.assertIsInstance(rev, dict)
- self.assertLessEqual(rev['timestamp'], "2008-10-11T01:02:03Z")
- for rev in mysite.watchlist_revs(end="2008-04-01T02:03:04Z",
+ self.assertLessEqual(rev['timestamp'], '2008-10-11T01:02:03Z')
+ for rev in mysite.watchlist_revs(end='2008-04-01T02:03:04Z',
total=5):
self.assertIsInstance(rev, dict)
- self.assertGreaterEqual(rev['timestamp'], "2008-10-11T02:03:04Z")
- for rev in mysite.watchlist_revs(start="2008-10-11T03:05:07Z",
+ self.assertGreaterEqual(rev['timestamp'], '2008-10-11T02:03:04Z')
+ for rev in mysite.watchlist_revs(start='2008-10-11T03:05:07Z',
total=5, reverse=True):
self.assertIsInstance(rev, dict)
- self.assertGreaterEqual(rev['timestamp'], "2008-10-11T03:05:07Z")
- for rev in mysite.watchlist_revs(end="2008-10-11T04:06:08Z",
+ self.assertGreaterEqual(rev['timestamp'], '2008-10-11T03:05:07Z')
+ for rev in mysite.watchlist_revs(end='2008-10-11T04:06:08Z',
total=5, reverse=True):
self.assertIsInstance(rev, dict)
- self.assertLessEqual(rev['timestamp'], "2008-10-11T04:06:08Z")
- for rev in mysite.watchlist_revs(start="2008-10-13T11:59:59Z",
- end="2008-10-13T00:00:01Z",
+ self.assertLessEqual(rev['timestamp'], '2008-10-11T04:06:08Z')
+ for rev in mysite.watchlist_revs(start='2008-10-13T11:59:59Z',
+ end='2008-10-13T00:00:01Z',
total=5):
self.assertIsInstance(rev, dict)
self.assertTrue(
'2008-10-13T00:00:01Z' <= rev['timestamp']
<= '2008-10-13T11:59:59Z')
- for rev in mysite.watchlist_revs(start="2008-10-15T06:00:01Z",
- end="2008-10-15T23:59:59Z",
+ for rev in mysite.watchlist_revs(start='2008-10-15T06:00:01Z',
+ end='2008-10-15T23:59:59Z',
reverse=True, total=5):
self.assertIsInstance(rev, dict)
self.assertTrue(
@@ -1786,33 +1789,33 @@
<= '2008-10-15T23:59:59Z')
# start earlier than end
self.assertRaises(pywikibot.Error, mysite.watchlist_revs,
- start="2008-09-03T00:00:01Z",
- end="2008-09-03T23:59:59Z", total=5)
+ start='2008-09-03T00:00:01Z',
+ end='2008-09-03T23:59:59Z', total=5)
# reverse: end earlier than start
self.assertRaises(pywikibot.Error, mysite.watchlist_revs,
- start="2008-09-03T23:59:59Z",
- end="2008-09-03T00:00:01Z", reverse=True, total=5)
+ 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):
self.assertIsInstance(rev, dict)
self.assertIn('title', rev)
self.assertIn('ns', rev)
title = rev['title']
- self.assertIn(":", title)
- prefix = title[:title.index(":")]
+ self.assertIn(':', title)
+ prefix = title[:title.index(':')]
self.assertIn(self.site.namespaces.lookup_name(prefix).id, [6, 7])
- self.assertIn(rev["ns"], [6, 7])
+ self.assertIn(rev['ns'], [6, 7])
for rev in mysite.watchlist_revs(minor=True, total=5):
self.assertIsInstance(rev, dict)
- self.assertIn("minor", rev)
+ self.assertIn('minor', rev)
for rev in mysite.watchlist_revs(minor=False, total=5):
self.assertIsInstance(rev, dict)
- self.assertNotIn("minor", rev)
+ self.assertNotIn('minor', rev)
for rev in mysite.watchlist_revs(bot=True, total=5):
self.assertIsInstance(rev, dict)
- self.assertIn("bot", rev)
+ self.assertIn('bot', rev)
for rev in mysite.watchlist_revs(bot=False, total=5):
self.assertIsInstance(rev, dict)
- self.assertNotIn("bot", rev)
+ self.assertNotIn('bot', rev)
for rev in mysite.watchlist_revs(anon=True, total=5):
self.assertIsInstance(rev, dict)
for rev in mysite.watchlist_revs(anon=False, total=5):
@@ -1829,10 +1832,10 @@
"""Test sysop related methods."""
mysite = self.get_site()
self.assertIsInstance(mysite.is_blocked(True), bool)
- self.assertIsInstance(mysite.has_right("edit", True), bool)
- self.assertFalse(mysite.has_right("nonexistent_right", True))
- self.assertIsInstance(mysite.has_group("bots", True), bool)
- self.assertFalse(mysite.has_group("nonexistent_group", True))
+ self.assertIsInstance(mysite.has_right('edit', True), bool)
+ self.assertFalse(mysite.has_right('nonexistent_right', True))
+ self.assertIsInstance(mysite.has_group('bots', True), bool)
+ self.assertFalse(mysite.has_group('nonexistent_group', True))

def test_deletedrevs(self):
"""Test the site.deletedrevs() method."""
@@ -1847,56 +1850,56 @@
self.assertLessEqual(len(dr['revisions']), 10)
self.assertTrue(all(isinstance(rev, dict)
for rev in dr['revisions']))
- for item in mysite.deletedrevs(start="2008-10-11T01:02:03Z",
+ for item in mysite.deletedrevs(start='2008-10-11T01:02:03Z',
page=mainpage, total=5):
for rev in item['revisions']:
self.assertIsInstance(rev, dict)
- self.assertLessEqual(rev['timestamp'], "2008-10-11T01:02:03Z")
- for item in mysite.deletedrevs(end="2008-04-01T02:03:04Z",
+ self.assertLessEqual(rev['timestamp'], '2008-10-11T01:02:03Z')
+ for item in mysite.deletedrevs(end='2008-04-01T02:03:04Z',
page=mainpage, total=5):
for rev in item['revisions']:
self.assertIsInstance(rev, dict)
self.assertGreaterEqual(rev['timestamp'],
'2008-10-11T02:03:04Z')
- for item in mysite.deletedrevs(start="2008-10-11T03:05:07Z",
+ for item in mysite.deletedrevs(start='2008-10-11T03:05:07Z',
page=mainpage, total=5,
reverse=True):
for rev in item['revisions']:
self.assertIsInstance(rev, dict)
self.assertGreaterEqual(rev['timestamp'],
'2008-10-11T03:05:07Z')
- for item in mysite.deletedrevs(end="2008-10-11T04:06:08Z",
+ for item in mysite.deletedrevs(end='2008-10-11T04:06:08Z',
page=mainpage, total=5,
reverse=True):
for rev in item['revisions']:
self.assertIsInstance(rev, dict)
- self.assertLessEqual(rev['timestamp'], "2008-10-11T04:06:08Z")
- for item in mysite.deletedrevs(start="2008-10-13T11:59:59Z",
- end="2008-10-13T00:00:01Z",
+ self.assertLessEqual(rev['timestamp'], '2008-10-11T04:06:08Z')
+ for item in mysite.deletedrevs(start='2008-10-13T11:59:59Z',
+ end='2008-10-13T00:00:01Z',
page=mainpage, total=5):
for rev in item['revisions']:
self.assertIsInstance(rev, dict)
- self.assertLessEqual(rev['timestamp'], "2008-10-13T11:59:59Z")
+ self.assertLessEqual(rev['timestamp'], '2008-10-13T11:59:59Z')
self.assertGreaterEqual(rev['timestamp'],
'2008-10-13T00:00:01Z')
- for item in mysite.deletedrevs(start="2008-10-15T06:00:01Z",
- end="2008-10-15T23:59:59Z",
+ for item in mysite.deletedrevs(start='2008-10-15T06:00:01Z',
+ end='2008-10-15T23:59:59Z',
page=mainpage, reverse=True,
total=5):
for rev in item['revisions']:
self.assertIsInstance(rev, dict)
- self.assertLessEqual(rev['timestamp'], "2008-10-15T23:59:59Z")
+ self.assertLessEqual(rev['timestamp'], '2008-10-15T23:59:59Z')
self.assertGreaterEqual(rev['timestamp'],
'2008-10-15T06:00:01Z')

# start earlier than end
self.assertRaises(pywikibot.Error, mysite.deletedrevs,
- page=mainpage, start="2008-09-03T00:00:01Z",
- end="2008-09-03T23:59:59Z", total=5)
+ page=mainpage, start='2008-09-03T00:00:01Z',
+ end='2008-09-03T23:59:59Z', total=5)
# reverse: end earlier than start
self.assertRaises(pywikibot.Error, mysite.deletedrevs,
- page=mainpage, start="2008-09-03T23:59:59Z",
- end="2008-09-03T00:00:01Z", reverse=True,
+ page=mainpage, start='2008-09-03T23:59:59Z',
+ end='2008-09-03T00:00:01Z', reverse=True,
total=5)


@@ -1913,7 +1916,7 @@
def test_protect(self):
"""Test the site.protect() method."""
site = self.get_site()
- p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+ p1 = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest')

r = site.protect(protections={'edit': 'sysop',
'move': 'autoconfirmed'},
@@ -1921,8 +1924,8 @@
reason='Pywikibot unit test')
self.assertEqual(r, None)
self.assertEqual(site.page_restrictions(page=p1),
- {u'edit': (u'sysop', u'infinity'),
- u'move': (u'autoconfirmed', u'infinity')})
+ {'edit': ('sysop', 'infinity'),
+ 'move': ('autoconfirmed', 'infinity')})

expiry = pywikibot.Timestamp.fromISOformat('2050-01-01T00:00:00Z')
site.protect(protections={'edit': 'sysop', 'move': 'autoconfirmed'},
@@ -1942,7 +1945,7 @@
def test_protect_alt(self):
"""Test the site.protect() method, works around T78522."""
site = self.get_site()
- p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+ p1 = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest')

r = site.protect(protections={'edit': 'sysop',
'move': 'autoconfirmed'},
@@ -1950,10 +1953,10 @@
reason='Pywikibot unit test')
self.assertEqual(r, None)
self.assertEqual(site.page_restrictions(page=p1),
- {u'edit': (u'sysop', u'infinity'),
- u'move': (u'autoconfirmed', u'infinity')})
+ {'edit': ('sysop', 'infinity'),
+ 'move': ('autoconfirmed', 'infinity')})

- p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+ p1 = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest')
expiry = pywikibot.Timestamp.fromISOformat('2050-01-01T00:00:00Z')
site.protect(protections={'edit': 'sysop', 'move': 'autoconfirmed'},
page=p1,
@@ -1964,7 +1967,7 @@
{'edit': ('sysop', '2050-01-01T00:00:00Z'),
'move': ('autoconfirmed', '2050-01-01T00:00:00Z')})

- p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+ p1 = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest')
site.protect(protections={'edit': '', 'move': ''},
page=p1,
reason='Pywikibot unit test')
@@ -1973,7 +1976,7 @@
def test_protect_exception(self):
"""Test that site.protect() throws an exception for invalid args."""
site = self.get_site()
- p1 = pywikibot.Page(site, u'User:Unicodesnowman/ProtectTest')
+ p1 = pywikibot.Page(site, 'User:Unicodesnowman/ProtectTest')
self.assertRaises(pywikibot.Error, site.protect,
protections={'anInvalidValue': 'sysop'},
page=p1, reason='Pywikibot unit test')
@@ -1984,7 +1987,7 @@
def test_delete(self):
"""Test the site.deletepage() and site.undelete_page() methods."""
site = self.get_site()
- p = pywikibot.Page(site, u'User:Unicodesnowman/DeleteTestSite')
+ p = pywikibot.Page(site, 'User:Unicodesnowman/DeleteTestSite')
# Verify state
if not p.exists():
site.undelete_page(p, 'pywikibot unit tests')
@@ -1993,8 +1996,8 @@
self.assertRaises(pywikibot.NoPage, p.get, force=True)

site.undelete_page(p, 'pywikibot unit tests',
- revisions=[u'2014-12-21T06:07:47Z',
- u'2014-12-21T06:07:31Z'])
+ revisions=['2014-12-21T06:07:47Z',
+ '2014-12-21T06:07:31Z'])

revs = list(p.revisions())
self.assertEqual(len(revs), 2)
@@ -2033,10 +2036,10 @@
mysite = self.site
cnt = 0
for user in mysite.users(
- ["Jimbo Wales", "Brion VIBBER", "Tim Starling"]):
+ ['Jimbo Wales', 'Brion VIBBER', 'Tim Starling']):
self.assertIsInstance(user, dict)
- self.assertTrue(user["name"]
- in ["Jimbo Wales", "Brion VIBBER", "Tim Starling"])
+ self.assertTrue(user['name']
+ in ['Jimbo Wales', 'Brion VIBBER', 'Tim Starling'])
cnt += 1
if not cnt:
raise unittest.SkipTest('Test usernames not found')
@@ -2068,13 +2071,13 @@
try:
result = list(mysite.patrol(rcid=rc['rcid']))
except api.APIError as error:
- if error.code == u'permissiondenied':
+ if error.code == 'permissiondenied':
raise unittest.SkipTest(error)
raise

- if hasattr(mysite, u'_patroldisabled') and mysite._patroldisabled:
- raise unittest.SkipTest(u'Patrolling is disabled on %s wiki.'
- % mysite)
+ if hasattr(mysite, '_patroldisabled') and mysite._patroldisabled:
+ raise unittest.SkipTest('Patrolling is disabled on {} wiki.'
+ .format(mysite))

result = result[0]
self.assertIsInstance(result, dict)
@@ -2087,7 +2090,7 @@
# no such rcid, revid or too old revid
result = list(mysite.patrol(**params))
except api.APIError as error:
- if error.code == u'badtoken':
+ if error.code == 'badtoken':
raise unittest.SkipTest(error)
except pywikibot.Error:
# expected result
@@ -2174,17 +2177,17 @@
"""Test tokens."""
if version and self._version < MediaWikiVersion(version):
raise unittest.SkipTest(
- u'Site %s version %s is too low for this tests.'
- % (self.mysite, self._version))
+ 'Site {} version {} is too low for this tests.'
+ .format(self.mysite, self._version))

if version and self._version < MediaWikiVersion(test_version):
raise unittest.SkipTest(
- u'Site %s version %s is too low for this tests.'
- % (self.mysite, self._version))
+ 'Site {} version {} is too low for this tests.'
+ .format(self.mysite, self._version))

self.mysite.version = lambda: test_version

- for ttype in ("edit", "move", additional_token):
+ for ttype in ('edit', 'move', additional_token):
tokentype = self.mysite.validate_tokens([ttype])
try:
token = self.mysite.tokens[ttype]
@@ -2251,7 +2254,7 @@
token = self.token
mysite = self.get_site()
mainpage = self.get_mainpage()
- ttype = "edit"
+ ttype = 'edit'
self.assertEqual(token, mysite.token(mainpage, ttype))
self.assertOneDeprecationParts('pywikibot.site.APISite.token',
"the 'tokens' property")
@@ -2421,7 +2424,8 @@
entered_loop(mysite.siteinfo.get(not_exists).itervalues()))
self.assertFalse(
entered_loop(mysite.siteinfo.get(not_exists).iterkeys()))
- self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).items()))
+ self.assertFalse(
+ entered_loop(mysite.siteinfo.get(not_exists).items()))
self.assertFalse(
entered_loop(mysite.siteinfo.get(not_exists).values()))
self.assertFalse(entered_loop(mysite.siteinfo.get(not_exists).keys()))
@@ -2547,7 +2551,7 @@
self.assertEqual(len(self.mainpage._revisions), 15)
revs = self.mainpage._revisions
timestamps = [str(revs[rev].timestamp) for rev in revs]
- self.assertTrue(all(ts < "2002-01-31T00:00:00Z" for ts in timestamps))
+ self.assertTrue(all(ts < '2002-01-31T00:00:00Z' for ts in timestamps))

# Retrieve oldest revisions; listing based on timestamp.
# Raises "loadrevisions: starttime > endtime with rvdir=True"
@@ -2574,29 +2578,29 @@
# Raises "loadrevisions: startid > endid with rvdir=True"
self.assertRaises(ValueError, self.mysite.loadrevisions,
self.mainpage, rvdir=True,
- startid="200000", endid="100000")
+ startid='200000', endid='100000')

# Retrieve newest revisions; listing based on revid.
# Raises "loadrevisions: endid > startid with rvdir=False
self.assertRaises(ValueError, self.mysite.loadrevisions,
self.mainpage, rvdir=False,
- startid="100000", endid="200000")
+ startid='100000', endid='200000')

def test_loadrevisions_user(self):
"""Test the site.loadrevisions() method, filtering by user."""
# Only list revisions made by this user.
self.mainpage._revisions = {}
self.mysite.loadrevisions(self.mainpage, rvdir=True,
- user="Magnus Manske")
+ user='Magnus Manske')
revs = self.mainpage._revisions
- self.assertTrue(all(revs[rev].user == "Magnus Manske" for rev in revs))
+ self.assertTrue(all(revs[rev].user == 'Magnus Manske' for rev in revs))

def test_loadrevisions_excludeuser(self):
"""Test the site.loadrevisions() method, excluding user."""
# Do not list revisions made by this user.
self.mainpage._revisions = {}
self.mysite.loadrevisions(self.mainpage, rvdir=True,
- excludeuser="Magnus Manske")
+ excludeuser='Magnus Manske')
revs = self.mainpage._revisions
self.assertFalse(any(revs[rev].user == 'Magnus Manske'
for rev in revs))
@@ -2674,15 +2678,15 @@

"""Test cases for Site methods on Commons."""

- family = "commons"
- code = "commons"
+ family = 'commons'
+ code = 'commons'

cached = True

def test_interwiki_forward(self):
"""Test interwiki forward."""
self.site = self.get_site()
- self.mainpage = pywikibot.Page(pywikibot.Link("Main Page", self.site))
+ self.mainpage = pywikibot.Page(pywikibot.Link('Main Page', self.site))
# test pagelanglinks on commons,
# which forwards interwikis to wikipedia
ll = next(self.site.pagelanglinks(self.mainpage))
@@ -3532,11 +3536,11 @@

def test_non_mw_sites(self):
"""Test NonMWAPISite for sites not using MediaWiki."""
- self._run_test("http://moinmo.in/$1")
- self._run_test("http://twiki.org/cgi-bin/view/$1")
- self._run_test("http://www.usemod.com/cgi-bin/wiki.pl?$1")
- self._run_test("https://developer.mozilla.org/en/docs/$1")
- self._run_test("http://www.tvtropes.org/pmwiki/pmwiki.php/Main/$1")
+ self._run_test('http://moinmo.in/$1')
+ self._run_test('http://twiki.org/cgi-bin/view/$1')
+ self._run_test('http://www.usemod.com/cgi-bin/wiki.pl?$1')
+ self._run_test('https://developer.mozilla.org/en/docs/$1')
+ self._run_test('http://www.tvtropes.org/pmwiki/pmwiki.php/Main/$1')

def _run_test(self, url):
"""Run test method."""
@@ -3565,8 +3569,8 @@
def test_cache_proofreadinfo_on_site_with_proofreadpage(self):
"""Test Site._cache_proofreadinfo()."""
site = self.get_site('en-ws')
- ql_res = {0: u'Without text', 1: u'Not proofread', 2: u'Problematic',
- 3: u'Proofread', 4: u'Validated'}
+ ql_res = {0: 'Without text', 1: 'Not proofread', 2: 'Problematic',
+ 3: 'Proofread', 4: 'Validated'}

site._cache_proofreadinfo()
self.assertEqual(site.namespaces[106], site.proofread_index_ns)
diff --git a/tests/sparql_tests.py b/tests/sparql_tests.py
index c3440dd..ef9a0cb 100644
--- a/tests/sparql_tests.py
+++ b/tests/sparql_tests.py
@@ -18,11 +18,11 @@

SQL_RESPONSE_CONTAINER = """
{
- "head" : {
- "vars" : [ "cat", "d", "catLabel" ]
+ 'head' : {
+ 'vars' : [ 'cat', 'd', 'catLabel' ]
},
- "results" : {
- "bindings" : [
+ 'results' : {
+ 'bindings' : [
%s
]
}
@@ -31,19 +31,19 @@

ITEM_Q498787 = """
{
- "cat" : {
- "type" : "uri",
- "value" : "http://www.wikidata.org/entity/Q498787"
+ 'cat' : {
+ 'type' : 'uri',
+ 'value' : 'http://www.wikidata.org/entity/Q498787'
},
- "d" : {
- "datatype" : "http://www.w3.org/2001/XMLSchema#dateTime",
- "type" : "literal",
- "value" : "1955-01-01T00:00:00Z"
+ 'd' : {
+ 'datatype' : 'http://www.w3.org/2001/XMLSchema#dateTime',
+ 'type' : 'literal',
+ 'value' : '1955-01-01T00:00:00Z'
},
- "catLabel" : {
- "xml:lang" : "en",
- "type" : "literal",
- "value" : "Muezza"
+ 'catLabel' : {
+ 'xml:lang' : 'en',
+ 'type' : 'literal',
+ 'value' : 'Muezza'
}
}
"""
@@ -51,33 +51,33 @@
ITEM_Q677525 = """
{
"cat" : {
- "type" : "uri",
- "value" : "http://www.wikidata.org/entity/Q677525"
+ 'type' : 'uri',
+ 'value' : 'http://www.wikidata.org/entity/Q677525'
},
- "d" : {
- "datatype" : "http://www.w3.org/2001/XMLSchema#dateTime",
- "type" : "literal",
- "value" : "2015-06-22T00:00:00Z"
+ 'd' : {
+ 'datatype' : 'http://www.w3.org/2001/XMLSchema#dateTime',
+ 'type' : 'literal',
+ 'value' : '2015-06-22T00:00:00Z'
},
- "catLabel" : {
- "xml:lang" : "en",
- "type" : "literal",
- "value" : "Orangey"
+ 'catLabel' : {
+ 'xml:lang' : 'en',
+ 'type' : 'literal',
+ 'value' : 'Orangey'
}
}
"""

RESPONSE_TRUE = """
{
- "head" : { },
- "boolean" : true
+ 'head' : { },
+ 'boolean' : true
}
"""

RESPONSE_FALSE = """
{
- "head" : { },
- "boolean" : false
+ 'head' : { },
+ 'boolean' : false
}
"""

@@ -97,51 +97,58 @@
def testQuerySelect(self, mock_method):
"""Test SELECT query."""
mock_method.return_value = Container(
- SQL_RESPONSE_CONTAINER % ("%s, %s" % (ITEM_Q498787, ITEM_Q677525)))
+ SQL_RESPONSE_CONTAINER % ('{}, {}'
+ .format(ITEM_Q498787, ITEM_Q677525)))
q = sparql.SparqlQuery()
res = q.select('SELECT * WHERE { ?x ?y ?z }')
self.assertIsInstance(res, list, 'Result is not a list')
self.assertEqual(len(res), 2)

- self.assertDictEqual(res[0],
- {'cat': 'http://www.wikidata.org/entity/Q498787',
- 'catLabel': 'Muezza', 'd': '1955-01-01T00:00:00Z'},
- 'Bad result')
- self.assertDictEqual(res[1],
- {'cat': 'http://www.wikidata.org/entity/Q677525',
- 'catLabel': 'Orangey', 'd': '2015-06-22T00:00:00Z'},
- 'Bad result')
+ self.assertDictEqual(
+ res[0], {'cat': 'http://www.wikidata.org/entity/Q498787',
+ 'catLabel': 'Muezza', 'd': '1955-01-01T00:00:00Z'},
+ 'Bad result')
+ self.assertDictEqual(
+ res[1], {'cat': 'http://www.wikidata.org/entity/Q677525',
+ 'catLabel': 'Orangey', 'd': '2015-06-22T00:00:00Z'},
+ 'Bad result')

@patch.object(sparql.http, 'fetch')
def testQuerySelectFull(self, mock_method):
"""Test SELECT query with full data."""
mock_method.return_value = Container(
- SQL_RESPONSE_CONTAINER % ("%s, %s" % (ITEM_Q498787, ITEM_Q677525)))
+ SQL_RESPONSE_CONTAINER % ('{}, {}'
+ .format(ITEM_Q498787, ITEM_Q677525)))
q = sparql.SparqlQuery()
res = q.select('SELECT * WHERE { ?x ?y ?z }', full_data=True)
self.assertIsInstance(res, list, 'Result is not a list')
self.assertEqual(len(res), 2)

self.assertIsInstance(res[0]['cat'], sparql.URI, 'Wrong type for URI')
- self.assertEqual(repr(res[0]['cat']), '<http://www.wikidata.org/entity/Q498787>',
+ self.assertEqual(repr(res[0]['cat']),
+ '<http://www.wikidata.org/entity/Q498787>',
'Wrong URI representation')
self.assertEqual(res[0]['cat'].getID(), 'Q498787', 'Wrong URI ID')

- self.assertIsInstance(res[0]['catLabel'], sparql.Literal, 'Wrong type for Literal')
- self.assertEqual(repr(res[0]['catLabel']), 'Muezza@en', 'Wrong literal representation')
+ self.assertIsInstance(res[0]['catLabel'], sparql.Literal,
+ 'Wrong type for Literal')
+ self.assertEqual(repr(res[0]['catLabel']), 'Muezza@en',
+ 'Wrong literal representation')

- self.assertIsInstance(res[0]['d'], sparql.Literal, 'Wrong type for Literal')
- self.assertEqual(repr(res[0]['d']),
- '1955-01-01T00:00:00Z^^http://www.w3.org/2001/XMLSchema#dateTime',
- 'Wrong URI representation')
+ self.assertIsInstance(res[0]['d'], sparql.Literal,
+ 'Wrong type for Literal')
+ self.assertEqual(
+ repr(res[0]['d']),
+ '1955-01-01T00:00:00Z^^http://www.w3.org/2001/XMLSchema#dateTime',
+ 'Wrong URI representation')

@patch.object(sparql.http, 'fetch')
def testGetItems(self, mock_method):
"""Test item list retrieval via SPARQL."""
mock_method.return_value = Container(
- SQL_RESPONSE_CONTAINER % ("%s, %s, %s" % (ITEM_Q498787,
- ITEM_Q677525,
- ITEM_Q677525)))
+ SQL_RESPONSE_CONTAINER % ('{}, {}, {}'.format(ITEM_Q498787,
+ ITEM_Q677525,
+ ITEM_Q677525)))
q = sparql.SparqlQuery()
res = q.get_items('SELECT * WHERE { ?x ?y ?z }', 'cat')
self.assertSetEqual(res, {'Q498787', 'Q677525'})
@@ -186,14 +193,16 @@

def test__unicode__returnsUnicodeType(self):
"""__unicode__ should return type unicode."""
- self.assertIsInstance(self.object_under_test.__unicode__(), UnicodeType)
+ self.assertIsInstance(self.object_under_test.__unicode__(),
+ UnicodeType)


class LiteralTests(Shared.SparqlNodeTests):
"""Tests for sparql.Literal."""

net = False
- object_under_test = sparql.Literal({'datatype': '', 'lang': 'en', 'value': 'value'})
+ object_under_test = sparql.Literal({'datatype': '', 'lang': 'en',
+ 'value': 'value'})


class BnodeTests(Shared.SparqlNodeTests):
@@ -207,7 +216,8 @@
"""Tests for sparql.URI."""

net = False
- object_under_test = sparql.URI({'value': 'http://foo.com'}, 'http://bar.com')
+ object_under_test = sparql.URI({'value': 'http://foo.com'},
+ 'http://bar.com')


if __name__ == '__main__': # pragma: no cover

To view, visit change 463284. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I97d24fa834e3f875a8547fc0e38f5a240f93907e
Gerrit-Change-Number: 463284
Gerrit-PatchSet: 2
Gerrit-Owner: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot (75)