jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/596433 )
Change subject: [bugfix] Solve IndexError when showing an empty diff with a non-zero context
......................................................................
[bugfix] Solve IndexError when showing an empty diff with a non-zero context
- Also provide a test for this case
- use subTest method for all subtests
Bug: T252724
Change-Id: I7499ae7a8f0050faeec865793841a3244b0931f5
---
M pywikibot/diff.py
M tests/diff_tests.py
2 files changed, 15 insertions(+), 2 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/diff.py b/pywikibot/diff.py
index 1bc9a20..9823d33 100644
--- a/pywikibot/diff.py
+++ b/pywikibot/diff.py
@@ -340,6 +340,10 @@
def _generate_super_hunks(self, hunks=None):
if hunks is None:
hunks = self.hunks
+
+ if not hunks:
+ return []
+
if self.context:
# Determine if two hunks are connected by self.context
super_hunk = []
diff --git a/tests/diff_tests.py b/tests/diff_tests.py
index 5d2f08d..80a982f 100644
--- a/tests/diff_tests.py
+++ b/tests/diff_tests.py
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
"""Test diff module."""
#
-# (C) Pywikibot team, 2016-2019
+# (C) Pywikibot team, 2016-2020
#
# Distributed under the terms of the MIT license.
from __future__ import absolute_import, division, unicode_literals
@@ -180,7 +180,16 @@
for case in self.cases:
p = PatchManager(case[0], case[1])
for key in case[2].keys(): # for each hunk
- self.assertEqual(p.hunks[key].diff_plain_text, case[2][key])
+ with self.subTest(case=case[0].strip(), key=key):
+ self.assertEqual(p.hunks[key].diff_plain_text,
+ case[2][key])
+
+ def test_patch_manager_no_diff(self):
+ """Test PatchManager for the same strings."""
+ for context in range(2):
+ p = PatchManager('Pywikibot', 'Pywikibot', context=context)
+ with self.subTest(context=context):
+ self.assertIsEmpty(p.hunks)
class TestCherryPick(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/596433
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7499ae7a8f0050faeec865793841a3244b0931f5
Gerrit-Change-Number: 596433
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Huji <huji.huji(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/606438 )
Change subject: [cleanup] Cleanup getFilesFromAnHash and getImagesFromAnHash
......................................................................
[cleanup] Cleanup getFilesFromAnHash and getImagesFromAnHash
- Make hash_found parameter mandatory for both methods.
As noted in _get_titles_with_hash helper function it
does not make any sense to call these methods with no
parameter. Instead of the warning a TypeError is raised.
- Remove helper function and call allimages method directly.
- Call getFilesFromAnHash from older getImagesFromAnHash.
- Throw a FutureWarning with this method that they can be
desupported and removed soon after more than 5 years of
deprecation.
Bug: T106121
Change-Id: I920e6c6f71c9d842be9496d8eeca0c3810dae966
---
M pywikibot/site/__init__.py
1 file changed, 9 insertions(+), 18 deletions(-)
Approvals:
Matěj Suchánek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 5ee61be..f7b20ab 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -6267,35 +6267,26 @@
"""Backwards-compatible interface to exturlusage()."""
return self.exturlusage(siteurl, total=limit, protocol=euprotocol)
- def _get_titles_with_hash(self, hash_found=None):
- """Helper for the deprecated method get(Files|Images)FromAnHash."""
- # This should be removed with together with get(Files|Images)FromHash
- if hash_found is None:
- # This makes absolutely NO sense.
- pywikibot.warning(
- 'The "hash_found" parameter in "getFilesFromAnHash" and '
- '"getImagesFromAnHash" are not optional.')
- return
- return [image.title(with_ns=False)
- for image in self.allimages(sha1=hash_found)]
-
- @deprecated('Site().allimages', since='20141219')
- def getFilesFromAnHash(self, hash_found=None):
+ @deprecated('Site().allimages(sha1=hash_found)', since='20141219',
+ future_warning=True)
+ def getFilesFromAnHash(self, hash_found):
"""
Return all files that have the same hash.
DEPRECATED: Use L{APISite.allimages} instead using 'sha1'.
"""
- return self._get_titles_with_hash(hash_found)
+ return [image.title(with_ns=False)
+ for image in self.allimages(sha1=hash_found)]
- @deprecated('Site().allimages', since='20141219')
- def getImagesFromAnHash(self, hash_found=None):
+ @deprecated('Site().allimages(sha1=hash_found)', since='20141219',
+ future_warning=True)
+ def getImagesFromAnHash(self, hash_found):
"""
Return all images that have the same hash.
DEPRECATED: Use L{APISite.allimages} instead using 'sha1'.
"""
- return self._get_titles_with_hash(hash_found)
+ return self.getFilesFromAnHash(hash_found)
@need_right('edit')
def is_uploaddisabled(self):
--
To view, visit https://gerrit.wikimedia.org/r/606438
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I920e6c6f71c9d842be9496d8eeca0c3810dae966
Gerrit-Change-Number: 606438
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/606830 )
Change subject: [PY3] Use PY3 identifiers in favour of PY2 in pywikibot.page
......................................................................
[PY3] Use PY3 identifiers in favour of PY2 in pywikibot.page
- Do not rename Python 3 html.entities to the corresponding
Python 2 identifier htmlentitydefs. Use the htmlentitydefs
dict directly instead
- use htmlentitydefs.get() instead of the current implementation
Change-Id: Ib1f3ceaa8767ee84e223b6e402bfde687d801c97
---
M pywikibot/page/__init__.py
1 file changed, 3 insertions(+), 7 deletions(-)
Approvals:
Dvorapa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 9085f15..acf6a99 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -57,7 +57,7 @@
from pywikibot.tools import is_IP
if not PY2:
- from html import entities as htmlentitydefs
+ from html.entities import name2codepoint
from urllib.parse import quote_from_bytes, unquote_to_bytes
else:
if __debug__ and not PY2:
@@ -65,7 +65,7 @@
chr = unichr
- import htmlentitydefs
+ from htmlentitydefs import name2codepoint
from urllib import quote as quote_from_bytes, unquote as unquote_to_bytes
@@ -6842,11 +6842,7 @@
unicode_codepoint = int(match.group('hex'), 16)
elif match.group('name'):
name = match.group('name')
- if name in htmlentitydefs.name2codepoint:
- # We found a known HTML entity.
- unicode_codepoint = htmlentitydefs.name2codepoint[name]
- else:
- unicode_codepoint = False
+ unicode_codepoint = name2codepoint.get(name, False)
unicode_codepoint = _ILLEGAL_HTML_ENTITIES_MAPPING.get(
unicode_codepoint, unicode_codepoint)
--
To view, visit https://gerrit.wikimedia.org/r/606830
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib1f3ceaa8767ee84e223b6e402bfde687d801c97
Gerrit-Change-Number: 606830
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: jenkins-bot (75)