test-webkitpy: executive_unittest fails if PYTHONPATH isn't set
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 01:47:43 +0000 (01:47 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 01:47:43 +0000 (01:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77058

Reviewed by Eric Seidel.

r105935 broke executive_unittest by changing which script we
were running and not ensuring that the PYTHONPATH was set up
properly.

This change also fixes a regression introduced recently where
test-webkitpy wasn't figuring out the path to Tools/Scripts
right, either (so running ./test-webkitpy would fail).

* Scripts/test-webkitpy:
* Scripts/webkitpy/common/system/executive_unittest.py:
(script_dir):
(ExecutiveTest.setUp):
(ExecutiveTest):
(ExecutiveTest.tearDown):

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

Tools/ChangeLog
Tools/Scripts/test-webkitpy
Tools/Scripts/webkitpy/common/system/executive_unittest.py

index 520c74a..682c7f6 100644 (file)
@@ -1,3 +1,25 @@
+2012-01-25  Dirk Pranke  <dpranke@chromium.org>
+
+        test-webkitpy: executive_unittest fails if PYTHONPATH isn't set
+        https://bugs.webkit.org/show_bug.cgi?id=77058
+
+        Reviewed by Eric Seidel.
+
+        r105935 broke executive_unittest by changing which script we
+        were running and not ensuring that the PYTHONPATH was set up
+        properly.
+
+        This change also fixes a regression introduced recently where
+        test-webkitpy wasn't figuring out the path to Tools/Scripts
+        right, either (so running ./test-webkitpy would fail).
+
+        * Scripts/test-webkitpy:
+        * Scripts/webkitpy/common/system/executive_unittest.py:
+        (script_dir):
+        (ExecutiveTest.setUp):
+        (ExecutiveTest):
+        (ExecutiveTest.tearDown):
+
 2012-01-25  Adam Barth  <abarth@webkit.org>
 
         Disable tests on the mac-ews while we sort out hte stability issues.
index 55ad97b..4298fea 100755 (executable)
@@ -42,7 +42,7 @@ _log = logging.getLogger("test-webkitpy")
 
 
 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 = [
index 425609d..6b31e3c 100644 (file)
@@ -67,7 +67,23 @@ def command_line(cmd, *args):
     return [sys.executable, __file__, '--' + cmd] + list(args)
 
 
+def script_dir():
+    return os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+
+
 class ExecutiveTest(unittest.TestCase):
+    def setUp(self):
+        # We need this so that we can launch 'python executive_unittests.py' directly (to test
+        # actually spawning subprocesses) and have 'from webkitpy...' imports work reliably.
+        self.orig_pythonpath = os.environ.get('PYTHONPATH')
+        os.environ['PYTHONPATH'] = script_dir()
+
+    def tearDown(self):
+        if self.orig_pythonpath is not None:
+            os.environ['PYTHONPATH'] = self.orig_pythonpath
+        else:
+            del os.environ['PYTHONPATH']
+
     def assert_interpreter_for_content(self, intepreter, content):
         fs = MockFileSystem()
         file_path = None