jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Ignore some code from coverage

Also adjust some tests and update documentation.

Change-Id: Idc6dd567888069774fe7a7ec027087ad8de7bd86
---
M tests/script_tests.py
M pywikibot/families/commons_family.py
M tests/flow_tests.py
M tests/tools_chars_tests.py
M pywikibot/site/_datasite.py
M tests/textlib_tests.py
M pywikibot/site/_generators.py
M tests/paraminfo_tests.py
M tests/user_tests.py
M tests/i18n_tests.py
M pywikibot/page/_user.py
M tests/archivebot_tests.py
M tests/file_tests.py
M pywikibot/families/wikidata_family.py
14 files changed, 77 insertions(+), 43 deletions(-)

diff --git a/pywikibot/families/commons_family.py b/pywikibot/families/commons_family.py
index 41b3303..578c715 100644
--- a/pywikibot/families/commons_family.py
+++ b/pywikibot/families/commons_family.py
@@ -1,6 +1,6 @@
"""Family module for Wikimedia Commons."""
#
-# (C) Pywikibot team, 2005-2022
+# (C) Pywikibot team, 2005-2023
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/families/wikidata_family.py b/pywikibot/families/wikidata_family.py
index 9030a5c..816e147 100644
--- a/pywikibot/families/wikidata_family.py
+++ b/pywikibot/families/wikidata_family.py
@@ -1,6 +1,6 @@
"""Family module for Wikidata."""
#
-# (C) Pywikibot team, 2012-2022
+# (C) Pywikibot team, 2012-2023
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/page/_user.py b/pywikibot/page/_user.py
index 9ac8e03..c889dba 100644
--- a/pywikibot/page/_user.py
+++ b/pywikibot/page/_user.py
@@ -322,14 +322,35 @@
"""
return next(self.logevents(total=1), None)

- def contributions(self, total: int = 500, **kwargs) -> tuple:
- """
- Yield tuples describing this user edits.
+ def contributions(
+ self,
+ total: int = 500,
+ **kwargs
+ ) -> Tuple[Page, int, pywikibot.Timestamp, Optional[str]]:
+ """Yield tuples describing this user edits.

- Each tuple is composed of a pywikibot.Page object,
- the revision id (int), the edit timestamp (as a pywikibot.Timestamp
- object), and the comment (str).
- Pages returned are not guaranteed to be unique.
+ Each tuple is composed of a pywikibot.Page object, the revision
+ id, the edit timestamp and the comment. Pages returned are not
+ guaranteed to be unique.
+
+ Example:
+
+ >>> site = pywikibot.Site('wikipedia:test')
+ >>> user = pywikibot.User(site, 'pywikibot-test')
+ >>> contrib = next(user.contributions(reverse=True))
+ >>> len(contrib)
+ 4
+ >>> contrib[0].title()
+ 'User:Unicodesnowman/DeleteMark'
+ >>> contrib[1]
+ 504586
+ >>> str(contrib[2])
+ '2022-03-04T17:35:41Z'
+ >>> contrib[3]
+ 'pywikibot unit test. Do NOT actually delete.'
+
+ .. seealso:: :meth:`Site.usercontribs()
+ <pywikibot.site._generators.GeneratorsMixin.usercontribs>`

:param total: limit result to this number of pages
:keyword start: Iterate contributions starting at this Timestamp
diff --git a/pywikibot/site/_datasite.py b/pywikibot/site/_datasite.py
index ab5394e..a5601ba 100644
--- a/pywikibot/site/_datasite.py
+++ b/pywikibot/site/_datasite.py
@@ -1,6 +1,6 @@
"""Objects representing API interface to Wikibase site."""
#
-# (C) Pywikibot team, 2012-2022
+# (C) Pywikibot team, 2012-2023
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/site/_generators.py b/pywikibot/site/_generators.py
index 25f205f..99a75e7 100644
--- a/pywikibot/site/_generators.py
+++ b/pywikibot/site/_generators.py
@@ -1442,7 +1442,9 @@

Iterated values are in the same format as recentchanges.

- .. seealso:: :api:`Usercontribs`
+ .. seealso::
+ - :api:`Usercontribs`
+ - :meth:`pywikibot.User.contributions`

:param user: Iterate contributions by this user (name or IP)
:param userprefix: Iterate contributions by all users whose names
diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py
index f17f83a..198fa06 100755
--- a/tests/archivebot_tests.py
+++ b/tests/archivebot_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Tests for archivebot scripts."""
#
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2023
#
# Distributed under the terms of the MIT license.
#
@@ -311,12 +311,12 @@

try:
archivebot.PageArchiver(page, tmpl_with_ns, '')
- except Error as e:
+ except Error as e: # pragma: no cover
self.fail(f'PageArchiver() raised {e}!')

try:
archivebot.PageArchiver(page, tmpl_without_ns, '')
- except Error as e:
+ except Error as e: # pragma: no cover
self.fail(f'PageArchiver() raised {e}!')

def testLoadConfigInOtherNamespace(self):
@@ -338,7 +338,7 @@
# TEMPLATE_PAGE assumed in ns=10 if ns is not explicit.
try:
archivebot.PageArchiver(page, tmpl_with_ns, '')
- except Error as e:
+ except Error as e: # pragma: no cover
self.fail(f'PageArchiver() raised {e}!')

with self.assertRaises(archivebot.MissingConfigError):
diff --git a/tests/file_tests.py b/tests/file_tests.py
index 197cf94..4004df3 100755
--- a/tests/file_tests.py
+++ b/tests/file_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""FilePage tests."""
#
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2023
#
# Distributed under the terms of the MIT license.
#
@@ -53,9 +53,6 @@
commons = self.get_site('commons')
itwp = self.get_site('itwiki')
itwp_file = pywikibot.FilePage(itwp, title)
- for using in itwp_file.using_pages():
- self.assertIsInstance(using, pywikibot.Page)
-
commons_file = pywikibot.FilePage(commons, title)

self.assertFalse(itwp_file.exists())
@@ -67,6 +64,9 @@
self.assertTrue(commons_file.file_is_used)
self.assertTrue(commons_file.get_file_url())

+ for using in commons_file.using_pages():
+ self.assertIsInstance(using, pywikibot.Page)
+
self.assertIn('/wikipedia/commons/', itwp_file.get_file_url())
with self.assertRaisesRegex(
NoPageError,
diff --git a/tests/flow_tests.py b/tests/flow_tests.py
index 32ef3fb..f9d0896 100755
--- a/tests/flow_tests.py
+++ b/tests/flow_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Tests for the flow module."""
#
-# (C) Pywikibot team, 2015-2022
+# (C) Pywikibot team, 2015-2023
#
# Distributed under the terms of the MIT license.
#
@@ -149,7 +149,7 @@
config.step = step
for i, _ in enumerate(board.topics(total=total), start=1):
if i > total:
- break
+ break # pragma: no cover
self.assertEqual(i, total)
config.step = saved_step

diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index bf81f14..7f3de2c 100755
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Test i18n module."""
#
-# (C) Pywikibot team, 2007-2022
+# (C) Pywikibot team, 2007-2023
#
# Distributed under the terms of the MIT license.
#
@@ -27,9 +27,6 @@
self.family = self.Family()
self.family.name = family

- def __repr__(self):
- return "'{site.family.name}:{site.code}'".format(site=self)
-

class TestTranslate(TestCase):

diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index 2b6d71d..dc3ed88 100755
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Test confirming paraminfo contains expected values."""
#
-# (C) Pywikibot team, 2015-2022
+# (C) Pywikibot team, 2015-2023
#
# Distributed under the terms of the MIT license.
#
@@ -119,13 +119,12 @@
def test_content_format(self):
"""Test content format."""
base = [
+ 'application/json',
'text/x-wiki',
'text/javascript',
'text/css',
'text/plain',
]
- if self.site.mw_version >= '1.24':
- base.append('application/json')
if self.site.mw_version >= '1.36.0-wmf.2':
base.extend([
'application/octet-stream',
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 9b63c97..ac0b54a 100755
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -140,11 +140,12 @@


def collector(loader=unittest.loader.defaultTestLoader):
- """Load the default tests."""
- # Note: Raising SkipTest during load_tests will
- # cause the loader to fallback to its own
- # discover() ordering of unit tests.
- if unrunnable_script_set:
+ """Load the default tests.
+
+ .. note:: Raising SkipTest during load_tests will cause the loader
+ to fallback to its own discover() ordering of unit tests.
+ """
+ if unrunnable_script_set: # pragma: no cover
unittest_print('Skipping execution of unrunnable scripts:\n {!r}'
.format(unrunnable_script_set))

diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 86c494c..310a924 100755
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Test textlib module."""
#
-# (C) Pywikibot team, 2011-2022
+# (C) Pywikibot team, 2011-2023
#
# Distributed under the terms of the MIT license.
#
@@ -943,7 +943,9 @@
if link.title == 'World':
# This must be a bytes instance not unicode
return b'homeworlder'
- return None
+
+ # 'World' is the first link and leads to ValueError
+ return None # pragma: no cover

with self.assertRaisesRegex(ValueError,
r'The result must be str and not bytes\.'):
diff --git a/tests/tools_chars_tests.py b/tests/tools_chars_tests.py
index e80429b..58fb63f 100755
--- a/tests/tools_chars_tests.py
+++ b/tests/tools_chars_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Test tools.chars package."""
#
-# (C) Pywikibot team, 2015-2022
+# (C) Pywikibot team, 2015-2023
#
# Distributed under the terms of the MIT license.
import unicodedata
@@ -37,8 +37,8 @@
for char in chars._category_cf:
cat = unicodedata.category(char)
if cat not in ('Cf', 'Cn'):
- invalid[char] = cat
- self.assertCountEqual(invalid.items(), [])
+ invalid[char] = cat # pragma: no cover
+ self.assertIsEmpty(invalid.items())


if __name__ == '__main__': # pragma: no cover
diff --git a/tests/user_tests.py b/tests/user_tests.py
index 05570ce..54f387c 100755
--- a/tests/user_tests.py
+++ b/tests/user_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/python3
"""Tests for the User page."""
#
-# (C) Pywikibot team, 2016-2022
+# (C) Pywikibot team, 2016-2023
#
# Distributed under the terms of the MIT license.
#
@@ -74,13 +74,14 @@
pywikibot.Page(self.site,
'Benutzer Diskussion:Xqt/pwb'))
self.assertTrue(user.is_thankable)
- contribs = user.contributions(total=10)
- self.assertLength(list(contribs), 10)
+ contribs = list(user.contributions(total=10))
+ self.assertLength(contribs, 10)

for contrib in contribs:
self.assertIsInstance(contrib, tuple)
- self.assertIn('user', contrib)
- self.assertIsEqual(contrib['user'], user.username)
+ self.assertIsInstance(contrib[0], pywikibot.Page)
+ self.assertIsInstance(contrib[1], int)
+ self.assertIsInstance(contrib[2], pywikibot.Timestamp)

self.assertIn('user', user.groups())
self.assertIn('edit', user.rights())

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Idc6dd567888069774fe7a7ec027087ad8de7bd86
Gerrit-Change-Number: 875196
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged