Changeset 51362 in webkit


Ignore:
Timestamp:
Nov 24, 2009 3:19:28 PM (14 years ago)
Author:
eric@webkit.org
Message:

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.
Location:
trunk/WebKitTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r51357 r51362  
     12009-11-24  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        queries_unittest.py should test command output
     6        https://bugs.webkit.org/show_bug.cgi?id=31845
     7
     8        * Scripts/modules/commands/queries_unittest.py:
     9         - Capture stdout and stderr and compare with expected strings.
     10
    1112009-11-24  Simon Fraser  <simon.fraser@apple.com>
    212
  • trunk/WebKitTools/Scripts/modules/commands/queries_unittest.py

    r51278 r51362  
    2828
    2929import unittest
     30from StringIO import StringIO
    3031
    3132from modules.commands.queries import *
     
    3334
    3435class QueryCommandsTest(unittest.TestCase):
     36    def _capture_output_with_name(output_name):
     37        self.saved_outputs[output_name] = getattr(sys, output_name)
     38        setattr(sys, output_name, StringIO.StringIO())
     39
     40    def _release_output_with_name(output_name):
     41        captured_output = getattr(sys, output_name).getvalue()
     42        setattr(sys, output_name, self.saved_outputs[output_name])
     43        del self.saved_outputs[output_name]
     44        return captured_output
     45
     46    def _capture_output(self):
     47        self._capture_output_with_name("stdout")
     48        self._capture_output_with_name("stderr")
     49
     50    def _restore_output(self):
     51        return (self._release_output_with_name("stdout"), self._release_output_with_name("stderr"))
     52
     53    def _assert_execute_outputs(self, command, command_args, expected_stdout, expected_stderr = ""):
     54        self._capture_output()
     55        command.execute(None, command_args, MockBugzillaTool())
     56        (stdout_string, stderr_string) = self._restore_output()
     57        self.assertEqual(stdout_string, expected_stdout)
     58        self.assertEqual(expected_stderr, expected_stderr)
     59
    3560    def test_bugs_to_commit(self):
    36         BugsToCommit().execute(None, None, MockBugzillaTool())
     61        self._assert_execute_outputs(BugsToCommit(), None, "42\n75\n")
    3762
    3863    def test_patches_to_commit(self):
    39         PatchesToCommit().execute(None, None, MockBugzillaTool())
     64        expected_stdout = "http://example.com/197\nhttp://example.com/128\n"
     65        expected_stderr = "Patches in commit queue:\n"
     66        self._assert_execute_outputs(PatchesToCommit(), None, expected_stdout, expected_stderr)
    4067
    4168    def test_reviewed_patches(self):
    42         args = [42]
    43         ReviewedPatches().execute(None, args, MockBugzillaTool())
     69        expected_stdout = "http://example.com/197\nhttp://example.com/128\n"
     70        self._assert_execute_outputs(ReviewedPatches(), [42], expected_stdout)
    4471
    4572    def test_tree_status(self):
    46         TreeStatus().execute(None, None, MockBugzillaTool())
     73        expected_stdout = "ok   : Builder1\nok   : Builder2\n"
     74        self._assert_execute_outputs(TreeStatus(), None, expected_stdout)
Note: See TracChangeset for help on using the changeset viewer.