Changeset 51381 in webkit
- Timestamp:
- Nov 25, 2009 7:46:04 AM (14 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r51373 r51381 1 2009-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 1 12 2009-11-24 Dmitry Titov <dimich@chromium.org> 2 13 -
trunk/WebKitTools/Scripts/modules/commands/queries_unittest.py
r51362 r51381 28 28 29 29 import unittest 30 from StringIO import StringIO31 30 32 31 from modules.commands.queries import * 33 32 from modules.mock_bugzillatool import * 33 from modules.outputcapture import OutputCapture 34 34 35 35 class 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_output45 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 36 def _assert_execute_outputs(self, command, command_args, expected_stdout, expected_stderr = ""): 54 self._capture_output() 37 capture = OutputCapture() 38 capture.capture_output() 55 39 command.execute(None, command_args, MockBugzillaTool()) 56 (stdout_string, stderr_string) = self._restore_output()40 (stdout_string, stderr_string) = capture.restore_output() 57 41 self.assertEqual(stdout_string, expected_stdout) 58 42 self.assertEqual(expected_stderr, expected_stderr) -
trunk/WebKitTools/Scripts/modules/multicommandtool_unittest.py
r51283 r51381 30 30 import unittest 31 31 from multicommandtool import MultiCommandTool, Command 32 from StringIO import StringIO32 from modules.outputcapture import OutputCapture 33 33 34 34 from optparse import make_option … … 67 67 68 68 class MultiCommandToolTest(unittest.TestCase): 69 def _capture_stderr(self):70 self.saved_stderr = sys.stderr71 sys.stderr = StringIO()72 73 def _release_stderr(self):74 string = sys.stderr.getvalue()75 sys.stderr = self.saved_stderr76 self.saved_stderr = None77 return string78 79 69 def _assert_split(self, args, expected_split): 80 70 self.assertEqual(MultiCommandTool._split_args(args), expected_split) … … 104 94 tool = TrivialTool(commands=[command_with_options]) 105 95 106 self._capture_stderr() 96 capture = OutputCapture() 97 capture.capture_output() 107 98 exit_code = tool.main(["tool", "help", "trivial"]) 108 help_text = self._release_stderr()109 expected_subcommand_help = " 99 (stdout_string, stderr_string) = capture.restore_output() 100 expected_subcommand_help = "trivial [options] help text\nOptions:\n --my_option=MY_OPTION\n\n" 110 101 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) 112 104 113 105
Note: See TracChangeset
for help on using the changeset viewer.