Changeset 51381 in webkit


Ignore:
Timestamp:
Nov 25, 2009 7:46:04 AM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-25 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Abstract out capturing stdout/stderr into a new OutputCapture class for re-use among the various unit tests.
https://bugs.webkit.org/show_bug.cgi?id=31870

  • Scripts/modules/commands/queries_unittest.py: Use the new class.
  • Scripts/modules/multicommandtool_unittest.py: Ditto.
  • Scripts/modules/outputcapture.py: Added.
Location:
trunk/WebKitTools
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r51373 r51381  
     12009-11-25  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Abstract out capturing stdout/stderr into a new OutputCapture class for re-use among the various unit tests.
     6        https://bugs.webkit.org/show_bug.cgi?id=31870
     7
     8        * Scripts/modules/commands/queries_unittest.py: Use the new class.
     9        * Scripts/modules/multicommandtool_unittest.py: Ditto.
     10        * Scripts/modules/outputcapture.py: Added.
     11
    1122009-11-24  Dmitry Titov  <dimich@chromium.org>
    213
  • trunk/WebKitTools/Scripts/modules/commands/queries_unittest.py

    r51362 r51381  
    2828
    2929import unittest
    30 from StringIO import StringIO
    3130
    3231from modules.commands.queries import *
    3332from modules.mock_bugzillatool import *
     33from modules.outputcapture import OutputCapture
    3434
    3535class 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 
    5336    def _assert_execute_outputs(self, command, command_args, expected_stdout, expected_stderr = ""):
    54         self._capture_output()
     37        capture = OutputCapture()
     38        capture.capture_output()
    5539        command.execute(None, command_args, MockBugzillaTool())
    56         (stdout_string, stderr_string) = self._restore_output()
     40        (stdout_string, stderr_string) = capture.restore_output()
    5741        self.assertEqual(stdout_string, expected_stdout)
    5842        self.assertEqual(expected_stderr, expected_stderr)
  • trunk/WebKitTools/Scripts/modules/multicommandtool_unittest.py

    r51283 r51381  
    3030import unittest
    3131from multicommandtool import MultiCommandTool, Command
    32 from StringIO import StringIO
     32from modules.outputcapture import OutputCapture
    3333
    3434from optparse import make_option
     
    6767
    6868class MultiCommandToolTest(unittest.TestCase):
    69     def _capture_stderr(self):
    70         self.saved_stderr = sys.stderr
    71         sys.stderr = StringIO()
    72 
    73     def _release_stderr(self):
    74         string = sys.stderr.getvalue()
    75         sys.stderr = self.saved_stderr
    76         self.saved_stderr = None
    77         return string
    78 
    7969    def _assert_split(self, args, expected_split):
    8070        self.assertEqual(MultiCommandTool._split_args(args), expected_split)
     
    10494        tool = TrivialTool(commands=[command_with_options])
    10595
    106         self._capture_stderr()
     96        capture = OutputCapture()
     97        capture.capture_output()
    10798        exit_code = tool.main(["tool", "help", "trivial"])
    108         help_text = self._release_stderr()
    109         expected_subcommand_help = "  trivial [options]   help text\nOptions:\n  --my_option=MY_OPTION\n\n"
     99        (stdout_string, stderr_string) = capture.restore_output()
     100        expected_subcommand_help = "trivial [options]   help text\nOptions:\n  --my_option=MY_OPTION\n\n"
    110101        self.assertEqual(exit_code, 0)
    111         self.assertEqual(help_text, expected_subcommand_help)
     102        self.assertEqual(stdout_string, "")
     103        self.assertEqual(stderr_string, expected_subcommand_help)
    112104
    113105
Note: See TracChangeset for help on using the changeset viewer.