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):
pywikibot-commits@lists.wikimedia.org