本文整理汇总了Python中validator.errorbundler.ErrorBundle.error方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorBundle.error方法的具体用法?Python ErrorBundle.error怎么用?Python ErrorBundle.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validator.errorbundler.ErrorBundle
的用法示例。
在下文中一共展示了ErrorBundle.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_json_compatibility
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_json_compatibility():
"""Test compatibility elements in the JSON output."""
err = ErrorBundle()
err.notice(err_id="m1", notice="Compat error", description="Compatibility error 1", compatibility_type="error")
err.notice(err_id="m2", notice="Compat error", description="Compatibility error 2", compatibility_type="error")
err.warning(err_id="m3", warning="Compat notice", description="Compatibility notice 1", compatibility_type="notice")
err.warning(
err_id="m4", warning="Compat warning", description="Compatibility warning 1", compatibility_type="warning"
)
err.warning(
err_id="m5", warning="Compat warning", description="Compatibility warning 1", compatibility_type="warning"
)
err.error(err_id="foo", error="Something else", description="An error that has nothign to do with compatibility")
results = err.render_json()
jdata = json.loads(results)
assert "compatibility_summary" in jdata
nose.tools.eq_(jdata["compatibility_summary"], {"errors": 2, "warnings": 2, "notices": 1})
reference = {"m1": "error", "m2": "error", "m3": "notice", "m4": "warning", "m5": "warning"}
assert "messages" in jdata and len(jdata["messages"])
for message in jdata["messages"]:
if message["id"] in reference:
print (message["id"], reference[message["id"]], message["compatibility_type"])
nose.tools.eq_(reference[message["id"]], message["compatibility_type"])
示例2: test_json_compatibility
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_json_compatibility():
"""Test compatibility elements in the JSON output."""
err = ErrorBundle()
err.notice(
err_id='m1',
notice='Compat error',
description='Compatibility error 1',
compatibility_type='error')
err.notice(
err_id='m2',
notice='Compat error',
description='Compatibility error 2',
compatibility_type='error')
err.warning(
err_id='m3',
warning='Compat notice',
description='Compatibility notice 1',
compatibility_type='notice')
err.warning(
err_id='m4',
warning='Compat warning',
description='Compatibility warning 1',
compatibility_type='warning')
err.warning(
err_id='m5',
warning='Compat warning',
description='Compatibility warning 1',
compatibility_type='warning')
err.error(
err_id='foo',
error='Something else',
description='An error that has nothign to do with compatibility')
results = err.render_json()
jdata = json.loads(results)
assert 'compatibility_summary' in jdata
assert jdata['compatibility_summary'] == {
'errors': 2,
'warnings': 2,
'notices': 1}
reference = {'m1': 'error',
'm2': 'error',
'm3': 'notice',
'm4': 'warning',
'm5': 'warning'}
assert 'messages' in jdata and len(jdata['messages'])
for message in jdata['messages']:
if message['id'] in reference:
print (message['id'],
reference[message['id']],
message['compatibility_type'])
assert reference[message['id']] == message['compatibility_type']
示例3: test_validation_timeout
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_validation_timeout(test_package):
def slow(*args, **kw):
time.sleep(1)
test_package.side_effect = slow
err = ErrorBundle()
err.error(('an', 'error'), 'occurred')
submain.prepare_package(err, 'tests/resources/main/foo.xpi', timeout=0.1)
# Make sure that our error got moved to the front of the list.
assert len(err.errors) == 2
assert err.errors[0]['id'] == ('validator', 'unexpected_exception',
'validation_timeout')
示例4: test_validation_timeout
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_validation_timeout(test_package):
def slow(*args, **kw):
time.sleep(1)
test_package.side_effect = slow
err = ErrorBundle()
err.error(("an", "error"), "occurred")
submain.prepare_package(err, "tests/resources/main/foo.xpi", timeout=0.1)
# Make sure that our error got moved to the front of the list.
eq_(len(err.errors), 2)
eq_(err.errors[0]["id"], ("validator", "unexpected_exception", "validation_timeout"))
示例5: test_validation_error
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_validation_error(log, test_package):
"""Test that an unexpected exception during validation is turned into
an error message and logged."""
test_package.side_effect = Exception
err = ErrorBundle()
err.error(("an", "error"), "occurred")
submain.prepare_package(err, "tests/resources/main/foo.xpi")
assert log.error.called
# Make sure that our error got moved to the front of the list.
eq_(len(err.errors), 2)
eq_(err.errors[0]["id"], ("validator", "unexpected_exception"))
示例6: test_validation_error
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_validation_error(log, test_package):
"""Test that an unexpected exception during validation is turned into
an error message and logged."""
test_package.side_effect = Exception
err = ErrorBundle()
err.error(('an', 'error'), 'occurred')
submain.prepare_package(err, 'tests/resources/main/foo.xpi')
assert log.error.called
# Make sure that our error got moved to the front of the list.
assert len(err.errors) == 2
assert err.errors[0]['id'] == ('validator', 'unexpected_exception')
示例7: test_boring
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_boring():
"""Test that boring output strips out color sequences."""
stdout = sys.stdout
sys.stdout = StringIO()
# Use the StringIO as an output buffer.
bundle = ErrorBundle()
bundle.error((), "<<BLUE>><<GREEN>><<YELLOW>>")
bundle.print_summary(no_color=True)
outbuffer = sys.stdout
sys.stdout = stdout
outbuffer.seek(0)
assert outbuffer.getvalue().count("<<GREEN>>") == 0
示例8: test_message_completeness
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_message_completeness():
"""Test we're fully expecting all of the values for a message."""
bundle = ErrorBundle()
bundle.error(("id",), "error", "description", "file", 123, 456) # line # column
results = json.loads(bundle.render_json())
eq_(len(results["messages"]), 1, "Unexpected number of messages.")
message = results["messages"][0]
eq_(message["id"], ["id"])
eq_(message["message"], "error")
eq_(message["description"], "description")
eq_(message["file"], "file")
eq_(message["line"], 123)
eq_(message["column"], 456)
示例9: test_search_failure
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_search_failure():
'Tests the submain test_search function with a failure'
err = ErrorBundle()
submain.detect_opensearch = (
lambda err, x, listed: err.error(('foo', ), 'Test'))
submain.test_search(err, None, PACKAGE_ANY)
assert err.failed()
示例10: test_search_failure_undecided
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_search_failure_undecided():
"Tests the submain test_search function with an unrejected fail case"
err = ErrorBundle()
submain.detect_opensearch = lambda err, x, listed: err.error(("foo", ),
"Test")
submain.test_search(err, None, PACKAGE_ANY)
assert err.failed()
示例11: test_json_constructs
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_json_constructs():
"""This tests some of the internal JSON stuff so we don't break zamboni."""
e = ErrorBundle()
e.detected_type = 1
e.error(("a", "b", "c"), "Test")
e.error(("a", "b", "foo"), "Test")
e.error(("a", "foo", "c"), "Test")
e.error(("a", "foo", "c"), "Test")
e.error(("b", "foo", "bar"), "Test")
e.warning((), "Context test", context=("x", "y", "z"))
e.warning((), "Context test", context=ContextGenerator("x\ny\nz\n"), line=2, column=0)
e.notice((), "none")
e.notice((), "line", line=1)
e.notice((), "column", column=0)
e.notice((), "line column", line=1, column=1)
results = e.render_json()
print results
j = json.loads(results)
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"]
for m in (m for m in j["messages"] if m["type"] == "notice"):
if "line" in m["message"]:
assert m["line"] is not None
assert isinstance(m["line"], int)
assert m["line"] > 0
else:
assert m["line"] is None
if "column" in m["message"]:
assert m["column"] is not None
assert isinstance(m["column"], int)
assert m["column"] > -1
else:
assert m["column"] is None
示例12: test_json
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_json():
"Tests the JSON output capability of the error bundler."
# Use the StringIO as an output buffer.
bundle = ErrorBundle() # No color since no output
bundle.set_type(4)
bundle.tier = 3
bundle.error((), "error", "description")
bundle.warning((), "warning", "description")
bundle.notice((), "notice", "description")
results = json.loads(bundle.render_json())
print results
assert len(results["messages"]) == 3
assert results["detected_type"] == 'langpack'
assert not results["success"]
assert results["ending_tier"] == 3
示例13: test_json
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_json():
"""Test the JSON output capability of the error bundler."""
# Use the StringIO as an output buffer.
bundle = ErrorBundle() # No color since no output
bundle.detected_type = 4
bundle.set_tier(4)
bundle.set_tier(3)
bundle.error((), 'error', 'description')
bundle.warning((), 'warning', 'description')
bundle.notice((), 'notice', 'description')
results = json.loads(bundle.render_json())
print results
assert len(results['messages']) == 3
assert results['detected_type'] == 'langpack'
assert not results['success']
assert results['ending_tier'] == 4
示例14: test_forappversions
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_forappversions():
"""Test that app version information is passed to the JSON."""
app_test_data = {"guid": ["version1", "version2"]}
e = ErrorBundle()
e.supported_versions = {"guid": ["version1"]}
e.error(err_id=("foo",), error="Test", for_appversions=app_test_data)
# This one should not apply.
e.error(err_id=("foo",), error="Test", for_appversions={"fooguid": ["bar", "baz"]})
e.warning(err_id=("foo",), warning="Test", for_appversions=app_test_data)
# Give one its data from the decorator
e.version_requirements = app_test_data
e.notice(err_id=("foo",), notice="Test")
j = e.render_json()
jdata = json.loads(j)
assert len(jdata["messages"]) == 3
for m in jdata["messages"]:
assert m["for_appversions"] == app_test_data
示例15: test_prepare_package_xml
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import error [as 别名]
def test_prepare_package_xml(test_search):
'Tests that the prepare_package function passes with search providers'
err = ErrorBundle()
submain.prepare_package(err, 'tests/resources/main/foo.xml')
assert not err.failed()
assert test_search.called
test_search.side_effect = lambda err, *args: err.error(('x'), 'Failed')
submain.prepare_package(err, 'tests/resources/main/foo.xml')
assert err.failed()