本文整理汇总了Python中validator.validate.validate函数的典型用法代码示例。如果您正苦于以下问题:Python validate函数的具体用法?Python validate怎么用?Python validate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_compat
def test_is_compat():
"""Test that we know when we're running a compatibility test."""
out = validate(path="tests/resources/junk.xpi", format=None, compat_test=False)
assert not out.get_resource("is_compat_test")
out = validate(path="tests/resources/junk.xpi", format=None, compat_test=True)
assert out.get_resource("is_compat_test")
示例2: test_app_versions_dict
def test_app_versions_dict():
"""
Test that `approved_applications` can be provided as a pre-parsed dict
of versions.
"""
with open('tests/resources/test_app_versions.json') as f:
apps = json.load(f)
validate(path='tests/resources/junk.xpi', approved_applications=apps)
assert constants.APPROVED_APPLICATIONS['1']['name'] == 'Foo App'
示例3: test_app_versions_dict
def test_app_versions_dict():
"""
Test that `approved_applications` can be provided as a pre-parsed dict
of versions.
"""
with open("tests/resources/test_app_versions.json") as f:
apps = json.load(f)
validate(path="tests/resources/junk.xpi", approved_applications=apps)
print constants.APPROVED_APPLICATIONS
assert constants.APPROVED_APPLICATIONS["1"]["name"] == "Foo App"
示例4: test_mrkt_urls
def test_mrkt_urls():
"""
Tests that Marketplace URLs are correctly added to the MRKT_URLS constant.
"""
# Keep a copy so we don't permanently overwrite.
MRKT_URLS = constants.DEFAULT_WEBAPP_MRKT_URLS[:]
validate(path="tests/resources/junk.xpi",
market_urls=["foobar"])
print constants.DEFAULT_WEBAPP_MRKT_URLS
assert "foobar" in constants.DEFAULT_WEBAPP_MRKT_URLS
# Clean up!
constants.DEFAULT_WEBAPP_MRKT_URLS = MRKT_URLS
示例5: test_validate_embedded_webextension_xpi
def test_validate_embedded_webextension_xpi():
"""Integration test for the expected notice message on 'embedded
webextension' add-ons."""
err_bundle = validate(
path='tests/resources/validate/hybrid_extension.xpi', format=None)
assert err_bundle.get_resource('has_embedded_webextension') is True
result = validate(path='tests/resources/validate/hybrid_extension.xpi')
data = json.loads(result)
assert data['success'] is True
assert data['errors'] == 0
assert data['notices'] == 1
assert data['warnings'] == 0
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert len(data['messages']) == 1
assert data['messages'][0]['file'] == u'install.rdf'
assert data['messages'][0]['message'] == (
u'This add-on contains an embedded webextension')
expected_embedded_webext_desc = (
'The embedded webextension is in the folder "webextension"')
expected_embedded_webext_doc_url = (
'https://developer.mozilla.org/en-US/Add-ons/WebExtensions/'
'Embedded_WebExtensions')
messages = data['messages']
assert expected_embedded_webext_desc in messages[0]['description']
assert expected_embedded_webext_doc_url in messages[0]['description']
assert data['message_tree']
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'name_value'
assert data['metadata']['version'] == u'1.2.3.4'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'[email protected]'
assert data['metadata'].get('strict_compatibility') is None
assert data['metadata']['is_extension'] is True
示例6: _test_validate_jpm_multiprocess_compatible
def _test_validate_jpm_multiprocess_compatible(compat_test):
"""Integration test for a multiprocess compatible jpm-style extension xpi,
without mocks."""
result = validate(path='tests/resources/validate/jpm_multiprocess.xpi', compat_test=compat_test)
data = json.loads(result)
assert data['success'] is True
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 0
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert data['messages'] == []
assert data['message_tree'] == {}
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'My Jetpack Addon'
assert data['metadata']['version'] == u'0.0.3'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'@test-addon'
示例7: _test_validate_old_xpi_multiprocess_compatible
def _test_validate_old_xpi_multiprocess_compatible(compat_test):
"""Integration test for a multiprocess compatible old-style extension xpi,
without mocks."""
result = validate(
path='tests/resources/validate/extension_multiprocess.xpi', compat_test=compat_test)
data = json.loads(result)
assert data['success'] is True
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 0
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert data['messages'] == []
assert data['message_tree'] == {}
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'name_value'
assert data['metadata']['version'] == u'1.2.3.4'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'[email protected]'
示例8: test_validate_old_xpi_with_jar_in_it
def test_validate_old_xpi_with_jar_in_it():
"""Integration test for a basic old-style extension xpi that contains a
.jar file, without mocks."""
result = validate(path='tests/resources/validate/extension_with_jar.xpi')
data = json.loads(result)
assert data['success'] is False
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 1
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert len(data['messages']) == 1
assert data['messages'][0]['id'] == [
u'submain', u'test_inner_package', u'not_multiprocess_compatible']
assert data['message_tree']
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'xpi name'
assert data['metadata']['version'] == u'0.2'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'[email protected]'
示例9: test_validate_dictionnary_no_multiprocess_compatible_warning
def test_validate_dictionnary_no_multiprocess_compatible_warning():
"""Integration test for a dictionnary xpi, without mocks."""
result = validate(path='tests/resources/validate/dictionary.xpi')
data = json.loads(result)
assert data['success'] is True
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 0
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'dictionary'
assert data['messages'] == []
assert data['message_tree'] == {}
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'My Fake Dictionary'
assert data['metadata']['version'] == u'1.0.0'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'[email protected]'
assert data['metadata'].get('strict_compatibility') is None
assert data['metadata']['is_extension'] is False
示例10: _test_validate_jpm
def _test_validate_jpm(compat_test):
"""Integration test for a basic jpm-style extension xpi, without mocks."""
result = validate(path='tests/resources/validate/jpm.xpi',
compat_test=compat_test)
data = json.loads(result)
assert data['success'] is False
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 1
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert len(data['messages']) == 1
assert data['messages'][0]['id'] == [
u'submain', u'test_inner_package', u'not_multiprocess_compatible']
assert data['message_tree']
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'My Jetpack Addon'
assert data['metadata']['version'] == u'0.0.3'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'@test-addon'
assert data['metadata'].get('strict_compatibility') is None
assert data['metadata']['is_extension'] is True
示例11: test_validate_old_xpi_thunderbird_only
def test_validate_old_xpi_thunderbird_only():
"""Integration test for a thunderbird-only old-style extension xpi
without mocks."""
result = validate(
path='tests/resources/validate/thunderbird_extension.xpi')
data = json.loads(result)
assert data['success'] is True
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 0
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert data['messages'] == []
assert data['message_tree'] == {}
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata']['name'] == u'name_value'
assert data['metadata']['version'] == u'1.2.3.4'
assert data['metadata']['listed'] is True
assert data['metadata']['id'] == u'[email protected]'
assert data['metadata'].get('strict_compatibility') is None
assert data['metadata']['is_extension'] is True
示例12: test_validate_webextension
def test_validate_webextension():
"""Integration test for a basic webextension, without mocks.
We're not supposed to use amo-validator for webextensions anymore now that
we have addons-linter, but let's make sure that we don't completely
blow up anyway."""
result = validate(path='tests/resources/validate/webextension.xpi')
data = json.loads(result)
assert data['success'] is True
assert data['errors'] == 0
assert data['notices'] == 0
assert data['warnings'] == 0
assert data['compatibility_summary']
assert data['compatibility_summary']['errors'] == 0
assert data['compatibility_summary']['notices'] == 0
assert data['compatibility_summary']['warnings'] == 0
assert data['detected_type'] == 'extension'
assert data['messages'] == []
assert data['message_tree'] == {}
assert data['signing_summary']['high'] == 0
assert data['signing_summary']['medium'] == 0
assert data['signing_summary']['low'] == 0
assert data['signing_summary']['trivial'] == 0
assert data['metadata']
assert data['metadata'].get('strict_compatibility') is None
assert data['metadata']['is_extension'] is True
示例13: _validator
def _validator(file_path):
# TODO(Kumar) This is currently copied from Zamboni because
# it's really hard to import from zamboni outside of itself.
# TODO(Kumar) remove this when validator is fixed, see bug 620503
from validator.testcases import scripting
import validator.constants
js = os.environ.get('SPIDERMONKEY_INSTALLATION', 'js')
scripting.SPIDERMONKEY_INSTALLATION = js
validator.constants.SPIDERMONKEY_INSTALLATION = js
apps = os.path.join(os.path.dirname(__file__), 'apps.json')
orig = sys.stderr
sys.stderr = StringIO()
try:
result = validate(file_path, format='json',
# Test all tiers at once. This will make sure we see
# all error messages.
determined=True,
approved_applications=apps,
spidermonkey=js)
sys.stdout.write(sys.stderr.getvalue())
if 'Traceback' in sys.stderr.getvalue():
# the validator catches and ignores certain errors in an attempt
# to remain versatile. There should not be any exceptions
# while testing.
raise RuntimeError(
"An exception was raised during validation. Check stderr")
finally:
sys.stderr = orig
return result
示例14: _validator
def _validator(file_path, for_appversions=None, overrides=None):
from validator.testcases import scripting
import validator
import validator.constants
js = os.environ.get('SPIDERMONKEY_INSTALLATION', 'js')
scripting.SPIDERMONKEY_INSTALLATION = js
validator.constants.SPIDERMONKEY_INSTALLATION = js
apps = os.path.join(os.path.dirname(validator.__file__),
'app_versions.json')
if not os.path.exists(apps):
raise EnvironmentError('Could not locate app_versions.json in git '
'repo for validator. Tried: %s' % apps)
orig = sys.stderr
sys.stderr = StringIO()
try:
result = validate(file_path, format='json',
# Test all tiers at once. This will make sure we see
# all error messages.
determined=True,
approved_applications=apps,
spidermonkey=js,
for_appversions=for_appversions,
timeout=60 * 3, # seconds
overrides=overrides)
sys.stdout.write(sys.stderr.getvalue())
if 'Traceback' in sys.stderr.getvalue():
# the validator catches and ignores certain errors in an attempt
# to remain versatile. There should not be any exceptions
# while testing.
raise RuntimeError(
"An exception was raised during validation. Check stderr")
finally:
sys.stderr = orig
return result
示例15: run_validator
def run_validator(file_path, for_appversions=None, test_all_tiers=False, overrides=None):
"""A pre-configured wrapper around the addon validator.
*file_path*
Path to addon / extension file to validate.
*for_appversions=None*
An optional dict of application versions to validate this addon
for. The key is an application GUID and its value is a list of
versions.
*test_all_tiers=False*
When False (default) the validator will not continue if it
encounters fatal errors. When True, all tests in all tiers are run.
See bug 615426 for discussion on this default.
*overrides=None*
Normally the validator gets info from install.rdf but there are a
few things we need to override. See validator for supported overrides.
Example: {'targetapp_maxVersion': {'<app guid>': '<version>'}}
To validate the addon for compatibility with Firefox 5 and 6,
you'd pass in::
for_appversions={amo.FIREFOX.guid: ['5.0.*', '6.0.*']}
Not all application versions will have a set of registered
compatibility tests.
"""
from validator.validate import validate
# TODO(Kumar) remove this when validator is fixed, see bug 620503
from validator.testcases import scripting
scripting.SPIDERMONKEY_INSTALLATION = settings.SPIDERMONKEY
import validator.constants
validator.constants.SPIDERMONKEY_INSTALLATION = settings.SPIDERMONKEY
apps = dump_apps.Command.JSON_PATH
if not os.path.exists(apps):
call_command("dump_apps")
with statsd.timer("devhub.validator"):
return validate(
file_path,
for_appversions=for_appversions,
format="json",
# When False, this flag says to stop testing after one
# tier fails.
determined=test_all_tiers,
approved_applications=apps,
spidermonkey=settings.SPIDERMONKEY,
overrides=overrides,
timeout=settings.VALIDATOR_TIMEOUT,
)