Sn1per has uploaded a new change for review. https://gerrit.wikimedia.org/r/324724
Change subject: Basic PatchManager unit tests ...................................................................... Basic PatchManager unit tests Tests to make sure it generates proper diff output. Bug: T130805 Change-Id: Ic85d8f41583ad1c64ab1316e92528c6773db15cd --- M tests/diff_tests.py 1 file changed, 50 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/24/324724/1 diff --git a/tests/diff_tests.py b/tests/diff_tests.py index a96921d..23deee8 100644 --- a/tests/diff_tests.py +++ b/tests/diff_tests.py @@ -11,7 +11,7 @@ import sys -from pywikibot.diff import html_comparator +from pywikibot.diff import html_comparator, PatchManager from pywikibot.tools import PY2 from tests import join_html_data_path @@ -97,7 +97,7 @@ side_effect=ImportError, autospec=True) class TestNoBeautifulSoup(TestCase): - """Test functions when BeautifulSoup is not installes.""" + """Test functions when BeautifulSoup is not installed.""" net = False @@ -108,6 +108,54 @@ self.assertIn('bs4', mocked_import.call_args[0]) +class TestPatchManager(TestCase): + + """Test PatchManager class with given strings as test cases.""" + + net = False + + def test_patch_manager(self): + # each tuple: before, after, expected hunks + cases = [('.foola.Pywikipediabot', + '.foo.Pywikipediabot.foo.', + {0: '@@ -1 +1 @@\n\n' + '- .foola.Pywikipediabot\n' + '? --\n' + '+ .foo.Pywikipediabot.foo.\n' + '? +++++\n'}), + ('{foola}Pywikipediabot', + '{foo}Pywikipediabot{foo}', + {0: '@@ -1 +1 @@\n\n' + '- {foola}Pywikipediabot\n' + '? --\n' + '+ {foo}Pywikipediabot{foo}\n' + '? +++++\n'}), + ('{default}Foo bar Pywikipediabot foo bar', + '{default}Foo bar Pywikipediabot foo bar', + {0: '@@ -1 +1 @@\n\n' + '- {default}Foo bar Pywikipediabot foo bar\n' + '+ {default}Foo bar Pywikipediabot foo bar\n' + '? + + + +\n'}), + ('Pywikipediabot foo', + 'Pywikipediabot foo', + {0: '@@ -1 +1 @@\n\n' + '- Pywikipediabot foo\n' + '+ Pywikipediabot foo\n' + '? +\n'}), + (' Pywikipediabot ', + ' Pywikipediabot ', + {0: '@@ -1 +1 @@\n\n' + '- Pywikipediabot \n' + '? -\n' + '+ Pywikipediabot \n' + '? +\n'})] + + for case in cases: + p = PatchManager(case[0], case[1]) + for num, hunk in enumerate(p.hunks): + self.assertEqual(hunk.diff_plain_text, case[2][num]) + + if __name__ == '__main__': # pragma: no cover try: unittest.main() -- To view, visit https://gerrit.wikimedia.org/r/324724 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic85d8f41583ad1c64ab1316e92528c6773db15cd Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Sn1per <geof...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits