jenkins-bot has submitted this change and it was merged.
Change subject: Add many test modules to mandatory list
......................................................................
Add many test modules to mandatory list
Fix a few docstrings where necessary to pass
mandatory rules.
Change-Id: I45e48a744accff8f1be94cb809f557b982984ffe
---
M tests/aspects.py
M tests/data_ingestion_tests.py
M tests/deletionbot_tests.py
M tests/flow_tests.py
M tests/http_tests.py
M tests/namespace_tests.py
M tests/thread_tests.py
M tests/tk_tests.py
M tests/weblib_tests.py
M tests/wikistats_tests.py
M tox.ini
11 files changed, 88 insertions(+), 6 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py
index df0a07c..4c9b8c6 100644
--- a/tests/aspects.py
+++ b/tests/aspects.py
@@ -380,6 +380,7 @@
"""Site interface to prevent sites being loaded."""
def __init__(self, code, fam=None, user=None, sysop=None):
+ """Constructor."""
raise pywikibot.SiteDefinitionError(
'Loading site %s:%s during dry test not permitted'
% (fam, code))
@@ -1021,6 +1022,12 @@
@classmethod
def override_default_site(cls, site):
+ """
+ Override the default site.
+
+ @param site: site tests should use
+ @type site: BaseSite
+ """
print('%s using %s instead of %s:%s.'
% (cls.__name__, site, cls.family, cls.code))
cls.site = site
@@ -1278,6 +1285,7 @@
@classmethod
def setUpClass(cls):
+ """Set up test class."""
if os.environ.get('PYWIKIBOT2_TEST_NO_RC', '0') == '1':
raise unittest.SkipTest('RecentChanges tests disabled.')
@@ -1293,6 +1301,7 @@
@classmethod
def setUpClass(cls):
+ """Set up test class."""
if not __debug__:
raise unittest.SkipTest(
'%s is disabled when __debug__ is disabled.' % cls.__name__)
@@ -1306,6 +1315,7 @@
_generic_match = re.compile(r'.* is deprecated(, use .* instead)?\.')
def __init__(self, *args, **kwargs):
+ """Constructor."""
super(DeprecationTestCase, self).__init__(*args, **kwargs)
self.warning_log = []
@@ -1318,15 +1328,18 @@
self.context_manager = warnings.catch_warnings(record=True)
def _reset_messages(self):
+ """Reset captured deprecation warnings."""
self._do_test_warning_filename = True
del self.warning_log[:]
@property
def deprecation_messages(self):
+ """Return captured deprecation warnings."""
messages = [str(item.message) for item in self.warning_log]
return messages
def assertDeprecation(self, msg=None):
+ """Assert that a deprecation warning happened."""
if msg is None:
self.assertGreater(sum(1 for msg in self.deprecation_messages
if self._generic_match.match(msg)), 0)
@@ -1343,20 +1356,24 @@
self._reset_messages()
def assertNoDeprecation(self, msg=None):
+ """Assert that no deprecation warning happened."""
if msg:
self.assertNotIn(msg, self.deprecation_messages)
else:
self.assertEqual([], self.deprecation_messages)
def assertDeprecationClass(self, cls):
+ """Assert that all deprecation warning are of one
class."""
self.assertTrue(all(isinstance(item.message, cls)
for item in self.warning_log))
def assertDeprecationFile(self, filename):
+ """Assert that all deprecation warning are of one
filename."""
for item in self.warning_log:
self.assertEqual(item.filename, filename)
def setUp(self):
+ """Set up unit test."""
super(DeprecationTestCase, self).setUp()
self.warning_log = self.context_manager.__enter__()
@@ -1365,6 +1382,7 @@
self._reset_messages()
def tearDown(self):
+ """Tear down unit test."""
self.context_manager.__exit__()
super(DeprecationTestCase, self).tearDown()
diff --git a/tests/data_ingestion_tests.py b/tests/data_ingestion_tests.py
index 17e96ac..a5c2ff8 100644
--- a/tests/data_ingestion_tests.py
+++ b/tests/data_ingestion_tests.py
@@ -32,6 +32,7 @@
}
def setUp(self):
+ """Set up unit test."""
super(TestPhoto, self).setUp()
self.obj = data_ingestion.Photo(
URL='http://upload.wikimedia.org/wikipedia/commons/f/fc/MP_sounds.png…png',
@@ -54,10 +55,12 @@
self.assertIn('MP sounds.png', [dup.replace("_", " ")
for dup in duplicates])
def test_getTitle(self):
+ """Test getTitle()."""
self.assertEqual(self.obj.getTitle('%(name)s - %(set)s.%(_ext)s'),
'Sound icon - Crystal SVG icon set.png')
def test_getDescription(self):
+ """Test getDescription()."""
self.assertEqual(self.obj.getDescription('CrystalTemplate'),
"""{{CrystalTemplate
|author=KDE artists {{!}} Silstor
@@ -77,6 +80,7 @@
code = 'commons'
def setUp(self):
+ """Set up unit test."""
super(TestCSVReader, self).setUp()
with open(os.path.join(_data_dir, 'csv_ingestion.csv')) as fileobj:
self.iterator = data_ingestion.CSVReader(fileobj, 'url',
@@ -84,14 +88,17 @@
self.obj = next(self.iterator)
def test_PhotoURL(self):
+ """Test PhotoURL()."""
self.assertEqual(self.obj.URL,
'http://upload.wikimedia.org/wikipedia/commons/f/fc/MP_sounds.png')
def test_getTitle(self):
+ """Test getTitle()."""
self.assertEqual(self.obj.getTitle('%(name)s - %(set)s.%(_ext)s'),
'Sound icon - Crystal SVG icon set.png')
def test_getDescription(self):
+ """Test getDescription()."""
self.assertEqual(self.obj.getDescription('CrystalTemplate'),
"""{{CrystalTemplate
|author=KDE artists {{!}} Silstor
diff --git a/tests/deletionbot_tests.py b/tests/deletionbot_tests.py
index c1050df..f4a31fd 100644
--- a/tests/deletionbot_tests.py
+++ b/tests/deletionbot_tests.py
@@ -61,6 +61,7 @@
write = True
def test_delete_mark(self):
+ """Test marking User:Unicodesnowman/DeleteMark for
deletion."""
site = self.get_site()
if site.username(sysop=True):
raise unittest.SkipTest('can\'t test mark with sysop account')
@@ -90,6 +91,7 @@
undelete_args = []
def setUp(self):
+ """Set up unit test."""
self._original_delete = pywikibot.Page.delete
self._original_undelete = pywikibot.Page.undelete
pywikibot.Page.delete = delete_dummy
@@ -97,11 +99,13 @@
super(TestDeletionBot, self).setUp()
def tearDown(self):
+ """Tear down unit test."""
pywikibot.Page.delete = self._original_delete
pywikibot.Page.undelete = self._original_undelete
super(TestDeletionBot, self).tearDown()
def test_dry(self):
+ """Test dry run of bot."""
delete.main('-page:Main Page', '-always',
'-summary:foo')
self.assertEqual(self.delete_args, ['[[Main Page]]', 'foo',
False, True])
delete.main('-page:FoooOoOooO', '-always',
'-summary:foo', '-undelete')
@@ -109,10 +113,12 @@
def delete_dummy(self, reason, prompt, mark):
+ """Dummy delete method."""
TestDeletionBot.delete_args = [self.title(asLink=True), reason, prompt, mark]
def undelete_dummy(self, reason):
+ """Dummy undelete method."""
TestDeletionBot.undelete_args = [self.title(asLink=True), reason]
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
index 2e95c48..8c4f85d 100644
--- a/tests/flow_tests.py
+++ b/tests/flow_tests.py
@@ -30,6 +30,7 @@
code = 'mediawiki'
def setUp(self):
+ """Set up unit test."""
self._page = pywikibot.flow.Board(
self.site, 'Talk:Sandbox')
super(TestBoardBasePageMethods, self).setUp()
@@ -54,6 +55,7 @@
code = 'mediawiki'
def setUp(self):
+ """Set up unit test."""
self._page = pywikibot.flow.Board(
self.site, 'Talk:Sandbox')
super(TestLoadRevisionsCaching, self).setUp()
diff --git a/tests/http_tests.py b/tests/http_tests.py
index 9ecebae..8804345 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -192,6 +192,7 @@
net = False
def test_user_agent(self):
+ """Test http.user_agent function."""
self.assertEqual('', http.user_agent(format_string=' '))
self.assertEqual('', http.user_agent(format_string=' '))
self.assertEqual('a', http.user_agent(format_string=' a '))
@@ -209,6 +210,7 @@
http.user_agent(format_string='SVN/1.7.5 {pwb}'))
def test_user_agent_username(self):
+ """Test http.user_agent_username function."""
self.assertEqual('%25', http.user_agent_username('%'))
self.assertEqual('%2525', http.user_agent_username('%25'))
self.assertEqual(';', http.user_agent_username(';'))
@@ -220,6 +222,7 @@
self.assertEqual('%E2%81%82', http.user_agent_username(u'⁂'))
def test_version(self):
+ """Test http.user_agent {version}."""
old_cache = pywikibot.version.cache
try:
pywikibot.version.cache = None
@@ -240,11 +243,13 @@
net = False
def setUp(self):
+ """Set up unit test."""
self.orig_format = config.user_agent_format
config.user_agent_format = ('{script_product} ({script_comments}) {pwb}
'
'({revision}) {http_backend} {python}')
def tearDown(self):
+ """Tear down unit test."""
config.user_agent_format = self.orig_format
def test_default_user_agent(self):
@@ -272,6 +277,7 @@
@staticmethod
def _create_request(charset=None, data=UTF8_BYTES):
+ """Helper method."""
req = threadedhttp.HttpRequest('', charset=charset)
resp = requests.Response()
resp.headers = {'content-type': 'charset=utf-8'}
@@ -345,6 +351,7 @@
@classmethod
def setUpClass(cls):
+ """Set up test class."""
super(BinaryTestCase, cls).setUpClass()
with open(os.path.join(_images_dir, 'MP_sounds.png'), 'rb') as
f:
diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py
index 1638114..f2e2373 100644
--- a/tests/namespace_tests.py
+++ b/tests/namespace_tests.py
@@ -53,7 +53,7 @@
net = False
def testNamespaceTypes(self):
- """Test cases for methods manipulating namespace
names."""
+ """Test cases for methods manipulating Namespace
names."""
ns = Namespace.builtin_namespaces(use_image_name=False)
self.assertIsInstance(ns, dict)
@@ -71,6 +71,7 @@
self.assertEqual(ns[ns[6]], ns[6])
def testNamespaceConstructor(self):
+ """Test Namespace constructor."""
kwargs = {u'case': u'first-letter'}
y = Namespace(id=6, custom_name=u'dummy',
canonical_name=u'File',
aliases=[u'Image', u'Immagine'], **kwargs)
@@ -104,6 +105,7 @@
self.assertIn(u'Immagine', y)
def testNamespaceToString(self):
+ """Test Namespace __str__ and __unicode__."""
ns = Namespace.builtin_namespaces(use_image_name=False)
self.assertEqual(str(ns[0]), ':')
@@ -125,6 +127,7 @@
self.assertEqual(y.custom_prefix(), u':ملف:')
def testNamespaceCompare(self):
+ """Test Namespace comparisons."""
a = Namespace(id=0, canonical_name=u'')
self.assertEqual(a, 0)
@@ -209,8 +212,8 @@
net = False
- def test_resolve(self):
- """Test Namespace.resolve."""
+ def test_resolve_equal(self):
+ """Test Namespace.resolve success."""
namespaces = Namespace.builtin_namespaces(use_image_name=False)
main_ns = namespaces[0]
file_ns = namespaces[6]
@@ -245,6 +248,8 @@
self.assertEqual(Namespace.resolve(':Image'), [file_ns])
self.assertEqual(Namespace.resolve(':Image:'), [file_ns])
+ def test_resolve_exceptions(self):
+ """Test Namespace.resolve failure."""
self.assertRaises(TypeError, Namespace.resolve, [True])
self.assertRaises(TypeError, Namespace.resolve, [False])
self.assertRaises(TypeError, Namespace.resolve, [None])
diff --git a/tests/thread_tests.py b/tests/thread_tests.py
index 326a606..7dfdaf6 100644
--- a/tests/thread_tests.py
+++ b/tests/thread_tests.py
@@ -20,17 +20,20 @@
net = False
def test_run_from_iterable(self):
+ """Test thread running with iterable target."""
iterable = 'abcd'
thd_gen = ThreadedGenerator(target=iterable)
thd_gen.start()
self.assertEqual(list(thd_gen), list(iterable))
def gen_func(self):
+ """Helper method for generator test."""
iterable = 'abcd'
for i in iterable:
yield i
def test_run_from_gen_function(self):
+ """Test thread running with generator as
target."""
iterable = 'abcd'
thd_gen = ThreadedGenerator(target=self.gen_func)
thd_gen.start()
@@ -42,6 +45,7 @@
"""Base class for intersect_generators test cases."""
def assertEqualItertools(self, gens):
+ """Assert intersect_generators result is same as set
intersection."""
# If they are a generator, we need to convert to a list
# first otherwise the generator is empty the second time.
datasets = [list(gen) for gen in gens]
@@ -62,9 +66,11 @@
net = False
def test_intersect_basic(self):
+ """Test basic interset without duplicates."""
self.assertEqualItertools(['abc', 'db', 'ba'])
def test_intersect_with_dups(self):
+ """Test basic interset with duplicates."""
self.assertEqualItertools(['aabc', 'dddb', 'baa'])
diff --git a/tests/tk_tests.py b/tests/tk_tests.py
index 8fc10af..e625e98 100644
--- a/tests/tk_tests.py
+++ b/tests/tk_tests.py
@@ -33,11 +33,13 @@
@classmethod
def setUpClass(cls):
+ """Set up test class."""
if os.environ.get('PYWIKIBOT2_TEST_GUI', '0') != '1':
raise unittest.SkipTest('Tkdialog tests are disabled on Travis-CI')
super(TestTkdialog, cls).setUpClass()
def testTkdialog(self):
+ """Test Tk dialog."""
try:
box = Tkdialog('foo', 'tests/data/MP_sounds.png',
'MP_sounds.png')
box.show_dialog()
@@ -53,11 +55,13 @@
@classmethod
def setUpClass(cls):
+ """Set up test class."""
if os.environ.get('PYWIKIBOT2_TEST_GUI', '0') != '1':
raise unittest.SkipTest('Tkinter tests are disabled on Travis-CI')
super(TestTkinter, cls).setUpClass()
def testTkinter(self):
+ """Test Tkinter window."""
root = Tkinter.Tk()
root.resizable(width=Tkinter.FALSE, height=Tkinter.FALSE)
root.title("pywikibot GUI")
diff --git a/tests/weblib_tests.py b/tests/weblib_tests.py
index 18fa710..7c4ae97 100644
--- a/tests/weblib_tests.py
+++ b/tests/weblib_tests.py
@@ -37,6 +37,7 @@
self.assertIn('closest', response.content)
def testInternetArchiveNewest(self):
+ """Test Internet Archive for newest
https://google.com."""
with PatchedHttp(weblib, False) as p:
p.after_fetch = self._test_response
archivedversion = weblib.getInternetArchiveURL('https://google.com')
@@ -46,6 +47,7 @@
self.assertTrue(parsed.path.strip('/').endswith('www.google.com'),
parsed.path)
def testInternetArchiveOlder(self):
+ """Test Internet Archive for
https://google.com as of June
2006."""
with PatchedHttp(weblib, False) as p:
p.after_fetch = self._test_response
archivedversion = weblib.getInternetArchiveURL('https://google.com',
'200606')
@@ -68,6 +70,7 @@
@unittest.expectedFailure
def testWebCiteOlder(self):
+ """Test WebCite for
https://google.com as of January
2013."""
archivedversion = weblib.getWebCitationURL('https://google.com',
'20130101')
self.assertEqual(archivedversion,
'http://www.webcitation.org/6DHSeh2L0')
diff --git a/tests/wikistats_tests.py b/tests/wikistats_tests.py
index 6a2dca0..6f2dff3 100644
--- a/tests/wikistats_tests.py
+++ b/tests/wikistats_tests.py
@@ -31,6 +31,7 @@
}
def test_sort(self):
+ """Test sorted results."""
ws = WikiStats()
data = ws.sorted('wikipedia', 'total')
top = data[0]
@@ -42,6 +43,7 @@
self.assertEqual(ws.languages_by_size('wikisource')[0], 'fr')
def test_csv(self):
+ """Test CSV."""
if not csv:
raise unittest.SkipTest('unicodecsv not installed.')
ws = WikiStats()
@@ -53,6 +55,7 @@
data = ws.get_dict
def test_xml(self):
+ """Test XML."""
ws = WikiStats()
data = ws.get_dict('wikisource', 'xml')
self.assertIsInstance(data, dict)
diff --git a/tox.ini b/tox.ini
index d85d20b..28b2087 100644
--- a/tox.ini
+++ b/tox.ini
@@ -111,32 +111,53 @@
scripts/watchlist.py \
setup.py \
tests/__init__.py \
+ tests/aspects.py \
tests/utils.py \
tests/archivebot_tests.py \
tests/basepage_tests.py \
- tests/category_tests.py \
+ tests/bot_tests.py \
tests/cache_tests.py \
+ tests/category_tests.py \
+ tests/checkimages_tests.py \
tests/cosmetic_changes_tests.py \
+ tests/data_ingestion_tests.py \
tests/date_tests.py \
+ tests/deletionbot_tests.py \
+ tests/disambredir_tests.py \
+ tests/djvu_tests.py \
tests/edit_tests.py \
tests/edit_failure_tests.py \
tests/exceptions_tests.py \
tests/family_tests.py \
tests/file_tests.py \
+ tests/flow_tests.py \
+ tests/http_tests.py \
tests/i18n/ \
+ tests/interwiki_graph_tests.py \
+ tests/interwiki_link_tests.py \
tests/l10n_tests.py \
tests/link_tests.py \
- tests/interwiki_graph_tests.py \
+ tests/logentry_tests.py \
+ tests/mediawikiversion_tests.py \
+ tests/namespace_tests.py \
+ tests/proofreadpage_tests.py \
+ tests/protectbot_tests.py \
tests/pwb/ \
tests/pwb_tests.py \
tests/script_tests.py \
+ tests/tests_tests.py \
tests/timestripper_tests.py \
+ tests/thread_tests.py \
+ tests/tk_tests.py \
tests/tools_chars_tests.py \
tests/tools_ip_tests.py \
tests/tools_tests.py \
tests/ui_options_tests.py \
tests/upload_tests.py \
- tests/wikidataquery_tests.py
+ tests/uploadbot_tests.py \
+ tests/weblib_tests.py \
+ tests/wikidataquery_tests.py \
+ tests/wikistats_tests.py
deps = flake8>=2.2.5
flake8-docstrings
--
To view, visit
https://gerrit.wikimedia.org/r/226699
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I45e48a744accff8f1be94cb809f557b982984ffe
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Mattflaschen <mflaschen(a)wikimedia.org>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>