jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] version: Use attribute instead of key
......................................................................
[FIX] version: Use attribute instead of key
The version script prints the `__version__` attribute of requests but if the
import fails it's creating a dict which doesn't have such an attribute.
Change-Id: I9bae580e457f48daeab35fbb6941dd6928d06f28
---
M scripts/version.py
1 file changed, 7 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/version.py b/scripts/version.py
index 3debf0b..7a90fd8 100755
--- a/scripts/version.py
+++ b/scripts/version.py
@@ -21,7 +21,13 @@
try:
import requests
except ImportError:
- requests = {'__version__': 'n/a'}
+ class DummyRequests(object):
+
+ """Fake requests instance."""
+
+ __version__ = 'n/a'
+
+ requests = DummyRequests()
WMF_CACERT = 'MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs'
--
To view, visit https://gerrit.wikimedia.org/r/216932
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9bae580e457f48daeab35fbb6941dd6928d06f28
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #2357
Status: Passed
Duration: 25 minutes and 42 seconds
Commit: ead5ee0 (master)
Author: Fabian Neundorf
Message: [FIX] site tests: Wait 1 second to change siteinfo
The test basically tests that 'time' is different, but this is only happening
once every second so it's waiting a second to guarantee to get a different
siteinfo dataset.
Change-Id: Ib3d7cfe9ea815e4331a5be207c2efe5e8a33a37c
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/6022ce52b969...ead5ee07…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/66019330
--
You can configure recipients for build notifications in your .travis.yml file. See http://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] site tests: Wait 1 second to change siteinfo
......................................................................
[FIX] site tests: Wait 1 second to change siteinfo
The test basically tests that 'time' is different, but this is only happening
once every second so it's waiting a second to guarantee to get a different
siteinfo dataset.
Change-Id: Ib3d7cfe9ea815e4331a5be207c2efe5e8a33a37c
---
M tests/site_tests.py
1 file changed, 2 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/site_tests.py b/tests/site_tests.py
index d0a68a5..ba372f7 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -15,6 +15,7 @@
from collections import Iterable
from datetime import datetime
import re
+import time
import pywikibot
@@ -78,6 +79,7 @@
self.assertIn('time', old)
self.assertEqual(old, self.site.siteinfo['general'])
self.assertEqual(self.site.siteinfo('general'), old)
+ time.sleep(1)
self.assertNotEqual(self.site.siteinfo('general', force=True), old)
self.assertDeprecation('Calling siteinfo is deprecated, use itself instead.')
--
To view, visit https://gerrit.wikimedia.org/r/216929
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib3d7cfe9ea815e4331a5be207c2efe5e8a33a37c
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Remove bracket from assert statements
......................................................................
Remove bracket from assert statements
It's against pylint rules and reduces readability
Change-Id: I08df3b4075ebb2adc048d4258161da69da7514fe
---
M pywikibot/__init__.py
M pywikibot/bot.py
M pywikibot/date.py
M pywikibot/diff.py
M pywikibot/family.py
M pywikibot/page.py
M pywikibot/pagegenerators.py
M pywikibot/site.py
M pywikibot/version.py
M scripts/isbn.py
M tests/aspects.py
M tests/i18n_tests.py
M tests/proofreadpage_tests.py
M tests/ui_tests.py
M tests/utils.py
15 files changed, 54 insertions(+), 38 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
XZise: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index ea8304a..bd05c51 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -552,7 +552,9 @@
@type url: string
"""
# Either code and fam or only url
- assert(not url or (not code and not fam))
+ if url and (code or fam):
+ raise ValueError('URL to the wiki OR a pair of code and family name '
+ 'should be provided')
_logger = "wiki"
if url:
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 4d8e5c9..6455325 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -117,7 +117,8 @@
# The same context details are provided by Python 3.X, but need to
# be extracted from the warning message for Python <= 2.7.
if record.name == 'py.warnings' and 'caller_file' not in record.__dict__:
- assert(len(record.args) == 1)
+ assert len(record.args) == 1, \
+ 'Arguments for record is not correctly set'
msg = record.args[0]
if sys.version_info[0] < 3:
@@ -125,7 +126,8 @@
record.lineno = msg.partition(':')[2].partition(':')[0]
record.module = msg.rpartition('/')[2].rpartition('.')[0]
else:
- assert(msg.startswith(record.pathname + ':'))
+ assert msg.startswith(record.pathname + ':'), \
+ 'Record argument should start with path'
record.__dict__['caller_file'] = record.pathname
record.__dict__['caller_name'] = record.module
@@ -618,7 +620,8 @@
default = 'y'
elif default is not None:
default = 'n'
- assert default in ['y', 'Y', 'n', 'N', None]
+ assert default in ['y', 'Y', 'n', 'N', None], \
+ 'Default choice must be one of YyNn or default'
return input_choice(question, [('Yes', 'y'), ('No', 'n')], default,
automatic_quit=automatic_quit, force=force) == 'y'
@@ -1587,4 +1590,4 @@
pywikibot.output('\nKeyboardInterrupt during %s bot run...' %
self.__class__.__name__)
except Exception as e:
- pywikibot.exception(msg=e, tb=True)
+ pywikibot.exception(msg=e, tb=True)
diff --git a/pywikibot/date.py b/pywikibot/date.py
index 262e786..92ef02b 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -2400,7 +2400,7 @@
day = min(date.day, calendar.monthrange(year, month)[1])
new_date = date.replace(year, month, day)
if add_overlap and day != date.day:
- assert(date.day > day)
+ assert date.day > day, 'Day must not be more than length of the month'
new_date += datetime.timedelta(days=date.day - day)
return new_date
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 08f939e..7bde222 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -206,7 +206,8 @@
@property
def reviewed(self):
- assert(len(set(hunk.reviewed for hunk in self._hunks)) == 1)
+ assert len(set(hunk.reviewed for hunk in self._hunks)) == 1, \
+ 'All hunks should have the same review status'
return self._hunks[0].reviewed
@reviewed.setter
@@ -446,7 +447,8 @@
elif super_hunk.reviewed == Hunk.NOT_APPR:
status = '-'
else:
- assert(False)
+ assert False, "The super hunk's review status is " \
+ "unknown."
if super_hunk[0].a_rng[1] - super_hunk[0].a_rng[0] > 0:
mode = '-'
first = self.a[super_hunk[0].a_rng[0]]
@@ -500,7 +502,7 @@
'{0} -> {1}'.format(answer, help_msg[answer])
for answer in answers))
else:
- assert(False)
+ assert False, '%s is not a valid option' % choice
def apply(self):
"""Apply changes. If there are undecided changes, ask to review."""
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 1df55fe..f112f76 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -898,7 +898,8 @@
if fam is None:
fam = config.family
- assert(all(x in NAME_CHARACTERS for x in fam))
+ assert all(x in NAME_CHARACTERS for x in fam), \
+ 'Name of family must be ASCII character'
if fam in Family._families:
return Family._families[fam]
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 73cbd90..95b0b3f 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2561,7 +2561,8 @@
total - len(cached)]
if total and len(cached) >= total:
break # already got enough
- assert(total is None or len(cached) <= total)
+ assert total is None or len(cached) <= total, \
+ 'Number of caches is more than total number requested'
return cached
# all pages which have been checked but where created before the
@@ -2579,7 +2580,8 @@
cmtitle=self.title()):
# TODO: Upcast to suitable class
page = pywikibot.Page(self.site, member['title'])
- assert(page.namespace() == member['ns'])
+ assert page.namespace() == member['ns'], \
+ 'Namespace of the page is not consistent'
cached = check_cache(pywikibot.Timestamp.fromISOformat(
member['timestamp']))
for cached_page in cached:
@@ -2591,7 +2593,8 @@
cache[page.oldest_revision.timestamp] += [page]
else:
# clear cache
- assert(total is None or total > 0)
+ assert total is None or total > 0, \
+ 'As many items as given in total already returned'
for cached_page in check_cache(pywikibot.Timestamp.min):
yield cached_page
@@ -3221,7 +3224,7 @@
}
def _diff_to(self, type_key, key_name, value_name, diffto, data):
- assert(type_key not in data)
+ assert type_key not in data, 'Key type must be defined in data'
source = self._normalizeLanguages(getattr(self, type_key)).copy()
diffto = {} if not diffto else diffto.get(type_key, {})
new = set(source.keys())
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index dd96d21..830f2fa 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1594,7 +1594,8 @@
def DequePreloadingGenerator(generator, step=50):
"""Preload generator of type DequeGenerator."""
- assert(isinstance(generator, DequeGenerator))
+ assert isinstance(generator, DequeGenerator), \
+ 'generator must be a DequeGenerator object'
while True:
page_count = min(len(generator), step)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index d1d730f..4f0165b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -205,7 +205,8 @@
if not canonical_name:
canonical_name = self.canonical_namespaces[id]
- assert(custom_name is not None or canonical_name is not None)
+ assert custom_name is not None or canonical_name is not None, \
+ 'Namespace needs to have at least one name'
self.custom_name = custom_name if custom_name is not None else canonical_name
self.canonical_name = canonical_name if canonical_name is not None else custom_name
@@ -753,7 +754,7 @@
@rtype: list (guaranteed to be not empty)
@raise KeyError: if there is no interwiki prefix for that site.
"""
- assert(site is not None)
+ assert site is not None, 'Site must not be None'
self._cache_interwikimap()
prefixes = set([prefix
for prefix, cache_entry in self._iw_sites.items()
@@ -1446,7 +1447,7 @@
in one request.
@type all: bool
"""
- assert(self.site.user())
+ assert self.site.user(), 'User must login in this site'
self._tokens.setdefault(self.site.user(), {}).update(
self.site.get_tokens(types, all=all))
@@ -1462,7 +1463,7 @@
def __getitem__(self, key):
"""Get token value for the given key."""
- assert(self.site.user())
+ assert self.site.user(), 'User must login in this site'
user_tokens = self._tokens.setdefault(self.site.user(), {})
# always preload all for users without tokens
@@ -2198,7 +2199,8 @@
if 'case' not in nsdata:
nsdata['case'] = default_case or self.siteinfo['case']
elif default_case is not None:
- assert(default_case == nsdata['case'])
+ assert default_case == nsdata['case'], \
+ 'Default case is not consistent'
namespace = Namespace(ns, canonical_name, custom_name,
use_image_name=not is_mw114,
@@ -4283,7 +4285,7 @@
% err.code,
_logger)
raise
- assert ("edit" in result and "result" in result["edit"]), result
+ assert "edit" in result and "result" in result["edit"], result
if result["edit"]["result"] == "Success":
self.unlock_page(page)
if "nochange" in result["edit"]:
@@ -5463,7 +5465,8 @@
"""
namespaces = Namespace.resolve(namespace, self.namespaces)
# always assert that, so we are be sure that type could be 'create'
- assert('create' in self.protection_types())
+ assert 'create' in self.protection_types(), \
+ "'create' should be a valid protection type."
if type == 'create':
return self._generator(
api.PageGenerator, type_arg='protectedtitles',
@@ -5677,7 +5680,8 @@
for key in ident:
req[key].append(ident[key])
else:
- assert(p.site.has_data_repository)
+ assert p.site.has_data_repository, \
+ 'Site must have a data repository'
if (p.site == p.site.data_repository() and
p.namespace() == p.data_repository.item_namespace):
req['ids'].append(p.title(withNamespace=False))
diff --git a/pywikibot/version.py b/pywikibot/version.py
index 10c35d7..3fe51f1 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -248,12 +248,12 @@
tag, rev, date = svn_rev_info(_program_dir)
hsh, date2 = github_svn_rev2hash(tag, rev)
if date.tm_isdst >= 0 and date2.tm_isdst >= 0:
- assert(date == date2)
+ assert date == date2, 'Date of version is not consistent'
# date.tm_isdst is -1 means unknown state
# compare its contents except daylight saving time status
else:
for i in range(date.n_fields - 1):
- assert(date[i] == date2[i])
+ assert date[i] == date2[i], 'Date of version is not consistent'
rev = 's%s' % rev
if (not date or not tag or not rev) and not path:
@@ -526,7 +526,7 @@
path = path.decode(sys.getfilesystemencoding())
info['path'] = path
- assert(path not in paths)
+ assert path not in paths, 'Path of the package is in defined paths'
paths[path] = name
if '__version__' in package.__dict__:
diff --git a/scripts/isbn.py b/scripts/isbn.py
index 4040642..b5357d1 100755
--- a/scripts/isbn.py
+++ b/scripts/isbn.py
@@ -1577,7 +1577,7 @@
if old_isbn == new_isbn:
continue
# remove 'ISBN ' prefix
- assert(new_isbn.startswith('ISBN '))
+ assert new_isbn.startswith('ISBN '), 'ISBN should start with "ISBN"'
new_isbn = new_isbn[5:]
claim.setTarget(new_isbn)
change_messages.append('Changing %s (%s --> %s)' %
diff --git a/tests/aspects.py b/tests/aspects.py
index 73c89ca..44e2653 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -190,7 +190,7 @@
if isinstance(namespaces, int):
namespaces = set([namespaces])
else:
- assert(isinstance(namespaces, set))
+ assert isinstance(namespaces, set)
page_namespaces = [page.namespace() for page in gen]
@@ -532,7 +532,7 @@
super(SiteWriteMixin, cls).setUpClass()
site = cls.get_site()
- assert('test' in (site.family.name, site.code))
+ assert 'test' in (site.family.name, site.code)
if cls.write == -1:
env_var = 'PYWIKIBOT2_TEST_WRITE_FAIL'
@@ -868,7 +868,7 @@
% (name, cls.__name__))
if isinstance(cls.site, BaseSite):
- assert(cls.sites[name]['site'] == cls.site)
+ assert cls.sites[name]['site'] == cls.site
return cls.site
return cls.sites[name]['site']
@@ -1021,9 +1021,9 @@
"""
super(WikimediaDefaultSiteTestCase, cls).setUpClass()
- assert(hasattr(cls, 'site') and hasattr(cls, 'sites'))
+ assert hasattr(cls, 'site') and hasattr(cls, 'sites')
- assert(len(cls.sites) == 1)
+ assert len(cls.sites) == 1
site = cls.get_site()
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index 897e2e2..791a455 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -322,8 +322,8 @@
# co has fr as altlang but has no plural rules defined (otherwise this
# test might not catch problems) so it's using the plural variant for 0
# although French uses the plural variant for numbers > 1 (so not 0)
- assert('co' not in plural.plural_rules)
- assert(plural.plural_rules['fr']['plural'](0) is False)
+ assert 'co' not in plural.plural_rules
+ assert plural.plural_rules['fr']['plural'](0) is False
self.assertEqual(
i18n.twntranslate('co', 'test-plural', {'num': 0, 'descr': 'seulement'}),
u'Robot: Changer seulement une page.')
diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py
index e57cf52..00abb32 100644
--- a/tests/proofreadpage_tests.py
+++ b/tests/proofreadpage_tests.py
@@ -111,7 +111,7 @@
"""Test ProofreadPage page decomposing/composing text."""
page = ProofreadPage(self.site, self.valid['title'])
plain_text = pywikibot.Page(self.site, self.valid['title']).text
- assert(page.text)
+ assert page.text
self.assertEqual(plain_text, page.text)
def test_preload_from_not_existing_page(self):
diff --git a/tests/ui_tests.py b/tests/ui_tests.py
index 811dfe2..e802632 100644
--- a/tests/ui_tests.py
+++ b/tests/ui_tests.py
@@ -148,8 +148,8 @@
try:
stream = patched_streams[targetStream]
except KeyError:
- assert(isinstance(targetStream, pywikibot.userinterfaces.win32_unicode.UnicodeOutput))
- assert(targetStream._stream)
+ assert isinstance(targetStream, pywikibot.userinterfaces.win32_unicode.UnicodeOutput)
+ assert targetStream._stream
stream = patched_streams[targetStream._stream]
org_print(text, stream)
diff --git a/tests/utils.py b/tests/utils.py
index 9b44240..27c7222 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -98,7 +98,7 @@
if sys.version_info[0] > 2:
return six.add_metaclass(cls.__metaclass__)(cls)
else:
- assert(cls.__metaclass__)
+ assert cls.__metaclass__
return cls
--
To view, visit https://gerrit.wikimedia.org/r/216605
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I08df3b4075ebb2adc048d4258161da69da7514fe
Gerrit-PatchSet: 6
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>