jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/331576 )
Change subject: Added tests for cherry_pick function of diff module ......................................................................
Added tests for cherry_pick function of diff module
Bug: T130805 Change-Id: I8fc121dc44382a6edfb9990f0442704d0f269f10 --- M tests/diff_tests.py 1 file changed, 71 insertions(+), 1 deletion(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/diff_tests.py b/tests/diff_tests.py index cbdc76d..82d1547 100644 --- a/tests/diff_tests.py +++ b/tests/diff_tests.py @@ -11,7 +11,7 @@
import sys
-from pywikibot.diff import html_comparator, PatchManager +from pywikibot.diff import cherry_pick, html_comparator, PatchManager from pywikibot.tools import PY2
from tests import join_html_data_path @@ -192,6 +192,76 @@ self.assertEqual(p.hunks[key].diff_plain_text, case[2][key])
+class TestCherryPick(TestCase): + + """Test cherry_pick method.""" + + net = False + + # texts used during testing + oldtext = 'old' + newtext = 'new' + + # output messages expected during testing + diff_message = '\x03{lightred}- old\n\x03{default}\x03{lightgreen}+ new\n\x03{default}' + none_message = '\x03{{lightpurple}}{0: ^50}\x03{{default}}'.format('None.') + header_base = '\n\x03{{lightpurple}}{0:*^50}\x03{{default}}\n' + headers = [' ALL CHANGES ', ' REVIEW CHANGES ', ' APPROVED CHANGES '] + diff_by_letter_message = ("\x03{lightred}- o\n\x03{default}" + "\x03{lightred}- l\n\x03{default}" + "\x03{lightred}- d\n\x03{default}" + "\x03{lightgreen}+ n\n\x03{default}" + "\x03{lightgreen}+ e\n\x03{default}" + "\x03{lightgreen}+ w\n\x03{default}") + + def check_headers(self, mock): + """Check if all headers were added to ouput.""" + for header in self.headers: + mock.assert_any_call(self.header_base.format(header)) + + @patch('pywikibot.output') + @patch('pywikibot.userinterfaces.terminal_interface_base.UI.input', return_value='y') + def test_accept(self, input, mock): + """Check output of cherry_pick if changes accepted.""" + self.assertEqual(cherry_pick(self.oldtext, self.newtext), self.newtext) + self.check_headers(mock) + mock.assert_any_call(self.diff_message) + + @patch('pywikibot.output') + @patch('pywikibot.userinterfaces.terminal_interface_base.UI.input', return_value='n') + def test_reject(self, input, mock): + """Check output of cherry_pick if changes rejected.""" + self.assertEqual(cherry_pick(self.oldtext, self.newtext), self.oldtext) + self.check_headers(mock) + mock.assert_any_call(self.diff_message) + mock.assert_any_call(self.none_message) + + @patch('pywikibot.output') + @patch('pywikibot.userinterfaces.terminal_interface_base.UI.input', return_value='q') + def test_quit(self, input, mock): + """Check output of cherry_pick if quitted.""" + self.assertEqual(cherry_pick(self.oldtext, self.newtext), self.oldtext) + self.check_headers(mock) + mock.assert_any_call(self.diff_message) + mock.assert_any_call(self.none_message) + + @patch('pywikibot.output') + @patch('pywikibot.userinterfaces.terminal_interface_base.UI.input', return_value='y') + def test_by_letter_accept(self, input, mock): + """Check output of cherry_pick if by_letter diff is enabled and changes accepted.""" + self.assertEqual(cherry_pick(self.oldtext, self.newtext, by_letter=True), self.newtext) + self.check_headers(mock) + mock.assert_any_call(self.diff_by_letter_message) + + @patch('pywikibot.output') + @patch('pywikibot.userinterfaces.terminal_interface_base.UI.input', return_value='q') + def test_by_letter_quit(self, input, mock): + """Check output of cherry_pick if by_letter diff is enabled and quitted during review.""" + self.assertEqual(cherry_pick(self.oldtext, self.newtext, by_letter=True), self.oldtext) + self.check_headers(mock) + mock.assert_any_call(self.diff_by_letter_message) + mock.assert_any_call(self.none_message) + if __name__ == '__main__': # pragma: no cover try: unittest.main()
pywikibot-commits@lists.wikimedia.org