Streamlined submain for packaged webapps
This commit is contained in:
Родитель
cd934ef16f
Коммит
f34a99ebbe
39
README.rst
39
README.rst
|
@ -140,30 +140,6 @@ sample document below.
|
|||
"notices": 1,
|
||||
"success": false,
|
||||
"ending_tier": 4,
|
||||
"message_tree": {
|
||||
"module": {
|
||||
"function": {
|
||||
"error": {
|
||||
"__messages": ["123456789"],
|
||||
"__errors": 1,
|
||||
"__warnings": 0,
|
||||
"__notices": 0
|
||||
},
|
||||
"__messages": [],
|
||||
"__errors": 1,
|
||||
"__warnings": 0,
|
||||
"__notices": 0
|
||||
},
|
||||
"__messages": [],
|
||||
"__errors": 1,
|
||||
"__warnings": 0,
|
||||
"__notices": 0
|
||||
},
|
||||
"__messages": [],
|
||||
"__errors": 1,
|
||||
"__warnings": 0,
|
||||
"__notices": 0
|
||||
},
|
||||
"messages": [
|
||||
{
|
||||
"uid": "123456789",
|
||||
|
@ -186,21 +162,6 @@ sample document below.
|
|||
}
|
||||
|
||||
|
||||
The ``message_tree`` element to the document above contains a series of
|
||||
JavaScript objects organized into a tree structure. The key of each element in
|
||||
the tree is the the name of each successive part of the validator that
|
||||
generated a particular message or set of messages (increasing in specificity as
|
||||
the depth of the tree increases). Each tree element also includes a series of
|
||||
additional nodes which provide extra information:
|
||||
|
||||
::
|
||||
|
||||
__errors - number - The number of errors generated in this node
|
||||
__warnings - number - The number of warnings generated in this node
|
||||
__notices - number - The number of messages generated in this node
|
||||
__messages - list - A list of UIDs from messages in the `messages` node
|
||||
|
||||
|
||||
JSON Notes:
|
||||
-----------
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ class ErrorBundle(object):
|
|||
self.warnings = []
|
||||
self.notices = []
|
||||
self.message_count = 0
|
||||
self.message_tree = {}
|
||||
|
||||
self.ending_tier = 1
|
||||
self.tier = 1
|
||||
|
@ -142,23 +141,6 @@ class ErrorBundle(object):
|
|||
if message["tier"] is None:
|
||||
message["tier"] = self.tier
|
||||
|
||||
# Build out the message tree entry.
|
||||
if message["id"]:
|
||||
tree = self.message_tree
|
||||
last_id = None
|
||||
for eid in message["id"]:
|
||||
if last_id is not None:
|
||||
tree = tree[last_id]
|
||||
if eid not in tree:
|
||||
tree[eid] = {"__errors": 0,
|
||||
"__warnings": 0,
|
||||
"__notices": 0,
|
||||
"__messages": []}
|
||||
tree[eid]["__%s" % type_] += 1
|
||||
last_id = eid
|
||||
|
||||
tree[last_id]['__messages'].append(uid)
|
||||
|
||||
# If instant mode is turned on, output the message immediately.
|
||||
if self.instant:
|
||||
self._print_message(type_, message, verbose=True)
|
||||
|
@ -203,14 +185,12 @@ class ErrorBundle(object):
|
|||
"warnings": self.warnings,
|
||||
"notices": self.notices,
|
||||
"detected_type": self.detected_type,
|
||||
"message_tree": self.message_tree,
|
||||
"resources": self.pushable_resources,
|
||||
"metadata": self.metadata})
|
||||
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
self.notices = []
|
||||
self.message_tree = {}
|
||||
self.pushable_resources = {}
|
||||
self.metadata = {}
|
||||
|
||||
|
@ -224,14 +204,12 @@ class ErrorBundle(object):
|
|||
errors = self.errors
|
||||
warnings = self.warnings
|
||||
notices = self.notices
|
||||
# We only rebuild message_tree anyway. No need to restore.
|
||||
|
||||
# Copy the existing state back into place
|
||||
self.errors = state["errors"]
|
||||
self.warnings = state["warnings"]
|
||||
self.notices = state["notices"]
|
||||
self.detected_type = state["detected_type"]
|
||||
self.message_tree = state["message_tree"]
|
||||
self.pushable_resources = state["resources"]
|
||||
self.metadata = state["metadata"]
|
||||
|
||||
|
@ -281,7 +259,6 @@ class ErrorBundle(object):
|
|||
"errors": len(self.errors),
|
||||
"warnings": len(self.warnings),
|
||||
"notices": len(self.notices),
|
||||
"message_tree": self.message_tree,
|
||||
"metadata": self.metadata}
|
||||
|
||||
messages = output["messages"]
|
||||
|
|
|
@ -69,7 +69,7 @@ def prepare_package(err, path, timeout=None):
|
|||
|
||||
|
||||
def test_package(err, file_, name):
|
||||
"Begins tests for the package."
|
||||
"""Begins tests for the package."""
|
||||
|
||||
# Load up a new instance of a package.
|
||||
try:
|
||||
|
|
|
@ -5,3 +5,4 @@ simplejson==2.3.0
|
|||
argparse==1.1
|
||||
-e git://github.com/mattbasta/fastchardet#egg=fastchardet
|
||||
mock==1.0b1
|
||||
fudge==1.0.3
|
|
@ -226,18 +226,6 @@ def test_json_constructs():
|
|||
assert "detected_type" in j
|
||||
assert j["detected_type"] == "extension"
|
||||
|
||||
assert "message_tree" in j
|
||||
tree = j["message_tree"]
|
||||
|
||||
assert "__errors" not in tree
|
||||
assert not tree["a"]["__messages"]
|
||||
assert tree["a"]["__errors"] == 4
|
||||
assert not tree["a"]["b"]["__messages"]
|
||||
assert tree["a"]["b"]["__errors"] == 2
|
||||
assert not tree["a"]["b"]["__messages"]
|
||||
assert tree["a"]["b"]["c"]["__errors"] == 1
|
||||
assert tree["a"]["b"]["c"]["__messages"]
|
||||
|
||||
assert "messages" in j
|
||||
for m in (m for m in j["messages"] if m["type"] == "warning"):
|
||||
assert m["context"] == ["x", "y", "z"]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import time
|
||||
|
||||
import fudge
|
||||
from mock import patch
|
||||
from nose.tools import eq_
|
||||
|
||||
import appvalidator.submain as submain
|
||||
|
@ -8,27 +10,22 @@ from appvalidator.constants import *
|
|||
from helper import MockXPI
|
||||
|
||||
|
||||
@patch("appvalidator.submain.test_package",
|
||||
lambda w, x, y: True)
|
||||
def test_prepare_package():
|
||||
"Tests that the prepare_package function passes for valid data"
|
||||
|
||||
tp = submain.test_package
|
||||
submain.test_package = lambda w, x, y: True
|
||||
|
||||
err = ErrorBundle()
|
||||
assert submain.prepare_package(err, "tests/resources/main/foo.xpi") == True
|
||||
submain.test_package = tp
|
||||
eq_(submain.prepare_package(err, "tests/resources/main/foo.xpi"), err)
|
||||
assert not err.failed()
|
||||
|
||||
|
||||
@patch("appvalidator.submain.test_inner_package",
|
||||
lambda err, package: time.sleep(1))
|
||||
def test_validation_timeout():
|
||||
tp = submain.test_inner_package
|
||||
def slow(*args, **kw):
|
||||
time.sleep(1)
|
||||
submain.test_inner_package = slow
|
||||
err = ErrorBundle()
|
||||
submain.prepare_package(err, "tests/resources/main/foo.xpi",
|
||||
timeout=0.1)
|
||||
submain.test_inner_package = tp
|
||||
|
||||
assert len(err.errors) == 1
|
||||
|
||||
|
||||
|
@ -50,77 +47,13 @@ def test_prepare_package_bad_file():
|
|||
assert err.failed()
|
||||
|
||||
|
||||
def test_prepare_package_webapp():
|
||||
_orig = submain.test_webapp
|
||||
calls = {'x': 0}
|
||||
submain.test_webapp = lambda err, y: calls.update(x=1)
|
||||
try:
|
||||
err = ErrorBundle()
|
||||
submain.prepare_package(err, "tests/resources/main/mozball.webapp")
|
||||
assert not err.failed()
|
||||
assert calls['x'] == 1, "test_webapp() was not called"
|
||||
finally:
|
||||
submain.test_webapp = _orig
|
||||
|
||||
# Test the function of the decorator iterator
|
||||
|
||||
def test_inner_package():
|
||||
"Tests that the test_inner_package function works properly"
|
||||
|
||||
smd = submain.decorator
|
||||
decorator = MockDecorator()
|
||||
submain.decorator = decorator
|
||||
err = MockErrorHandler(decorator)
|
||||
|
||||
submain.test_inner_package(err, "foo")
|
||||
@fudge.patch("appvalidator.submain.detect_webapp")
|
||||
def test_prepare_package_webapp(fake_webapp_validator):
|
||||
fake_webapp_validator.expects_call().with_arg_count(2)
|
||||
|
||||
err = ErrorBundle()
|
||||
submain.prepare_package(err, "tests/resources/main/mozball.webapp")
|
||||
assert not err.failed()
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
def test_inner_package_failtier():
|
||||
"Tests that the test_inner_package function fails at a failed tier"
|
||||
|
||||
smd = submain.decorator
|
||||
decorator = MockDecorator(3)
|
||||
submain.decorator = decorator
|
||||
err = MockErrorHandler(decorator)
|
||||
|
||||
submain.test_inner_package(err, "foo")
|
||||
|
||||
assert err.failed()
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
# Test determined modes
|
||||
def test_inner_package_determined():
|
||||
"Tests that the determined test_inner_package function works properly"
|
||||
|
||||
smd = submain.decorator
|
||||
decorator = MockDecorator(None, True)
|
||||
submain.decorator = decorator
|
||||
err = MockErrorHandler(decorator, True)
|
||||
|
||||
submain.test_inner_package(err, "foo")
|
||||
|
||||
assert not err.failed()
|
||||
eq_(decorator.last_tier, 5)
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
def test_inner_package_failtier():
|
||||
"Tests the test_inner_package function in determined mode while failing"
|
||||
|
||||
smd = submain.decorator
|
||||
decorator = MockDecorator(3, True)
|
||||
submain.decorator = decorator
|
||||
err = MockErrorHandler(decorator, True)
|
||||
|
||||
submain.test_inner_package(err, "foo")
|
||||
|
||||
assert err.failed()
|
||||
eq_(decorator.last_tier, 5)
|
||||
submain.decorator = smd
|
||||
|
||||
|
||||
class MockDecorator:
|
||||
|
@ -214,3 +147,44 @@ class MockErrorHandler:
|
|||
"Simple accessor because the standard error handler has one"
|
||||
return self.has_failed
|
||||
|
||||
|
||||
# Test the function of the decorator iterator
|
||||
@patch("appvalidator.submain.decorator", MockDecorator())
|
||||
def test_inner_package():
|
||||
"""Tests that the test_inner_package function works properly."""
|
||||
|
||||
err = MockErrorHandler(submain.decorator)
|
||||
submain.test_inner_package(err, "foo")
|
||||
assert not err.failed()
|
||||
|
||||
|
||||
@patch("appvalidator.submain.decorator", MockDecorator(3))
|
||||
def test_inner_package_failtier():
|
||||
"""Tests that the test_inner_package function fails at a failed tier."""
|
||||
|
||||
err = MockErrorHandler(submain.decorator)
|
||||
submain.test_inner_package(err, "foo")
|
||||
assert err.failed()
|
||||
|
||||
|
||||
# Test determined modes
|
||||
@patch("appvalidator.submain.decorator", MockDecorator(None, True))
|
||||
def test_inner_package_determined():
|
||||
"Tests that the determined test_inner_package function works properly"
|
||||
|
||||
err = MockErrorHandler(submain.decorator, True)
|
||||
submain.test_inner_package(err, "foo")
|
||||
|
||||
assert not err.failed()
|
||||
eq_(submain.decorator.last_tier, 5)
|
||||
|
||||
|
||||
@patch("appvalidator.submain.decorator", MockDecorator(3, True))
|
||||
def test_inner_package_failtier():
|
||||
"Tests the test_inner_package function in determined mode while failing"
|
||||
|
||||
err = MockErrorHandler(submain.decorator, True)
|
||||
submain.test_inner_package(err, "foo")
|
||||
|
||||
assert err.failed()
|
||||
eq_(submain.decorator.last_tier, 5)
|
||||
|
|
Загрузка…
Ссылка в новой задаче