Bug 37432

Summary: add basic mock unit tests to new-run-webkit-tests
Product: WebKit Reporter: Dirk Pranke <dpranke>
Component: Tools / TestsAssignee: Dirk Pranke <dpranke>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, cjerdonek, eric, hamaji
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Attachments:
Description Flags
Patch
abarth: review-, dpranke: commit-queue-
cleaned-up patch w/ abarth's feedback
none
revised patch - merged in changes from 37464
none
update Changelog abarth: review+

Description Dirk Pranke 2010-04-11 20:21:18 PDT
This is a CL to add some very minimal unit tests to new-run-webkit-tests. This should be enough to catch out-and-out syntax errors and so forth.
Comment 1 Dirk Pranke 2010-04-11 20:30:48 PDT
Created attachment 53142 [details]
Patch
Comment 2 Adam Barth 2010-04-11 20:50:42 PDT
Comment on attachment 53142 [details]
Patch

+def real_main(options, args, print_results=True):

This is confusing.  Python tries to trick you into having several levels of main.

+try:
+    d = os.path.dirname(__file__)
+except NameError:
+    d = os.path.dirname(sys.argv[0])
+
+sys.path.append(os.path.abspath(os.path.join(d, '../thirdparty')))

What is this?  We shouldn't be screwing around with sys.path.

+from run_webkit_tests import *

This should be:

from webkitpy.layout_test.run_webkit_tests import real_main, parse_args

Importing * make code very difficult to maintain because it imports all the imports transitively.

+if __name__ == '__main__':
+    unittest.main()

We usually skip this part.  You can run tests individually from test-webkitpy anyway.
Comment 3 Adam Barth 2010-04-11 20:53:15 PDT
Also, wil this test spawn off apache and the websocket server?  It might be a better approach to start testing from the "leaves" up instead of from main down.
Comment 4 Dirk Pranke 2010-04-12 13:12:58 PDT
(In reply to comment #3)
> Also, wil this test spawn off apache and the websocket server?  It might be a
> better approach to start testing from the "leaves" up instead of from main
> down.

No. This test suite (so far) only tests the "test" port, which contains no compiled code and stubs out all of the real work.
Comment 5 Dirk Pranke 2010-04-12 13:26:14 PDT
(In reply to comment #2)
> (From update of attachment 53142 [details])
> +def real_main(options, args, print_results=True):
> 
> This is confusing.  Python tries to trick you into having several levels of
> main.
> 

Agreed. I need to do this temporarily. I've filed bug 37464 to clean this up and am doing that in a separate CL just to make it easy to back out if I've forgotten some downstream reference to this file (I don't think there are any, but just to be sure ...)

> +try:
> +    d = os.path.dirname(__file__)
> +except NameError:
> +    d = os.path.dirname(sys.argv[0])
> +
> +sys.path.append(os.path.abspath(os.path.join(d, '../thirdparty')))
> 
> What is this?  We shouldn't be screwing around with sys.path.

Removed. It looks like y'all have cleaned up the import statements enough so that simply adding WebKitTools/Scripts to PYTHONPATH will allow me to run this file directly.

> 
> +from run_webkit_tests import *
> 
> This should be:
> 
> from webkitpy.layout_test.run_webkit_tests import real_main, parse_args
> 
> Importing * make code very difficult to maintain because it imports all the
> imports transitively.

True. I was writing this in a hurry; it's removed now.

> 
> +if __name__ == '__main__':
> +    unittest.main()
> 
> We usually skip this part.  You can run tests individually from test-webkitpy
> anyway.

You might; I don't. This is a pretty standard convention for Python test files and I'm inclined to keep it.
Comment 6 Dirk Pranke 2010-04-12 13:26:49 PDT
Created attachment 53184 [details]
cleaned-up patch w/ abarth's feedback
Comment 7 Dirk Pranke 2010-04-12 16:29:15 PDT
Created attachment 53193 [details]
revised patch - merged in changes from 37464
Comment 8 Dirk Pranke 2010-04-12 16:30:29 PDT
Created attachment 53195 [details]
update Changelog
Comment 9 Adam Barth 2010-04-14 08:19:54 PDT
Comment on attachment 53195 [details]
update Changelog

+ import run_webkit_tests

Our convention is to use absolute imports from webkitpy.  We still have a bunch of places where we need to clean this up, so it's not a big deal.  Yay tests!
Comment 10 Dirk Pranke 2010-04-14 17:16:38 PDT
(In reply to comment #9)
> (From update of attachment 53195 [details])
> + import run_webkit_tests

Quite correct. Fixed prior to landing the patch.
Comment 11 Dirk Pranke 2010-04-14 17:59:22 PDT
Committed r57622: <http://trac.webkit.org/changeset/57622>