X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=blobdiff_plain;f=WebKitTools%2FScripts%2Fmodules%2Fcommands%2Fqueries_unittest.py;h=6bae72222bc3936ac7df2d682dc9fe561a61b7a1;hp=5e8ddc175d7409ce7cb3f57c3f030b5569195ff6;hb=55624d9bc01f82f6f8d7779ddd748e9acd2e4ee8;hpb=09724fb3476e733a56a798206a9cf0e4ac12cd60 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)