More updates to simplify API and improve output
This commit is contained in:
Родитель
15545d1ea1
Коммит
d34b4e56a6
|
@ -18,7 +18,7 @@ def test_json():
|
|||
|
||||
bundle.error((), "error", "description")
|
||||
bundle.warning((), "warning", "description")
|
||||
bundle.info((), "info", "description")
|
||||
bundle.notice((), "notice", "description")
|
||||
|
||||
bundle.print_json()
|
||||
|
||||
|
@ -67,7 +67,7 @@ def test_states():
|
|||
bundle.set_type(4)
|
||||
bundle.error((), "error")
|
||||
bundle.warning((), "warning")
|
||||
bundle.info((), "info")
|
||||
bundle.notice((), "notice")
|
||||
bundle.save_resource("test", True)
|
||||
|
||||
# Push a state
|
||||
|
@ -76,7 +76,7 @@ def test_states():
|
|||
bundle.set_type(2)
|
||||
bundle.error((), "nested error")
|
||||
bundle.warning((), "nested warning")
|
||||
bundle.info((), "nested info")
|
||||
bundle.notice((), "nested notice")
|
||||
|
||||
# Push another state
|
||||
bundle.push_state("test2.xpi")
|
||||
|
@ -84,7 +84,7 @@ def test_states():
|
|||
bundle.set_type(3)
|
||||
bundle.error((), "super nested error")
|
||||
bundle.warning((), "super nested warning")
|
||||
bundle.info((), "super nested info")
|
||||
bundle.notice((), "super nested notice")
|
||||
|
||||
bundle.pop_state()
|
||||
|
||||
|
@ -102,13 +102,13 @@ def test_states():
|
|||
|
||||
messages = ["error",
|
||||
"warning",
|
||||
"info",
|
||||
"notice",
|
||||
"nested error",
|
||||
"nested warning",
|
||||
"nested info",
|
||||
"nested notice",
|
||||
"super nested error",
|
||||
"super nested warning",
|
||||
"super nested info"]
|
||||
"super nested notice"]
|
||||
|
||||
for message in output["messages"]:
|
||||
print message
|
||||
|
@ -194,7 +194,7 @@ def test_file_structure():
|
|||
assert not messages
|
||||
|
||||
|
||||
def test_info():
|
||||
def test_notice():
|
||||
"""Tests notice-related functions of the error bundler."""
|
||||
|
||||
outbuffer = StringIO()
|
||||
|
@ -202,7 +202,7 @@ def test_info():
|
|||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle(outbuffer, True) # No color since no output
|
||||
|
||||
bundle.info((), "info")
|
||||
bundle.notice((), "")
|
||||
|
||||
# Load the JSON output as an object.
|
||||
bundle.print_json()
|
||||
|
@ -213,19 +213,19 @@ def test_info():
|
|||
|
||||
print output
|
||||
|
||||
has_info = False
|
||||
has_ = False
|
||||
|
||||
for message in output["messages"]:
|
||||
print message
|
||||
|
||||
if message["type"] == "info":
|
||||
has_info = True
|
||||
if message["type"] == "notice":
|
||||
has_ = True
|
||||
|
||||
assert has_info
|
||||
assert has_
|
||||
assert not bundle.failed()
|
||||
|
||||
|
||||
def test_info_friendly():
|
||||
def test_notice_friendly():
|
||||
"""Tests notice-related human-friendly text output functions of the
|
||||
error bundler."""
|
||||
|
||||
|
@ -234,7 +234,7 @@ def test_info_friendly():
|
|||
# Use the StringIO as an output buffer.
|
||||
bundle = ErrorBundle(outbuffer, True) # No color since no output
|
||||
|
||||
bundle.info((), "foobar")
|
||||
bundle.notice((), "foobar")
|
||||
|
||||
# Load the JSON output as an object.
|
||||
bundle.print_summary(True)
|
||||
|
|
|
@ -160,5 +160,5 @@ def test_obsolete():
|
|||
"Tests that elements that shouldn't exist aren't there."
|
||||
|
||||
err = _run_test("tests/resources/installrdf/obsolete.rdf", False)
|
||||
assert err.infos
|
||||
assert err.notices
|
||||
|
||||
|
|
|
@ -134,4 +134,4 @@ def test_invalid_markup():
|
|||
assert result.warnings
|
||||
result = _do_test("tests/resources/markup/markuptester/bad_script.xml",
|
||||
False)
|
||||
assert result.infos
|
||||
assert result.notices
|
||||
|
|
|
@ -14,19 +14,20 @@ class ErrorBundle(object):
|
|||
'separating the sorrow and collecting up all the cream.' It's
|
||||
borderline magical."""
|
||||
|
||||
def __init__(self, pipe=None, no_color=False):
|
||||
def __init__(self, pipe=None, no_color=False, determined=True,
|
||||
listed=False):
|
||||
"""Specifying pipe allows the output of the bundler to be
|
||||
written to a file rather than to the screen."""
|
||||
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
self.infos = []
|
||||
self.notices = []
|
||||
self.message_tree = {}
|
||||
|
||||
self.tier = 0
|
||||
|
||||
self.metadata = {}
|
||||
self.determined = False
|
||||
self.determined = determined
|
||||
|
||||
self.subpackages = []
|
||||
self.package_stack = []
|
||||
|
@ -35,6 +36,9 @@ class ErrorBundle(object):
|
|||
self.resources = {}
|
||||
self.reject = False
|
||||
|
||||
if listed:
|
||||
self.resources["listed"] = True
|
||||
|
||||
self.handler = OutputHandler(pipe, no_color)
|
||||
|
||||
|
||||
|
@ -60,12 +64,16 @@ class ErrorBundle(object):
|
|||
"line": line})
|
||||
return self
|
||||
|
||||
def info(self, err_id, info, description='', filename='', line=0):
|
||||
def info(self, err_id, info, description="", filename="", line=0):
|
||||
"An alias for notice"
|
||||
self.notice(err_id, info, description, filename, line)
|
||||
|
||||
def notice(self, err_id, notice, description="", filename="", line=0):
|
||||
"Stores an informational message about the validation"
|
||||
self._save_message(self.infos,
|
||||
"infos",
|
||||
self._save_message(self.notices,
|
||||
"notices",
|
||||
{"id": err_id,
|
||||
"message": info,
|
||||
"message": notice,
|
||||
"description": description,
|
||||
"file": filename,
|
||||
"line": line})
|
||||
|
@ -131,14 +139,14 @@ class ErrorBundle(object):
|
|||
|
||||
self.subpackages.append({"errors": self.errors,
|
||||
"warnings": self.warnings,
|
||||
"infos": self.infos,
|
||||
"notices": self.notices,
|
||||
"detected_type": self.detected_type,
|
||||
"resources": self.resources,
|
||||
"message_tree": self.message_tree})
|
||||
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
self.infos = []
|
||||
self.notices = []
|
||||
self.resources = {}
|
||||
self.message_tree = {}
|
||||
|
||||
|
@ -151,13 +159,13 @@ class ErrorBundle(object):
|
|||
state = self.subpackages.pop()
|
||||
errors = self.errors
|
||||
warnings = self.warnings
|
||||
infos = self.infos
|
||||
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.infos = state["infos"]
|
||||
self.notices = state["notices"]
|
||||
self.detected_type = state["detected_type"]
|
||||
self.resources = state["resources"]
|
||||
self.message_tree = state["message_tree"]
|
||||
|
@ -166,7 +174,7 @@ class ErrorBundle(object):
|
|||
|
||||
self._merge_messages(errors, self.error, name)
|
||||
self._merge_messages(warnings, self.warning, name)
|
||||
self._merge_messages(infos, self.info, name)
|
||||
self._merge_messages(notices, self.notice, name)
|
||||
|
||||
|
||||
def _merge_messages(self, messages, callback, name):
|
||||
|
@ -229,7 +237,7 @@ class ErrorBundle(object):
|
|||
"messages":[],
|
||||
"errors": len(self.errors),
|
||||
"warnings": len(self.warnings),
|
||||
"notices": len(self.infos),
|
||||
"notices": len(self.notices),
|
||||
"message_tree": self.message_tree}
|
||||
|
||||
messages = output["messages"]
|
||||
|
@ -245,10 +253,10 @@ class ErrorBundle(object):
|
|||
self._clean_description(warning, True)
|
||||
messages.append(warning)
|
||||
|
||||
for info in self.infos:
|
||||
info["type"] = "notice"
|
||||
self._clean_description(info, True)
|
||||
messages.append(info)
|
||||
for notice in self.notices:
|
||||
notice["type"] = "notice"
|
||||
self._clean_description(notice, True)
|
||||
messages.append(notice)
|
||||
|
||||
# Output the JSON.
|
||||
json_output = json.dumps(output)
|
||||
|
@ -341,8 +349,8 @@ class ErrorBundle(object):
|
|||
def _print_verbose(self, verbose):
|
||||
"Prints info code to help prevent code duplication"
|
||||
|
||||
if self.infos and verbose:
|
||||
if self.notices and verbose:
|
||||
mesg = "<<WHITE>>Notice:<<NORMAL>>\t"
|
||||
for info in self.infos:
|
||||
self._print_message(mesg, info)
|
||||
for notice in self.notices:
|
||||
self._print_message(mesg, notice)
|
||||
|
||||
|
|
|
@ -79,15 +79,20 @@ def main():
|
|||
|
||||
args = parser.parse_args()
|
||||
|
||||
error_bundle = ErrorBundle(args.file,
|
||||
not args.file == sys.stdout or args.boring)
|
||||
error_bundle.determined = args.determined
|
||||
error_bundle = ErrorBundle(pipe=args.file,
|
||||
no_color=(not args.file == sys.stdout or
|
||||
args.boring),
|
||||
determined=args.determined,
|
||||
listed=not args.selfhosted)
|
||||
|
||||
# Emulates the "$status" variable in the original validation.php
|
||||
# test file. Equal to "$status == STATUS_LISTED".
|
||||
error_bundle.save_resource("listed", not args.selfhosted)
|
||||
# We want to make sure that the output is expected. Parse out the expected
|
||||
# type for the add-on and pass it in for validation.
|
||||
if args.type not in expectations:
|
||||
# Fail if the user provided invalid input.
|
||||
print "Given expectation (%s) not valid. See --help for details" % \
|
||||
args.type
|
||||
sys.exit(1)
|
||||
|
||||
# Parse out the expected add-on type and run the tests.
|
||||
expectation = expectations[args.type]
|
||||
submain.prepare_package(error_bundle, args.package, expectation)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче