From 55624d9bc01f82f6f8d7779ddd748e9acd2e4ee8 Mon Sep 17 00:00:00 2001 From: "eric@webkit.org" Date: Tue, 24 Nov 2009 23:19:28 +0000 Subject: [PATCH] 2009-11-24 Eric Seidel Reviewed by Adam Barth. queries_unittest.py should test command output https://bugs.webkit.org/show_bug.cgi?id=31845 * Scripts/modules/commands/queries_unittest.py: - Capture stdout and stderr and compare with expected strings. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51362 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebKitTools/ChangeLog | 10 +++++ .../modules/commands/queries_unittest.py | 38 ++++++++++++++++--- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog index bd8441e6e24b..b6c17ce25728 100644 --- a/WebKitTools/ChangeLog +++ b/WebKitTools/ChangeLog @@ -1,3 +1,13 @@ +2009-11-24 Eric Seidel + + Reviewed by Adam Barth. + + queries_unittest.py should test command output + https://bugs.webkit.org/show_bug.cgi?id=31845 + + * Scripts/modules/commands/queries_unittest.py: + - Capture stdout and stderr and compare with expected strings. + 2009-11-24 Simon Fraser No Review. diff --git a/WebKitTools/Scripts/modules/commands/queries_unittest.py b/WebKitTools/Scripts/modules/commands/queries_unittest.py index 5e8ddc175d74..6bae72222bc3 100644 --- a/WebKitTools/Scripts/modules/commands/queries_unittest.py +++ b/WebKitTools/Scripts/modules/commands/queries_unittest.py @@ -27,20 +27,48 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import unittest +from StringIO import StringIO from modules.commands.queries import * from modules.mock_bugzillatool import * class QueryCommandsTest(unittest.TestCase): + def _capture_output_with_name(output_name): + self.saved_outputs[output_name] = getattr(sys, output_name) + setattr(sys, output_name, StringIO.StringIO()) + + def _release_output_with_name(output_name): + captured_output = getattr(sys, output_name).getvalue() + setattr(sys, output_name, self.saved_outputs[output_name]) + del self.saved_outputs[output_name] + return captured_output + + def _capture_output(self): + self._capture_output_with_name("stdout") + self._capture_output_with_name("stderr") + + def _restore_output(self): + return (self._release_output_with_name("stdout"), self._release_output_with_name("stderr")) + + def _assert_execute_outputs(self, command, command_args, expected_stdout, expected_stderr = ""): + self._capture_output() + command.execute(None, command_args, MockBugzillaTool()) + (stdout_string, stderr_string) = self._restore_output() + self.assertEqual(stdout_string, expected_stdout) + self.assertEqual(expected_stderr, expected_stderr) + def test_bugs_to_commit(self): - BugsToCommit().execute(None, None, MockBugzillaTool()) + self._assert_execute_outputs(BugsToCommit(), None, "42\n75\n") def test_patches_to_commit(self): - PatchesToCommit().execute(None, None, MockBugzillaTool()) + expected_stdout = "http://example.com/197\nhttp://example.com/128\n" + expected_stderr = "Patches in commit queue:\n" + self._assert_execute_outputs(PatchesToCommit(), None, expected_stdout, expected_stderr) def test_reviewed_patches(self): - args = [42] - ReviewedPatches().execute(None, args, MockBugzillaTool()) + expected_stdout = "http://example.com/197\nhttp://example.com/128\n" + self._assert_execute_outputs(ReviewedPatches(), [42], expected_stdout) def test_tree_status(self): - TreeStatus().execute(None, None, MockBugzillaTool()) + expected_stdout = "ok : Builder1\nok : Builder2\n" + self._assert_execute_outputs(TreeStatus(), None, expected_stdout) -- 2.36.0