Skip to content

Commit 704559f

Browse files
committed
Merge branch 'master' of https://github.com/andreasgal/pdf.js
2 parents 63e4f02 + 0eb33ec commit 704559f

File tree

1 file changed

+54
-30
lines changed

1 file changed

+54
-30
lines changed

test/test.py

Lines changed: 54 additions & 30 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):
@@ -248,6 +251,7 @@ def makeBrowserCommand(browser):
248251
if (name and name.find(key) > -1) or path.find(key) > -1:
249252
command = types[key](browser)
250253
command.name = command.name or key
254+
break
251255

252256
if command is None:
253257
raise Exception("Unrecognized browser: %s" % browser)
@@ -294,7 +298,9 @@ def setUp(options):
294298
testBrowsers = makeBrowserCommands(options.browserManifestFile)
295299
elif options.browser:
296300
testBrowsers = [makeBrowserCommand({"path":options.browser, "name":None})]
297-
assert len(testBrowsers) > 0
301+
302+
if options.browserManifestFile or options.browser:
303+
assert len(testBrowsers) > 0
298304

299305
with open(options.manifestFile) as mf:
300306
manifestList = json.load(mf)
@@ -319,9 +325,11 @@ def startBrowsers(browsers, options):
319325
for b in browsers:
320326
b.setup()
321327
print 'Launching', b.name
328+
host = 'http://%s:%s' % (SERVER_HOST, SERVER_PORT)
329+
path = '/test/test_slave.html?'
322330
qs = 'browser='+ urllib.quote(b.name) +'&manifestFile='+ urllib.quote(options.manifestFile)
323331
qs += '&path=' + b.path
324-
b.start('http://localhost:8080/test/test_slave.html?'+ qs)
332+
b.start(host + path + qs)
325333

326334
def teardownBrowsers(browsers):
327335
for b in browsers:
@@ -438,26 +446,30 @@ def checkLoad(task, results, browser):
438446

439447
def processResults():
440448
print ''
441-
numErrors, numEqFailures, numEqNoSnapshot, numFBFFailures = State.numErrors, State.numEqFailures, State.numEqNoSnapshot, State.numFBFFailures
442-
numFatalFailures = (numErrors + numFBFFailures)
443-
if 0 == numEqFailures and 0 == numFatalFailures:
449+
numFatalFailures = (State.numErrors + State.numFBFFailures)
450+
if 0 == State.numEqFailures and 0 == numFatalFailures:
444451
print 'All tests passed.'
445452
else:
446453
print 'OHNOES! Some tests failed!'
447-
if 0 < numErrors:
448-
print ' errors:', numErrors
449-
if 0 < numEqFailures:
450-
print ' different ref/snapshot:', numEqFailures
451-
if 0 < numFBFFailures:
452-
print ' different first/second rendering:', numFBFFailures
453-
454-
if State.masterMode and (0 < numEqFailures or 0 < numEqNoSnapshot):
454+
if 0 < State.numErrors:
455+
print ' errors:', State.numErrors
456+
if 0 < State.numEqFailures:
457+
print ' different ref/snapshot:', State.numEqFailures
458+
if 0 < State.numFBFFailures:
459+
print ' different first/second rendering:', State.numFBFFailures
460+
461+
462+
def maybeUpdateRefImages(options, browser):
463+
if options.masterMode and (0 < State.numEqFailures or 0 < State.numEqNoSnapshot):
455464
print "Some eq tests failed or didn't have snapshots."
456465
print 'Checking to see if master references can be updated...'
466+
numFatalFailures = (State.numErrors + State.numFBFFailures)
457467
if 0 < numFatalFailures:
458468
print ' No. Some non-eq tests failed.'
459469
else:
460-
' Yes! The references in tmp/ can be synced with ref/.'
470+
print ' Yes! The references in tmp/ can be synced with ref/.'
471+
if options.reftest:
472+
startReftest(browser)
461473
if not prompt('Would you like to update the master copy in ref/?'):
462474
print ' OK, not updating.'
463475
else:
@@ -471,7 +483,8 @@ def processResults():
471483
print 'done'
472484

473485
def startReftest(browser):
474-
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"
475488
url += "#web=/test/eq.log"
476489
try:
477490
browser.setup()
@@ -482,20 +495,8 @@ def startReftest(browser):
482495
teardownBrowsers([browser])
483496
print "Completed reftest usage."
484497

485-
def main():
498+
def runTests(options, browsers):
486499
t1 = time.time()
487-
optionParser = TestOptions()
488-
options, args = optionParser.parse_args()
489-
options = optionParser.verifyOptions(options)
490-
if options == None:
491-
sys.exit(1)
492-
493-
httpd = TestServer(('127.0.0.1', 8080), PDFTestHandler)
494-
httpd_thread = threading.Thread(target=httpd.serve_forever)
495-
httpd_thread.setDaemon(True)
496-
httpd_thread.start()
497-
498-
browsers = setUp(options)
499500
try:
500501
startBrowsers(browsers, options)
501502
while not State.done:
@@ -506,9 +507,32 @@ def main():
506507
t2 = time.time()
507508
print "Runtime was", int(t2 - t1), "seconds"
508509

509-
if options.reftest and State.numEqFailures > 0:
510+
if options.masterMode:
511+
maybeUpdateRefImages(options, browsers[0])
512+
elif options.reftest and State.numEqFailures > 0:
510513
print "\nStarting reftest harness to examine %d eq test failures." % State.numEqFailures
511514
startReftest(browsers[0])
512515

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+
513537
if __name__ == '__main__':
514538
main()

0 commit comments

Comments
 (0)