Skip to content

Commit 0eb33ec

Browse files
committed
Merge pull request mozilla#153 from sayrer/master
Make it possible to run the server without any test browsers.
2 parents a772928 + 8031c72 commit 0eb33ec

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

test/test.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
TMPDIR = 'tmp'
1717
VERBOSE = False
1818

19+
SERVER_HOST = "localhost"
20+
SERVER_PORT = 8080
21+
1922
class TestOptions(OptionParser):
2023
def __init__(self, **kwargs):
2124
OptionParser.__init__(self, **kwargs)
@@ -41,7 +44,7 @@ def verifyOptions(self, options):
4144
if options.browser and options.browserManifestFile:
4245
print "Warning: ignoring browser argument since manifest file was also supplied"
4346
if not options.browser and not options.browserManifestFile:
44-
self.error("No test browsers found. Use --browserManifest or --browser args.")
47+
print "No browser arguments supplied, so just starting server on port %s." % SERVER_PORT
4548
return options
4649

4750
def prompt(question):
@@ -295,7 +298,9 @@ def setUp(options):
295298
testBrowsers = makeBrowserCommands(options.browserManifestFile)
296299
elif options.browser:
297300
testBrowsers = [makeBrowserCommand({"path":options.browser, "name":None})]
298-
assert len(testBrowsers) > 0
301+
302+
if options.browserManifestFile or options.browser:
303+
assert len(testBrowsers) > 0
299304

300305
with open(options.manifestFile) as mf:
301306
manifestList = json.load(mf)
@@ -320,9 +325,11 @@ def startBrowsers(browsers, options):
320325
for b in browsers:
321326
b.setup()
322327
print 'Launching', b.name
328+
host = 'http://%s:%s' % (SERVER_HOST, SERVER_PORT)
329+
path = '/test/test_slave.html?'
323330
qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile)
324331
qs += '&path=' + b.path
325-
b.start('http://localhost:8080/test/test_slave.html?'+ qs)
332+
b.start(host + path + qs)
326333

327334
def teardownBrowsers(browsers):
328335
for b in browsers:
@@ -476,7 +483,8 @@ def maybeUpdateRefImages(options, browser):
476483
print 'done'
477484

478485
def startReftest(browser):
479-
url = "http://127.0.0.1:8080/test/resources/reftest-analyzer.xhtml"
486+
url = "http://%s:%s" % (SERVER_HOST, SERVER_PORT)
487+
url += "/test/resources/reftest-analyzer.xhtml"
480488
url += "#web=/test/eq.log"
481489
try:
482490
browser.setup()
@@ -487,20 +495,8 @@ def startReftest(browser):
487495
teardownBrowsers([browser])
488496
print "Completed reftest usage."
489497

490-
def main():
498+
def runTests(options, browsers):
491499
t1 = time.time()
492-
optionParser = TestOptions()
493-
options, args = optionParser.parse_args()
494-
options = optionParser.verifyOptions(options)
495-
if options == None:
496-
sys.exit(1)
497-
498-
httpd = TestServer(('127.0.0.1', 8080), PDFTestHandler)
499-
httpd_thread = threading.Thread(target=httpd.serve_forever)
500-
httpd_thread.setDaemon(True)
501-
httpd_thread.start()
502-
503-
browsers = setUp(options)
504500
try:
505501
startBrowsers(browsers, options)
506502
while not State.done:
@@ -517,5 +513,26 @@ def main():
517513
print "\nStarting reftest harness to examine %d eq test failures." % State.numEqFailures
518514
startReftest(browsers[0])
519515

516+
def main():
517+
optionParser = TestOptions()
518+
options, args = optionParser.parse_args()
519+
options = optionParser.verifyOptions(options)
520+
if options == None:
521+
sys.exit(1)
522+
523+
httpd = TestServer((SERVER_HOST, SERVER_PORT), PDFTestHandler)
524+
httpd_thread = threading.Thread(target=httpd.serve_forever)
525+
httpd_thread.setDaemon(True)
526+
httpd_thread.start()
527+
528+
browsers = setUp(options)
529+
if len(browsers) > 0:
530+
runTests(options, browsers)
531+
else:
532+
# just run the server
533+
print "Running HTTP server. Press Ctrl-C to quit."
534+
while True:
535+
time.sleep(1)
536+
520537
if __name__ == '__main__':
521538
main()

0 commit comments

Comments
 (0)