jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Update coverage for tests

Change-Id: Ifaaf309ddd14d30f8ec1d8353c8f47d7a720afc1
---
M tests/site_login_logout_tests.py
M tests/proofreadpage_tests.py
M tests/time_tests.py
M tests/site_generators_tests.py
M tests/page_tests.py
M tests/paraminfo_tests.py
M tests/logentries_tests.py
M tests/eventstreams_tests.py
M tests/api_tests.py
9 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/tests/api_tests.py b/tests/api_tests.py
index 56580d4..783e1b5 100755
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -982,7 +982,7 @@
req.submit()
except SystemExit:
pass # expected exception from DummyThrottle instance
- except APIError as e:
+ except APIError as e: # pragma: no cover
pywikibot.warning(
'Wrong api lagpattern regex, cannot retrieve lag value')
raise e
diff --git a/tests/eventstreams_tests.py b/tests/eventstreams_tests.py
index 65dc347..a5762ec 100755
--- a/tests/eventstreams_tests.py
+++ b/tests/eventstreams_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Tests for the eventstreams module."""
#
-# (C) Pywikibot team, 2017-2022
+# (C) Pywikibot team, 2017-2023
#
# Distributed under the terms of the MIT license.
#
@@ -280,7 +280,7 @@
n += 1
try:
element = json.loads(event.data)
- except ValueError as e:
+ except ValueError as e: # pragma: no cover
self.source.resp.close() # close SSLSocket
del self.source
raise ValueError(
diff --git a/tests/logentries_tests.py b/tests/logentries_tests.py
index 6d21d45..1270738 100755
--- a/tests/logentries_tests.py
+++ b/tests/logentries_tests.py
@@ -88,12 +88,12 @@
self.assertIsInstance(logentry.comment(), str)
self.assertIsInstance(logentry.user(), str)
self.assertEqual(logentry.user(), logentry['user'])
- except HiddenKeyError as e:
+ except HiddenKeyError as e: # pragma: no cover
self.assertRegex(
str(e),
r"Log entry \([^)]+\) has a hidden '\w+' key and you "
r"don't have permission to view it")
- except KeyError as e:
+ except KeyError as e: # pragma: no cover
self.assertRegex(str(e), "Log entry ([^)]+) has no 'comment' key")
else:
self.assertEqual(logentry.comment(), logentry['comment'])
@@ -120,7 +120,7 @@
self.assertIsInstance(logentry.page(), pywikibot.FilePage)
else:
self.assertIsInstance(logentry.page(), pywikibot.Page)
- else:
+ else: # pragma: no cover
with self.assertRaises(KeyError):
logentry.page()

@@ -179,13 +179,13 @@
- set(LogEntryFactory._logtypes)):
if not simple_type:
# paraminfo also reports an empty string as a type
- continue
+ continue # pragma: no cover
try:
self._test_logevent(simple_type)
- except StopIteration:
+ except StopIteration: # pragma: no cover
unittest_print(
- 'Unable to test "{}" on "{}" because there are no log '
- 'entries with that type.'.format(simple_type, key))
+ f'Unable to test "{simple_type}" on "{key}" because there'
+ ' are no log entries with that type.')


class TestLogentryParams(TestLogentriesBase):
diff --git a/tests/page_tests.py b/tests/page_tests.py
index 795f437..6e92e99 100755
--- a/tests/page_tests.py
+++ b/tests/page_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Tests for the page module."""
#
-# (C) Pywikibot team, 2008-2022
+# (C) Pywikibot team, 2008-2023
#
# Distributed under the terms of the MIT license.
#
@@ -198,7 +198,7 @@
p1 = pywikibot.Page(site, 'Help:Test page#Testing')
ns_name = 'Help'
if site.namespaces[12][0] != ns_name:
- ns_name = site.namespaces[12][0]
+ ns_name = site.namespaces[12][0] # pragma: no cover
self.assertEqual(p1.title(), ns_name + ':Test page#Testing')
self.assertEqual(p1.title(underscore=True),
ns_name + ':Test_page#Testing')
@@ -232,7 +232,7 @@
p2 = pywikibot.Page(site, 'File:Jean-Léon Gérôme 003.jpg')
ns_name = 'File'
if site.namespaces[6][0] != ns_name:
- ns_name = site.namespaces[6][0]
+ ns_name = site.namespaces[6][0] # pragma: no cover
self.assertEqual(p2.title(), 'File:Jean-Léon Gérôme 003.jpg')
self.assertEqual(p2.title(underscore=True),
'File:Jean-Léon_Gérôme_003.jpg')
diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index 78a329d..13d67afd 100755
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -49,7 +49,7 @@
values = self._get_param_values(site, module, parameter)
exp = set(expected)
val = set(values)
- if not exp.issuperset(val):
+ if not exp.issuperset(val): # pragma: no cover
diff = val - exp
self.fail('Unexpected param{} {} in values'
.format('s' if len(diff) > 1 else '', diff))
diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py
index f05fc54..40a1728 100755
--- a/tests/proofreadpage_tests.py
+++ b/tests/proofreadpage_tests.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
"""Tests for the proofreadpage module."""
#
-# (C) Pywikibot team, 2015-2022
+# (C) Pywikibot team, 2015-2023
#
# Distributed under the terms of the MIT license.
#
@@ -392,11 +392,10 @@
total=1, **rvargs)
rvgen.set_maximum_items(-1) # suppress use of rvlimit parameter

- try:
+ loaded_text = ''
+ with suppress(LookupError, StopIteration, TypeError, ValueError):
pagedict = next(rvgen)
loaded_text = pagedict.get('revisions')[0].get('*')
- except (StopIteration, TypeError, KeyError, ValueError, IndexError):
- loaded_text = ''

page_text = page._page_to_json()
self.assertEqual(json.loads(page_text), json.loads(loaded_text))
diff --git a/tests/site_generators_tests.py b/tests/site_generators_tests.py
index 388d7e5..fe2572a 100755
--- a/tests/site_generators_tests.py
+++ b/tests/site_generators_tests.py
@@ -312,11 +312,10 @@
for page in mysite.allpages(maxsize=200, total=5):
self.assertIsInstance(page, pywikibot.Page)
self.assertTrue(page.exists())
- if (len(page.text.encode(mysite.encoding())) > 200
- and mysite.data_repository() == mysite):
+ if len(page.text.encode(mysite.encoding())) > 200 \
+ and mysite.data_repository() == mysite: # pragma: no cover
unittest_print(
- '{}.text is > 200 bytes while raw JSON is <= 200'
- .format(page))
+ f'{page}.text is > 200 bytes while raw JSON is <= 200')
continue
self.assertLessEqual(len(page.text.encode(mysite.encoding())), 200)

@@ -724,7 +723,8 @@
self.assertIn('editcount', user)
self.assertIn('registration', user)

- def _test_allusers_with_group(self):
+ @unittest.expectedFailure
+ 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):
@@ -800,10 +800,10 @@
imagepage = self.imagepage
for using in mysite.imageusage(imagepage, filterredir=False, total=5):
self.assertIsInstance(using, pywikibot.Page)
- if using.isRedirectPage():
+ if using.isRedirectPage(): # pragma: no cover
unittest_print(
- '{} is a redirect, although just non-redirects were '
- 'searched. See also T75120'.format(using))
+ f'{using} is a redirect, although just non-redirects were'
+ ' searched. See also T75120')
self.assertFalse(using.isRedirectPage())


@@ -827,8 +827,8 @@
entry = next(gen)
except StopIteration:
break
- except HiddenKeyError as e: # T216876
- self.skipTest(e)
+ except HiddenKeyError as e: # pragma: no cover
+ self.skipTest(e) # T216876
else:
self.assertEqual(entry.type(), logtype)

@@ -1094,13 +1094,12 @@
for hit in mysite.search('wiki', namespaces=0, total=10):
self.assertIsInstance(hit, pywikibot.Page)
self.assertEqual(hit.namespace(), 0)
- except APIError as e:
+ except APIError as e: # pragma: no cover
if e.code == 'gsrsearch-error' and 'timed out' in e.info:
- self.skipTest('gsrsearch returned timeout on site{}:\n{!r}'
- .format(mysite, e))
+ self.skipTest(
+ f'gsrsearch returned timeout on site {mysite}:\n{e!r}')
if e.code == 'gsrsearch-text-disabled':
- self.skipTest('gsrsearch is diabled on site {}:\n{!r}'
- .format(mysite, e))
+ self.skipTest(f'gsrsearch is diabled on site {mysite}:\n{e!r}')
raise

def test_search_where_title(self):
diff --git a/tests/site_login_logout_tests.py b/tests/site_login_logout_tests.py
index 5ea1cfd..5fbdc6e 100755
--- a/tests/site_login_logout_tests.py
+++ b/tests/site_login_logout_tests.py
@@ -6,7 +6,7 @@
to fail.
"""
#
-# (C) Pywikibot team, 2022
+# (C) Pywikibot team, 2022-2023
#
# Distributed under the terms of the MIT license.
#
@@ -74,7 +74,7 @@
raised = False
try:
site.login()
- except Exception as e:
+ except Exception as e: # pragma: no cover
raised = e
self.assertFalse(raised)

diff --git a/tests/time_tests.py b/tests/time_tests.py
index efa04d3..6e85f8e 100755
--- a/tests/time_tests.py
+++ b/tests/time_tests.py
@@ -130,7 +130,7 @@
sep = 'T'
t1 = Timestamp.utcnow()
if not t1.microsecond: # T199179: ensure microsecond is not 0
- t1 = t1.replace(microsecond=1)
+ t1 = t1.replace(microsecond=1) # pragma: no cover
ts1 = t1.isoformat()
t2 = Timestamp.fromISOformat(ts1)
ts2 = t2.isoformat()
@@ -170,7 +170,7 @@
"""Test conversion from and to Timestamp format."""
t1 = Timestamp.utcnow()
if not t1.microsecond: # T191827: ensure microsecond is not 0
- t1 = t1.replace(microsecond=1000)
+ t1 = t1.replace(microsecond=1000) # pragma: no cover
ts1 = t1.totimestampformat()
t2 = Timestamp.fromtimestampformat(ts1)
ts2 = t2.totimestampformat()

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

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