Change test.py to use an external browser_manifest.json file, and use OptionParser to handle the command line.
This commit is contained in:
parent
100d329804
commit
8b1669d5d6
7
browser_manifest.json
Normal file
7
browser_manifest.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"name":"Firefox 5",
|
||||||
|
"path":"/Applications/Firefox.app",
|
||||||
|
"type":"firefox"
|
||||||
|
}
|
||||||
|
]
|
104
test.py
104
test.py
@ -1,18 +1,41 @@
|
|||||||
import json, os, sys, subprocess, urllib2
|
import json, platform, os, sys, subprocess, urllib, urllib2
|
||||||
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
|
||||||
|
from optparse import OptionParser
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse
|
||||||
|
|
||||||
|
USAGE_EXAMPLE = "%prog"
|
||||||
|
|
||||||
|
ANAL = True
|
||||||
|
DEFAULT_MANIFEST_FILE = 'test_manifest.json'
|
||||||
|
DEFAULT_BROWSER_MANIFEST_FILE = 'browser_manifest.json'
|
||||||
|
REFDIR = 'ref'
|
||||||
|
TMPDIR = 'tmp'
|
||||||
|
VERBOSE = False
|
||||||
|
|
||||||
|
class TestOptions(OptionParser):
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
OptionParser.__init__(self, **kwargs)
|
||||||
|
self.add_option("-m", "--masterMode", action="store_true", dest="masterMode",
|
||||||
|
help="Run the script in master mode.", default=False)
|
||||||
|
self.add_option("--manifestFile", action="store", type="string", dest="manifestFile",
|
||||||
|
help="A JSON file in the form of test_manifest.json (the default).")
|
||||||
|
self.add_option("--browserManifestFile", action="store", type="string",
|
||||||
|
dest="browserManifestFile",
|
||||||
|
help="A JSON file in the form of browser_manifest.json (the default).",
|
||||||
|
default=DEFAULT_BROWSER_MANIFEST_FILE)
|
||||||
|
self.set_usage(USAGE_EXAMPLE)
|
||||||
|
|
||||||
|
def verifyOptions(self, options):
|
||||||
|
if options.masterMode and options.manifestFile:
|
||||||
|
self.error("--masterMode and --manifestFile must not be specified at the same time.")
|
||||||
|
options.manifestFile = DEFAULT_MANIFEST_FILE
|
||||||
|
return options
|
||||||
|
|
||||||
def prompt(question):
|
def prompt(question):
|
||||||
'''Return True iff the user answered "yes" to |question|.'''
|
'''Return True iff the user answered "yes" to |question|.'''
|
||||||
inp = raw_input(question +' [yes/no] > ')
|
inp = raw_input(question +' [yes/no] > ')
|
||||||
return inp == 'yes'
|
return inp == 'yes'
|
||||||
|
|
||||||
ANAL = True
|
|
||||||
DEFAULT_MANIFEST_FILE = 'test_manifest.json'
|
|
||||||
REFDIR = 'ref'
|
|
||||||
TMPDIR = 'tmp'
|
|
||||||
VERBOSE = False
|
|
||||||
|
|
||||||
MIMEs = {
|
MIMEs = {
|
||||||
'.css': 'text/css',
|
'.css': 'text/css',
|
||||||
'.html': 'text/html',
|
'.html': 'text/html',
|
||||||
@ -100,13 +123,34 @@ class PDFTestHandler(BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
State.done = (0 == State.remaining)
|
State.done = (0 == State.remaining)
|
||||||
|
|
||||||
|
# this just does Firefox for now
|
||||||
|
class BrowserCommand():
|
||||||
|
def __init__(self, browserRecord):
|
||||||
|
print browserRecord
|
||||||
|
self.name = browserRecord["name"]
|
||||||
|
self.path = browserRecord["path"]
|
||||||
|
self.type = browserRecord["type"]
|
||||||
|
|
||||||
def setUp(manifestFile, masterMode):
|
if platform.system() == "Darwin" and self.path.endswith(".app"):
|
||||||
|
self._fixupMacPath()
|
||||||
|
|
||||||
|
if not os.path.exists(self.path):
|
||||||
|
throw("Path to browser '%s' does not exist." % self.path)
|
||||||
|
|
||||||
|
def _fixupMacPath(self):
|
||||||
|
self.path = self.path + "/Contents/MacOS/firefox-bin"
|
||||||
|
|
||||||
|
def makeBrowserCommands(browserManifestFile):
|
||||||
|
with open(browserManifestFile) as bmf:
|
||||||
|
browsers = [BrowserCommand(browser) for browser in json.load(bmf)]
|
||||||
|
return browsers
|
||||||
|
|
||||||
|
def setUp(options):
|
||||||
# Only serve files from a pdf.js clone
|
# Only serve files from a pdf.js clone
|
||||||
assert not ANAL or os.path.isfile('pdf.js') and os.path.isdir('.git')
|
assert not ANAL or os.path.isfile('pdf.js') and os.path.isdir('.git')
|
||||||
|
|
||||||
State.masterMode = masterMode
|
State.masterMode = options.masterMode
|
||||||
if masterMode and os.path.isdir(TMPDIR):
|
if options.masterMode and os.path.isdir(TMPDIR):
|
||||||
print 'Temporary snapshot dir tmp/ is still around.'
|
print 'Temporary snapshot dir tmp/ is still around.'
|
||||||
print 'tmp/ can be removed if it has nothing you need.'
|
print 'tmp/ can be removed if it has nothing you need.'
|
||||||
if prompt('SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY'):
|
if prompt('SHOULD THIS SCRIPT REMOVE tmp/? THINK CAREFULLY'):
|
||||||
@ -114,14 +158,10 @@ def setUp(manifestFile, masterMode):
|
|||||||
|
|
||||||
assert not os.path.isdir(TMPDIR)
|
assert not os.path.isdir(TMPDIR)
|
||||||
|
|
||||||
testBrowsers = [ b for b in
|
testBrowsers = makeBrowserCommands(options.browserManifestFile)
|
||||||
( 'firefox5', )
|
|
||||||
#'chrome12', 'chrome13', 'firefox4', 'firefox6','opera11' ):
|
|
||||||
if os.access(b, os.R_OK | os.X_OK) ]
|
|
||||||
|
|
||||||
mf = open(manifestFile)
|
with open(options.manifestFile) as mf:
|
||||||
manifestList = json.load(mf)
|
manifestList = json.load(mf)
|
||||||
mf.close()
|
|
||||||
|
|
||||||
for item in manifestList:
|
for item in manifestList:
|
||||||
f, isLink = item['file'], item.get('link', False)
|
f, isLink = item['file'], item.get('link', False)
|
||||||
@ -140,22 +180,26 @@ def setUp(manifestFile, masterMode):
|
|||||||
|
|
||||||
print 'done'
|
print 'done'
|
||||||
|
|
||||||
|
print testBrowsers
|
||||||
|
|
||||||
for b in testBrowsers:
|
for b in testBrowsers:
|
||||||
State.taskResults[b] = { }
|
State.taskResults[b.name] = { }
|
||||||
for item in manifestList:
|
for item in manifestList:
|
||||||
id, rounds = item['id'], int(item['rounds'])
|
id, rounds = item['id'], int(item['rounds'])
|
||||||
State.manifest[id] = item
|
State.manifest[id] = item
|
||||||
taskResults = [ ]
|
taskResults = [ ]
|
||||||
for r in xrange(rounds):
|
for r in xrange(rounds):
|
||||||
taskResults.append([ ])
|
taskResults.append([ ])
|
||||||
State.taskResults[b][id] = taskResults
|
State.taskResults[b.name][id] = taskResults
|
||||||
|
|
||||||
State.remaining = len(manifestList)
|
State.remaining = len(manifestList)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for b in testBrowsers:
|
for b in testBrowsers:
|
||||||
print 'Launching', b
|
print 'Launching', b.name
|
||||||
qs = 'browser='+ b +'&manifestFile='+ manifestFile
|
qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile)
|
||||||
subprocess.Popen(( os.path.abspath(os.path.realpath(b)),
|
subprocess.Popen(( os.path.abspath(os.path.realpath(b.path)),
|
||||||
'http://localhost:8080/test_slave.html?'+ qs))
|
'http://localhost:8080/test_slave.html?'+ qs))
|
||||||
|
|
||||||
|
|
||||||
@ -285,14 +329,14 @@ def processResults():
|
|||||||
print 'done'
|
print 'done'
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main():
|
||||||
masterMode = False
|
optionParser = TestOptions()
|
||||||
manifestFile = DEFAULT_MANIFEST_FILE
|
options, args = optionParser.parse_args()
|
||||||
if len(args) == 1:
|
options = optionParser.verifyOptions(options)
|
||||||
masterMode = (args[0] == '-m')
|
if options == None:
|
||||||
manifestFile = args[0] if not masterMode else manifestFile
|
sys.exit(1)
|
||||||
|
|
||||||
setUp(manifestFile, masterMode)
|
setUp(options)
|
||||||
|
|
||||||
server = HTTPServer(('127.0.0.1', 8080), PDFTestHandler)
|
server = HTTPServer(('127.0.0.1', 8080), PDFTestHandler)
|
||||||
while not State.done:
|
while not State.done:
|
||||||
@ -301,4 +345,4 @@ def main(args):
|
|||||||
processResults()
|
processResults()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv[1:])
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user