2009-11-24 Eric Seidel <eric@webkit.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Nov 2009 23:19:28 +0000 (23:19 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Nov 2009 23:19:28 +0000 (23:19 +0000)
        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
WebKitTools/Scripts/modules/commands/queries_unittest.py

index bd8441e6e24bd20108a625f58ea44f7a6d7efc3d..b6c17ce25728e7006c61d4e3bd0a852b7c0473a1 100644 (file)
@@ -1,3 +1,13 @@
+2009-11-24  Eric Seidel  <eric@webkit.org>
+
+        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  <simon.fraser@apple.com>
 
         No Review.
index 5e8ddc175d7409ce7cb3f57c3f030b5569195ff6..6bae72222bc3936ac7df2d682dc9fe561a61b7a1 100644 (file)
 # 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)