Updated the Zamboni API for bug 614574 to support Spidermonkey paths in the validate.validate function

This commit is contained in:
mattbasta 2010-12-16 18:40:49 -05:00
Родитель 076e7c51c1
Коммит 72e1a2dd1b
6 изменённых файлов: 24 добавлений и 20 удалений

Просмотреть файл

@ -2,6 +2,7 @@ import json
from StringIO import StringIO
import validator.main
import validator.constants
import validator.testcases.targetapplication
from validator.errorbundler import ErrorBundle
from validator.constants import PACKAGE_ANY
@ -9,7 +10,8 @@ from validator.constants import PACKAGE_ANY
def validate(path, format="json",
approved_applications="validator/app_versions.json",
determined=True):
determined=True,
spidermonkey=None):
"Perform validation in one easy step!"
output = StringIO()
@ -20,6 +22,9 @@ def validate(path, format="json",
bundle = ErrorBundle(pipe=output, no_color=True, listed=True,
determined=determined)
if spidermonkey is not None:
bundle.save_resource("SPIDERMONKEY", spidermonkey)
validator.main.prepare_package(bundle, path, PACKAGE_ANY)
# Write the results to the pipe

Просмотреть файл

@ -30,3 +30,8 @@ if not os.path.exists(SPIDERMONKEY_INSTALLATION):
# The fallback is simply to disable JS tests.
SPIDERMONKEY_INSTALLATION = None
try:
from validator.constants_local import *
except ImportError:
pass

Просмотреть файл

@ -9,13 +9,6 @@ from validator.xpi import XPIManager
from validator.rdf import RDFParser
from validator import decorator
# This is modeled after Zamboni's settings_local.py implementation, but
# it is only designed to allow the constants to be overridden.
try:
import validator.constants_local as constants
except ImportError:
import validator.constants as constants
from constants import *
types = {0: "Unknown",

Просмотреть файл

@ -12,6 +12,11 @@ class MockBundler:
self.final_context = None
self.tier = 4
def get_resource(self, name):
"Represents a resource store"
return False
def error(self, id, title, description, file="",
line=1, column=0, context=None):
"Represents a mock error"

Просмотреть файл

@ -6,14 +6,14 @@ import subprocess
import tempfile
import validator.testcases.javascript.traverser as traverser
from validator.constants import SPIDERMONKEY_INSTALLATION
from validator.contextgenerator import ContextGenerator
import validator.submain as submain
SPIDERMONKEY = submain.constants.SPIDERMONKEY_INSTALLATION
def test_js_file(err, name, data, filename=None, line=0):
"Tests a JS file by parsing and analyzing its tokens"
if SPIDERMONKEY is None:
if SPIDERMONKEY_INSTALLATION is None and \
not err.get_resource("SPIDERMONKEY"):
return
# The filename is
@ -21,7 +21,8 @@ def test_js_file(err, name, data, filename=None, line=0):
filename = name
# Get the AST tree for the JS code
tree = _get_tree(name, data)
tree = _get_tree(name, data, err.get_resource("SPIDERMONKEY") or
SPIDERMONKEY_INSTALLATION)
if tree is None:
return None
@ -48,9 +49,6 @@ def test_js_file(err, name, data, filename=None, line=0):
def test_js_snippet(err, data, filename=None, line=0):
"Process a JS snippet by passing it through to the file tester."
if SPIDERMONKEY is None:
return
if filename is not None:
name = "%s:%d" % (filename, line)
else:
@ -96,7 +94,7 @@ def _regex_tests(err, data, filename):
context=c)
def _get_tree(name, code):
def _get_tree(name, code, shell=SPIDERMONKEY_INSTALLATION):
# TODO : It seems appropriate to cut the `name` parameter out if the
# parser is going to be installed locally.
@ -120,7 +118,7 @@ def _get_tree(name, code):
temp.write(data)
temp.flush() # This is very important
cmd = [SPIDERMONKEY, "-f", temp.name]
cmd = [shell, "-f", temp.name]
shell = subprocess.Popen(cmd,
shell=False,
stderr=subprocess.PIPE,

Просмотреть файл

@ -1,7 +1,5 @@
from validator import decorator
import validator.submain as submain
PACKAGE_DICTIONARY = submain.constants.PACKAGE_DICTIONARY
FF4_MIN = submain.constants.FF4_MIN
from validator.constants import PACKAGE_DICTIONARY, FF4_MIN
APPLICATIONS = {
"{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "firefox",