webkitpy: clean up a bunch of test scaffolding
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jan 2012 23:46:02 +0000 (23:46 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 25 Jan 2012 23:46:02 +0000 (23:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76973

Reviewed by Eric Seidel.

There were several helper modules in the webkitpy.test package
that appear to only be used by executive_unittest.py. I am
rolling them all into that file to make that clearer.

* Scripts/webkitpy/common/system/executive_unittest.py:
(ExecutiveTest.test_run_command_args_type):
(ExecutiveTest.test_run_command_with_unicode):
(ExecutiveTest.test_running_pids):
(command_line):
(main):
* Scripts/webkitpy/common/system/fileutils.py: Removed.
* Scripts/webkitpy/test/cat.py: Removed.
* Scripts/webkitpy/test/cat_unittest.py: Removed.
* Scripts/webkitpy/test/echo.py: Removed.
* Scripts/webkitpy/test/echo_unittest.py: Removed.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/common/system/executive_unittest.py
Tools/Scripts/webkitpy/common/system/fileutils.py
Tools/Scripts/webkitpy/test/cat.py
Tools/Scripts/webkitpy/test/cat_unittest.py
Tools/Scripts/webkitpy/test/echo.py
Tools/Scripts/webkitpy/test/echo_unittest.py

index 6a9cd1c..8bd8f39 100644 (file)
@@ -1,3 +1,26 @@
+2012-01-25  Dirk Pranke  <dpranke@chromium.org>
+
+        webkitpy: clean up a bunch of test scaffolding
+        https://bugs.webkit.org/show_bug.cgi?id=76973
+
+        Reviewed by Eric Seidel.
+
+        There were several helper modules in the webkitpy.test package
+        that appear to only be used by executive_unittest.py. I am
+        rolling them all into that file to make that clearer.
+
+        * Scripts/webkitpy/common/system/executive_unittest.py:
+        (ExecutiveTest.test_run_command_args_type):
+        (ExecutiveTest.test_run_command_with_unicode):
+        (ExecutiveTest.test_running_pids):
+        (command_line):
+        (main):
+        * Scripts/webkitpy/common/system/fileutils.py: Removed.
+        * Scripts/webkitpy/test/cat.py: Removed.
+        * Scripts/webkitpy/test/cat_unittest.py: Removed.
+        * Scripts/webkitpy/test/echo.py: Removed.
+        * Scripts/webkitpy/test/echo_unittest.py: Removed.
+
 2012-01-25  Eric Seidel  <eric@webkit.org>
 
         Remove Python 2.5 support from WebKit
index a0878f9..425609d 100644 (file)
@@ -35,7 +35,6 @@ import unittest
 
 from webkitpy.common.system.executive import Executive, ScriptError
 from webkitpy.common.system.filesystem_mock import MockFileSystem
-from webkitpy.test import cat, echo
 
 
 class ScriptErrorTest(unittest.TestCase):
@@ -64,8 +63,11 @@ def never_ending_command():
     return ['yes']
 
 
-class ExecutiveTest(unittest.TestCase):
+def command_line(cmd, *args):
+    return [sys.executable, __file__, '--' + cmd] + list(args)
+
 
+class ExecutiveTest(unittest.TestCase):
     def assert_interpreter_for_content(self, intepreter, content):
         fs = MockFileSystem()
         file_path = None
@@ -102,8 +104,8 @@ class ExecutiveTest(unittest.TestCase):
         executive = Executive()
         self.assertRaises(AssertionError, executive.run_command, "echo")
         self.assertRaises(AssertionError, executive.run_command, u"echo")
-        executive.run_command(echo.command_arguments('foo'))
-        executive.run_command(tuple(echo.command_arguments('foo')))
+        executive.run_command(command_line('echo', 'foo'))
+        executive.run_command(tuple(command_line('echo', 'foo')))
 
     def test_run_command_with_unicode(self):
         """Validate that it is safe to pass unicode() objects
@@ -124,24 +126,24 @@ class ExecutiveTest(unittest.TestCase):
 
         executive = Executive()
 
-        output = executive.run_command(cat.command_arguments(), input=unicode_tor_input)
+        output = executive.run_command(command_line('cat'), input=unicode_tor_input)
         self.assertEquals(output, unicode_tor_output)
 
-        output = executive.run_command(echo.command_arguments("-n", unicode_tor_input))
+        output = executive.run_command(command_line('echo', unicode_tor_input))
         self.assertEquals(output, unicode_tor_output)
 
-        output = executive.run_command(echo.command_arguments("-n", unicode_tor_input), decode_output=False)
+        output = executive.run_command(command_line('echo', unicode_tor_input), decode_output=False)
         self.assertEquals(output, encoded_tor)
 
         # Make sure that str() input also works.
-        output = executive.run_command(cat.command_arguments(), input=encoded_tor, decode_output=False)
+        output = executive.run_command(command_line('cat'), input=encoded_tor, decode_output=False)
         self.assertEquals(output, encoded_tor)
 
         # FIXME: We should only have one run* method to test
-        output = executive.run_and_throw_if_fail(echo.command_arguments("-n", unicode_tor_input), quiet=True)
+        output = executive.run_and_throw_if_fail(command_line('echo', unicode_tor_input), quiet=True)
         self.assertEquals(output, unicode_tor_output)
 
-        output = executive.run_and_throw_if_fail(echo.command_arguments("-n", unicode_tor_input), quiet=True, decode_output=False)
+        output = executive.run_and_throw_if_fail(command_line('echo', unicode_tor_input), quiet=True, decode_output=False)
         self.assertEquals(output, encoded_tor)
 
     def test_kill_process(self):
@@ -207,3 +209,17 @@ class ExecutiveTest(unittest.TestCase):
         executive = Executive()
         pids = executive.running_pids()
         self.assertTrue(os.getpid() in pids)
+
+
+def main(platform, stdin, stdout, cmd, args):
+    if platform == 'win32' and hasattr(stdout, 'fileno'):
+        import msvcrt
+        msvcrt.setmode(stdout.fileno(), os.O_BINARY)
+    if cmd == '--cat':
+        stdout.write(stdin.read())
+    elif cmd == '--echo':
+        stdout.write(' '.join(args))
+    return 0
+
+if __name__ == '__main__' and len(sys.argv) > 1 and sys.argv[1] in ('--cat', '--echo'):
+    sys.exit(main(sys.platform, sys.stdin, sys.stdout, sys.argv[1], sys.argv[2:]))
index 55821f8..e69de29 100644 (file)
@@ -1,33 +0,0 @@
-# Copyright (C) 2010 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1.  Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer.
-# 2.  Redistributions in binary form must reproduce the above copyright
-#     notice, this list of conditions and the following disclaimer in the
-#     documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import sys
-
-
-def make_stdout_binary():
-    """Puts sys.stdout into binary mode (on platforms that have a distinction
-    between text and binary mode)."""
-    if sys.platform != 'win32' or not hasattr(sys.stdout, 'fileno'):
-        return
-    import msvcrt
-    import os
-    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
index ac56d1c..e69de29 100644 (file)
@@ -1,42 +0,0 @@
-# Copyright (C) 2010 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1.  Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer.
-# 2.  Redistributions in binary form must reproduce the above copyright
-#     notice, this list of conditions and the following disclaimer in the
-#     documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import os.path
-import sys
-
-# Add WebKitTools/Scripts to the path to ensure we can find webkitpy.
-sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
-
-from webkitpy.common.system import fileutils
-
-
-def command_arguments(*args):
-    return [sys.executable, __file__] + list(args)
-
-
-def main():
-    fileutils.make_stdout_binary()
-    sys.stdout.write(sys.stdin.read())
-    return 0
-
-if __name__ == '__main__':
-    sys.exit(main())
index 4ed1f67..e69de29 100644 (file)
@@ -1,52 +0,0 @@
-# Copyright (C) 2010 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1.  Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer.
-# 2.  Redistributions in binary form must reproduce the above copyright
-#     notice, this list of conditions and the following disclaimer in the
-#     documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import StringIO
-import os.path
-import sys
-import unittest
-
-from webkitpy.common.system import executive, outputcapture
-from webkitpy.test import cat
-
-
-class CatTest(outputcapture.OutputCaptureTestCaseBase):
-    def assert_cat(self, input):
-        saved_stdin = sys.stdin
-        sys.stdin = StringIO.StringIO(input)
-        cat.main()
-        self.assertStdout(input)
-        sys.stdin = saved_stdin
-
-    def test_basic(self):
-        self.assert_cat('foo bar baz\n')
-
-    def test_no_newline(self):
-        self.assert_cat('foo bar baz')
-
-    def test_unicode(self):
-        self.assert_cat(u'WebKit \u2661 Tor Arne Vestb\u00F8!')
-
-    def test_as_command(self):
-        input = 'foo bar baz\n'
-        output = executive.Executive().run_command(cat.command_arguments(), input=input)
-        self.assertEqual(input, output)
index 5d4d8e2..e69de29 100644 (file)
@@ -1,52 +0,0 @@
-# Copyright (C) 2010 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1.  Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer.
-# 2.  Redistributions in binary form must reproduce the above copyright
-#     notice, this list of conditions and the following disclaimer in the
-#     documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import os.path
-import sys
-
-# Add WebKitTools/Scripts to the path to ensure we can find webkitpy.
-sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
-
-from webkitpy.common.system import fileutils
-
-
-def command_arguments(*args):
-    return [sys.executable, __file__] + list(args)
-
-
-def main(args=None):
-    if args is None:
-        args = sys.argv[1:]
-
-    fileutils.make_stdout_binary()
-
-    print_newline = True
-    if len(args) and args[0] == '-n':
-        print_newline = False
-        del args[0]
-    sys.stdout.write(' '.join(args))
-    if print_newline:
-        sys.stdout.write('\n')
-    return 0
-
-if __name__ == '__main__':
-    sys.exit(main())
index bc13b5e..e69de29 100644 (file)
@@ -1,64 +0,0 @@
-# Copyright (C) 2010 Apple Inc. All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1.  Redistributions of source code must retain the above copyright
-#     notice, this list of conditions and the following disclaimer.
-# 2.  Redistributions in binary form must reproduce the above copyright
-#     notice, this list of conditions and the following disclaimer in the
-#     documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import os.path
-import sys
-import unittest
-
-from webkitpy.common.system import executive, outputcapture
-from webkitpy.test import echo
-
-
-class EchoTest(outputcapture.OutputCaptureTestCaseBase):
-    def test_basic(self):
-        echo.main(['foo', 'bar', 'baz'])
-        self.assertStdout('foo bar baz\n')
-
-    def test_no_newline(self):
-        echo.main(['-n', 'foo', 'bar', 'baz'])
-        self.assertStdout('foo bar baz')
-
-    def test_unicode(self):
-        echo.main([u'WebKit \u2661', 'Tor Arne', u'Vestb\u00F8!'])
-        self.assertStdout(u'WebKit \u2661 Tor Arne Vestb\u00F8!\n')
-
-    def test_argument_order(self):
-        echo.main(['foo', '-n', 'bar'])
-        self.assertStdout('foo -n bar\n')
-
-    def test_empty_arguments(self):
-        old_argv = sys.argv
-        sys.argv = ['echo.py', 'foo', 'bar', 'baz']
-        echo.main([])
-        self.assertStdout('\n')
-        sys.argv = old_argv
-
-    def test_no_arguments(self):
-        old_argv = sys.argv
-        sys.argv = ['echo.py', 'foo', 'bar', 'baz']
-        echo.main()
-        self.assertStdout('foo bar baz\n')
-        sys.argv = old_argv
-
-    def test_as_command(self):
-        output = executive.Executive().run_command(echo.command_arguments('foo', 'bar', 'baz'))
-        self.assertEqual(output, 'foo bar baz\n')