Title: [106060] trunk/Tools
Revision
106060
Author
[email protected]
Date
2012-01-26 16:16:24 -0800 (Thu, 26 Jan 2012)

Log Message

webkitpy: re-land cleanup of test scaffolding
https://bugs.webkit.org/show_bug.cgi?id=77153

Reviewed by Eric Seidel.

This is an attempt to reland the change in bug 76973 /
r105935. My earlier attempt to manipulate PYTHONPATH
seems to only work some of the time, for reasons that
elude me. Directly adding Tools/Scripts to sys.path from
inside the test script appears to work (more?) reliably.

Also, it seemed like the files didn't actually get deleted
the last time; I don't know why.

* Scripts/test-webkitpy:
* Scripts/webkitpy/common/system/executive_unittest.py:
(command_line):
(ExecutiveTest):
(ExecutiveTest.test_run_command_args_type):
(ExecutiveTest.test_run_command_with_unicode):
(ExecutiveTest.test_running_pids):
(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.

Modified Paths

Removed Paths

Diff

Modified: trunk/Tools/ChangeLog (106059 => 106060)


--- trunk/Tools/ChangeLog	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/ChangeLog	2012-01-27 00:16:24 UTC (rev 106060)
@@ -1,3 +1,33 @@
+2012-01-26  Dirk Pranke  <[email protected]>
+
+        webkitpy: re-land cleanup of test scaffolding
+        https://bugs.webkit.org/show_bug.cgi?id=77153
+
+        Reviewed by Eric Seidel.
+
+        This is an attempt to reland the change in bug 76973 / 
+        r105935. My earlier attempt to manipulate PYTHONPATH
+        seems to only work some of the time, for reasons that
+        elude me. Directly adding Tools/Scripts to sys.path from
+        inside the test script appears to work (more?) reliably.
+
+        Also, it seemed like the files didn't actually get deleted
+        the last time; I don't know why.
+
+        * Scripts/test-webkitpy:
+        * Scripts/webkitpy/common/system/executive_unittest.py:
+        (command_line):
+        (ExecutiveTest):
+        (ExecutiveTest.test_run_command_args_type):
+        (ExecutiveTest.test_run_command_with_unicode):
+        (ExecutiveTest.test_running_pids):
+        (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-26  Ojan Vafai  <[email protected]>
 
         run-webkit-tests calls "nm" when it doesn't need to

Modified: trunk/Tools/Scripts/test-webkitpy (106059 => 106060)


--- trunk/Tools/Scripts/test-webkitpy	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/test-webkitpy	2012-01-27 00:16:24 UTC (rev 106060)
@@ -42,7 +42,7 @@
 
 
 if __name__ == "__main__":
-    webkit_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+    webkit_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
     # FIXME: We should probably test each package separately to avoid naming conflicts.
     dirs = [

Modified: trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py (106059 => 106060)


--- trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/webkitpy/common/system/executive_unittest.py	2012-01-27 00:16:24 UTC (rev 106060)
@@ -33,9 +33,14 @@
 import sys
 import unittest
 
+# Since we execute this script directly as part of the unit tests, we need to ensure
+# that Tools/Scripts is in sys.path for the next imports to work correctly.
+script_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+if script_dir not in sys.path:
+    sys.path.append(script_dir)
+
 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 +69,11 @@
     return ['yes']
 
 
+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 +110,8 @@
         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 +132,24 @@
 
         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 +215,17 @@
         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:]))

Deleted: trunk/Tools/Scripts/webkitpy/common/system/fileutils.py (106059 => 106060)


--- trunk/Tools/Scripts/webkitpy/common/system/fileutils.py	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/webkitpy/common/system/fileutils.py	2012-01-27 00:16:24 UTC (rev 106060)
@@ -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)

Deleted: trunk/Tools/Scripts/webkitpy/test/cat.py (106059 => 106060)


--- trunk/Tools/Scripts/webkitpy/test/cat.py	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/webkitpy/test/cat.py	2012-01-27 00:16:24 UTC (rev 106060)
@@ -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())

Deleted: trunk/Tools/Scripts/webkitpy/test/cat_unittest.py (106059 => 106060)


--- trunk/Tools/Scripts/webkitpy/test/cat_unittest.py	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/webkitpy/test/cat_unittest.py	2012-01-27 00:16:24 UTC (rev 106060)
@@ -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)

Deleted: trunk/Tools/Scripts/webkitpy/test/echo.py (106059 => 106060)


--- trunk/Tools/Scripts/webkitpy/test/echo.py	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/webkitpy/test/echo.py	2012-01-27 00:16:24 UTC (rev 106060)
@@ -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())

Deleted: trunk/Tools/Scripts/webkitpy/test/echo_unittest.py (106059 => 106060)


--- trunk/Tools/Scripts/webkitpy/test/echo_unittest.py	2012-01-27 00:07:11 UTC (rev 106059)
+++ trunk/Tools/Scripts/webkitpy/test/echo_unittest.py	2012-01-27 00:16:24 UTC (rev 106060)
@@ -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')
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to