Changeset 49931 in webkit


Ignore:
Timestamp:
Oct 21, 2009 11:20:26 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-10-21 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

bugzilla-tool's "patch failed to download an apply" error should give more information
https://bugs.webkit.org/show_bug.cgi?id=30632

  • Scripts/modules/scm.py:
    • Use the common run_command method instead of custom POpen code.
    • Make run_command know how to take pipes as input.
  • Scripts/modules/scm_unittest.py:
    • Add new tests to cover change.
    • Also move test_error_handlers into new SCMClassTests so we don't run it 3 times.
Location:
trunk/WebKitTools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r49930 r49931  
     12009-10-21  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        bugzilla-tool's "patch failed to download an apply" error should give more information
     6        https://bugs.webkit.org/show_bug.cgi?id=30632
     7
     8        * Scripts/modules/scm.py:
     9         - Use the common run_command method instead of custom POpen code.
     10         - Make run_command know how to take pipes as input.
     11        * Scripts/modules/scm_unittest.py:
     12         - Add new tests to cover change.
     13         - Also move test_error_handlers into new SCMClassTests so we don't run it 3 times.
     14
    1152009-10-21  Kent Tamura  <tkent@chromium.org>
    216
  • trunk/WebKitTools/Scripts/modules/scm.py

    r49707 r49931  
    125125    @staticmethod
    126126    def run_command(args, cwd=None, input=None, error_handler=default_error_handler, return_exit_code=False):
    127         stdin = subprocess.PIPE if input else None
     127        if hasattr(input, 'read'): # Check if the input is a file.
     128            stdin = input
     129            string_to_communicate = None
     130        else:
     131            stdin = subprocess.PIPE if input else None
     132            string_to_communicate = input
    128133        process = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=cwd)
    129         output = process.communicate(input)[0].rstrip()
     134        output = process.communicate(string_to_communicate)[0].rstrip()
    130135        exit_code = process.wait()
    131136        if exit_code:
     
    167172        if force:
    168173            args.append('--force')
    169         patch_apply_process = subprocess.Popen(args, stdin=curl_process.stdout)
    170 
    171         return_code = patch_apply_process.wait()
    172         if return_code:
    173             raise ScriptError(message="Patch %s from bug %s failed to download and apply." % (patch['url'], patch['bug_id']))
     174
     175        self.run_command(args, input=curl_process.stdout)
    174176
    175177    def run_status_and_extract_filenames(self, status_command, status_regexp):
  • trunk/WebKitTools/Scripts/modules/scm_unittest.py

    r49707 r49931  
    114114        run(['rm', '-rf', test_object.svn_checkout_path])
    115115
    116 
     116# For testing the SCM baseclass directly.
     117class SCMClassTests(unittest.TestCase):
     118    def setUp(self):
     119        self.dev_null = open(os.devnull, "w") # Used to make our Popen calls quiet.
     120
     121    def tearDown(self):
     122        self.dev_null.close()
     123
     124    def test_run_command_with_pipe(self):
     125        input_process = subprocess.Popen(['/bin/echo', 'foo\nbar'], stdout=subprocess.PIPE, stderr=self.dev_null)
     126        self.assertEqual(SCM.run_command(['/usr/bin/grep', 'bar'], input=input_process.stdout), "bar")
     127
     128        # Test the non-pipe case too:
     129        self.assertEqual(SCM.run_command(['/usr/bin/grep', 'bar'], input="foo\nbar"), "bar")
     130
     131        command_returns_non_zero = ['/bin/sh', '--invalid-option']
     132        # Test when the input pipe process fails.
     133        input_process = subprocess.Popen(command_returns_non_zero, stdout=subprocess.PIPE, stderr=self.dev_null)
     134        self.assertTrue(input_process.poll() != 0)
     135        self.assertRaises(ScriptError, SCM.run_command, ['/usr/bin/grep', 'bar'], input=input_process.stdout)
     136
     137        # Test when the run_command process fails.
     138        input_process = subprocess.Popen(['/bin/echo', 'foo\nbar'], stdout=subprocess.PIPE, stderr=self.dev_null) # grep shows usage and calls exit(2) when called w/o arguments.
     139        self.assertRaises(ScriptError, SCM.run_command, command_returns_non_zero, input=input_process.stdout)
     140
     141    def test_error_handlers(self):
     142        git_failure_message="Merge conflict during commit: Your file or directory 'WebCore/ChangeLog' is probably out-of-date: resource out of date; try updating at /usr/local/libexec/git-core//git-svn line 469"
     143        svn_failure_message="""svn: Commit failed (details follow):
     144svn: File or directory 'ChangeLog' is out of date; try updating
     145svn: resource out of date; try updating
     146"""
     147        command_does_not_exist = ['does_not_exist', 'invalid_option']
     148        self.assertRaises(OSError, SCM.run_command, command_does_not_exist)
     149        self.assertRaises(OSError, SCM.run_command, command_does_not_exist, error_handler=ignore_error)
     150
     151        command_returns_non_zero = ['/bin/sh', '--invalid-option']
     152        self.assertRaises(ScriptError, SCM.run_command, command_returns_non_zero)
     153        self.assertTrue(SCM.run_command(command_returns_non_zero, error_handler=ignore_error))
     154
     155        self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=git_failure_message))
     156        self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=svn_failure_message))
     157        self.assertRaises(ScriptError, commit_error_handler, ScriptError(output='blah blah blah'))
     158
     159
     160# GitTest and SVNTest inherit from this so any test_ methods here will be run once for this class and then once for each subclass.
    117161class SCMTest(unittest.TestCase):
    118162    def _create_patch(self, patch_contents):
     
    132176        os.symlink(webkit_scripts_directory, local_scripts_directory)
    133177
    134     def test_error_handlers(self):
    135         git_failure_message="Merge conflict during commit: Your file or directory 'WebCore/ChangeLog' is probably out-of-date: resource out of date; try updating at /usr/local/libexec/git-core//git-svn line 469"
    136         svn_failure_message="""svn: Commit failed (details follow):
    137 svn: File or directory 'ChangeLog' is out of date; try updating
    138 svn: resource out of date; try updating
    139 """
    140         command_does_not_exist = ['does_not_exist', 'invalid_option']
    141         self.assertRaises(OSError, SCM.run_command, command_does_not_exist)
    142         self.assertRaises(OSError, SCM.run_command, command_does_not_exist, error_handler=ignore_error)
    143 
    144         command_returns_non_zero = ['/bin/sh', '--invalid-option']
    145         self.assertRaises(ScriptError, SCM.run_command, command_returns_non_zero)
    146         self.assertTrue(SCM.run_command(command_returns_non_zero, error_handler=ignore_error))
    147 
    148         self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=git_failure_message))
    149         self.assertRaises(CheckoutNeedsUpdate, commit_error_handler, ScriptError(output=svn_failure_message))
    150         self.assertRaises(ScriptError, commit_error_handler, ScriptError(output='blah blah blah'))
    151 
    152 
    153178    # Tests which both GitTest and SVNTest should run.
    154179    # FIXME: There must be a simpler way to add these w/o adding a wrapper method to both subclasses
Note: See TracChangeset for help on using the changeset viewer.