本文整理汇总了Python中validator.errorbundler.ErrorBundle.set_type方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorBundle.set_type方法的具体用法?Python ErrorBundle.set_type怎么用?Python ErrorBundle.set_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类validator.errorbundler.ErrorBundle
的用法示例。
在下文中一共展示了ErrorBundle.set_type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_xpi_subpackage
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_xpi_subpackage():
"XPIs should never be subpackages; only nested extensions"
err = ErrorBundle()
err.set_type(PACKAGE_EXTENSION)
mock_package = MockXPI(
{"chrome/package.xpi":
"tests/resources/content/subpackage.jar"})
content.testendpoint_validator = \
MockTestEndpoint(("test_package", ))
result = content.test_packed_packages(
err,
mock_package)
print result
assert result == 1
content.testendpoint_validator.assert_expectation(
"test_package",
1)
content.testendpoint_validator.assert_expectation(
"test_package",
0,
"subpackage")
示例2: _do_test
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def _do_test(path, test, failure=True,
require_install=False, set_type=0):
package_data = open(path, "rb")
package = XPIManager(package_data, path)
contents = package.get_file_data()
err = ErrorBundle()
# Populate in the dependencies.
if set_type:
err.set_type(set_type) # Conduit test requires type
if require_install:
err.save_resource("has_install_rdf", True)
rdf_data = package.read("install.rdf")
install_rdf = RDFParser(rdf_data)
err.save_resource("install_rdf", install_rdf)
test(err, contents, package)
print err.print_summary(verbose=True)
if failure:
assert err.failed()
else:
assert not err.failed()
return err
示例3: test_langpack
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_langpack():
"Tests a language pack in the content validator."
err = ErrorBundle(None, True)
err.set_type(PACKAGE_LANGPACK)
mock_package = MockXPIManager(
{"foo.dtd":
"tests/resources/content/junk.xpi"})
content.testendpoint_langpack = \
MockTestEndpoint(("test_unsafe_html", ))
result = content.test_packed_packages(
err,
{"foo.dtd":
{"extension": "dtd",
"name_lower": "foo.dtd"}},
mock_package)
print result
assert result == 1
content.testendpoint_langpack.assert_expectation(
"test_unsafe_html",
1)
content.testendpoint_langpack.assert_expectation(
"test_unsafe_html",
0,
"subpackage")
示例4: test_jar_subpackage
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_jar_subpackage():
"Tests JAR files that are subpackages."
err = ErrorBundle()
err.set_type(PACKAGE_EXTENSION)
err.supported_versions = {"foo": ["1.2.3"]}
mock_package = MockXPI(
{"chrome/subpackage.jar":
"tests/resources/content/subpackage.jar",
"subpackage.jar":
"tests/resources/content/subpackage.jar"})
content.testendpoint_validator = \
MockTestEndpoint(("test_inner_package", ))
result = content.test_packed_packages(
err,
mock_package)
print result
assert result == 2
content.testendpoint_validator.assert_expectation(
"test_inner_package",
2)
content.testendpoint_validator.assert_expectation(
"test_inner_package",
2,
"subpackage")
assert err.supported_versions == {"foo": ["1.2.3"]}
示例5: test_jar_nonsubpackage
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_jar_nonsubpackage():
"Tests XPI files that are not subpackages."
err = ErrorBundle()
err.set_type(PACKAGE_MULTI)
err.save_resource("is_multipackage", True)
mock_package = MockXPI(
{"foo.jar":
"tests/resources/content/subpackage.jar",
"chrome/bar.jar":
"tests/resources/content/subpackage.jar"})
content.testendpoint_validator = MockTestEndpoint(("test_inner_package",
"test_package"))
result = content.test_packed_packages(
err,
mock_package)
print result
assert result == 2
content.testendpoint_validator.assert_expectation(
"test_package",
2)
content.testendpoint_validator.assert_expectation(
"test_package",
0,
"subpackage")
示例6: _do_test
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def _do_test(path, test, failure=True,
require_install=False, set_type=0,
listed=False, xpi_mode="r"):
package_data = open(path, "rb")
package = XPIManager(package_data, mode=xpi_mode, name=path)
err = ErrorBundle()
if listed:
err.save_resource("listed", True)
# Populate in the dependencies.
if set_type:
err.set_type(set_type) # Conduit test requires type
if require_install:
err.save_resource("has_install_rdf", True)
rdf_data = package.read("install.rdf")
install_rdf = RDFParser(rdf_data)
err.save_resource("install_rdf", install_rdf)
populate_chrome_manifest(err, package)
test(err, package)
print err.print_summary(verbose=True)
if failure:
assert err.failed()
else:
assert not err.failed()
return err
示例7: test_type
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_type():
"""Tests that detected type is being stored properly in the error
bundle."""
bundle = ErrorBundle()
bundle.set_type(5)
assert bundle.detected_type == 5
示例8: test_subpackage
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_subpackage():
"Test a package with localization that should pass validation."
err = ErrorBundle()
err.set_type(PACKAGE_DICTIONARY)
assert l10n.test_xpi(err, None) is None
err.set_type(PACKAGE_EXTENSION)
err.push_state()
assert l10n.test_xpi(err, None) is None
示例9: _do_test
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def _do_test(unpack=False, contents=(), set_type=0, is_ff4=False):
"Runs the tests. Handy as hell."
err = ErrorBundle(None, True)
if set_type:
err.set_type(set_type)
err.save_resource("em:unpack", unpack)
err.save_resource("ff4", is_ff4)
packagelayout.test_emunpack(err, contents, None)
return err
示例10: _do_test
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def _do_test(unpack=False, contents=None, set_type=0, is_ff4=False):
"Runs the tests. Handy as hell."
if not contents:
contents = []
err = ErrorBundle(None, True)
if set_type:
err.set_type(set_type)
err.save_resource("em:unpack", unpack)
err.save_resource("ff4", is_ff4)
packagelayout.test_emunpack(err,
MockXPI(dict(zip(contents,
[True for c in contents]))))
return err
示例11: test_langpack
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_langpack():
"Tests a language pack in the content validator."
err = ErrorBundle()
err.supported_versions = {}
err.set_type(PACKAGE_LANGPACK)
mock_package = MockXPI({"foo.dtd": "tests/resources/content/junk.xpi"})
content.testendpoint_langpack = MockTestEndpoint(("test_unsafe_html", ))
result = content.test_packed_packages(err, mock_package)
print result
assert result == 1
content.testendpoint_langpack.assert_expectation("test_unsafe_html", 1)
content.testendpoint_langpack.assert_expectation("test_unsafe_html", 0,
"subpackage")
示例12: _do_test_raw
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def _do_test_raw(data, path, should_fail=False, type_=None):
filename = path.split("/")[-1]
extension = filename.split(".")[-1]
err = ErrorBundle()
err.supported_versions = {}
if type_:
err.set_type(type_)
parser = markuptester.MarkupParser(err, debug=True)
parser.process(filename, data, extension)
print err.print_summary(verbose=True)
if should_fail:
assert err.failed()
else:
assert not err.failed()
return err
示例13: test_json
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [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
示例14: _do_test
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def _do_test(path, should_fail=False, type_=None):
markup_file = open(path)
data = markup_file.read()
markup_file.close()
filename = path.split("/")[-1]
extension = filename.split(".")[-1]
err = ErrorBundle(None, True)
if type_:
err.set_type(type_)
parser = markuptester.MarkupParser(err, True)
parser.process(filename, data, extension)
err.print_summary(True)
if should_fail:
assert err.failed()
else:
assert not err.failed()
return err
示例15: test_states
# 需要导入模块: from validator.errorbundler import ErrorBundle [as 别名]
# 或者: from validator.errorbundler.ErrorBundle import set_type [as 别名]
def test_states():
"""Tests that detected type is preserved, even in subpackages."""
# Use the StringIO as an output buffer.
bundle = ErrorBundle()
# Populate the bundle with some test data.
bundle.set_type(4)
bundle.error((), "error")
bundle.warning((), "warning")
bundle.notice((), "notice")
bundle.save_resource("test", True)
# Push a state
bundle.push_state("test.xpi")
bundle.set_type(2)
bundle.error((), "nested error")
bundle.warning((), "nested warning")
bundle.notice((), "nested notice")
# Push another state
bundle.push_state("test2.xpi")
bundle.set_type(3)
bundle.error((), "super nested error")
bundle.warning((), "super nested warning")
bundle.notice((), "super nested notice")
bundle.pop_state()
bundle.pop_state()
# Load the JSON output as an object.
output = json.loads(bundle.render_json())
# Run some basic tests
assert output["detected_type"] == "langpack"
assert len(output["messages"]) == 9
print output
messages = ["error",
"warning",
"notice",
"nested error",
"nested warning",
"nested notice",
"super nested error",
"super nested warning",
"super nested notice"]
for message in output["messages"]:
print message
assert message["message"] in messages
messages.remove(message["message"])
assert message["message"].endswith(message["type"])
assert not messages
assert bundle.get_resource("test")