Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Fix flake8 errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaglione committed Jul 13, 2015
1 parent d75eee3 commit 7f123a2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion jetpack/addon-sdk
Submodule addon-sdk updated 729 files
9 changes: 9 additions & 0 deletions validator/loader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""
Presumably, the purpose of this module is to load things in an order such
that they do not cause import loops. Given how easy it is, at the moment,
to cause import loops by making trivial changes, this presumption is likely
valid.
It probably also has the effect of making sure each of these modules registers
its testcases in the appropriate places before we begin running tests.
"""
import validator.testcases.chromemanifest
# Import this before content to avoid import loops.
import validator.testcases.javascript.traverser
Expand Down
33 changes: 15 additions & 18 deletions validator/main.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import argparse
import json
import os
import sys
import zipfile
from StringIO import StringIO

from validator import constants
from validator.validate import validate
from constants import *


def main():
"Main function. Handles delegation to other functions."

expectations = {"any": PACKAGE_ANY,
"extension": PACKAGE_EXTENSION,
"theme": PACKAGE_THEME,
"dictionary": PACKAGE_DICTIONARY,
"languagepack": PACKAGE_LANGPACK,
"search": PACKAGE_SEARCHPROV,
"multi": PACKAGE_MULTI,
"webapp": PACKAGE_WEBAPP}
type_choices = {"any": constants.PACKAGE_ANY,
"extension": constants.PACKAGE_EXTENSION,
"theme": constants.PACKAGE_THEME,
"dictionary": constants.PACKAGE_DICTIONARY,
"languagepack": constants.PACKAGE_LANGUAGEPACK,
"search": constants.PACKAGE_SEARCH,
"multi": constants.PACKAGE_MULTI,
"webapp": constants.PACKAGE_WEBAPP}

# Parse the arguments that
parser = argparse.ArgumentParser(
Expand All @@ -30,7 +27,7 @@ def main():
parser.add_argument("-t",
"--type",
default="any",
choices=expectations.keys(),
choices=type_choices.keys(),
help="Type of addon you assume you're testing",
required=False)
parser.add_argument("-o",
Expand Down Expand Up @@ -98,17 +95,17 @@ def main():

# 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:
if args.type not in type_choices:
# Fail if the user provided invalid input.
print "Given expectation (%s) not valid. See --help for details" % \
args.type
sys.exit(1)

overrides = {}
if args.target_minversion:
overrides['targetapp_minVersion'] = json.loads(args.target_minversion)
overrides['targetapp_minVersion'] = json.loads(args.target_minversion)
if args.target_maxversion:
overrides['targetapp_maxVersion'] = json.loads(args.target_maxversion)
overrides['targetapp_maxVersion'] = json.loads(args.target_maxversion)

for_appversions = None
if args.for_appversions:
Expand All @@ -120,14 +117,14 @@ def main():
print "Invalid timeout. Integer expected."
sys.exit(1)

expectation = expectations[args.type]
expectation = type_choices[args.type]
error_bundle = validate(args.package,
format=None,
approved_applications=args.approved_applications,
determined=args.determined,
listed=not args.selfhosted,
overrides=overrides,
spidermonkey=SPIDERMONKEY_INSTALLATION,
spidermonkey=constants.SPIDERMONKEY_INSTALLATION,
for_appversions=for_appversions,
expectation=expectation,
timeout=timeout)
Expand Down
9 changes: 5 additions & 4 deletions validator/submain.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from validator.xpi import XPIManager
from validator import decorator

from constants import *
from constants import (PACKAGE_ANY, PACKAGE_EXTENSION, PACKAGE_SEARCHPROV,
PACKAGE_THEME, PACKAGE_WEBAPP)

types = {0: "Unknown",
1: "Extension/Multi-Extension",
Expand Down Expand Up @@ -158,7 +159,7 @@ def test_package(err, file_, name, expectation=PACKAGE_ANY,
if package.extension in assumed_extensions:
assumed_type = assumed_extensions[package.extension]
# Is the user expecting a different package type?
if not expectation in (PACKAGE_ANY, assumed_type):
if expectation not in (PACKAGE_ANY, assumed_type):
err.error(("main",
"test_package",
"unexpected_type"),
Expand Down Expand Up @@ -226,14 +227,14 @@ def _load_install_rdf(err, package, expectation):

# Compare the results of the low-level type detection to
# that of the expectation and the assumption.
if not expectation in (PACKAGE_ANY, results):
if expectation not in (PACKAGE_ANY, results):
err.warning(
err_id=("main", "test_package", "extension_type_mismatch"),
warning="Extension Type Mismatch",
description=("We detected that the add-on's type does not match "
"the expected type.",
'Type "%s" expected, found "%s"' %
(types[expectation], types[results])))
(types[expectation], types[results])))


def _load_package_json(err, package, expectation):
Expand Down
14 changes: 8 additions & 6 deletions validator/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

from . import constants
from .constants import PACKAGE_ANY
from errorbundler import ErrorBundle
import loader
from .errorbundler import ErrorBundle
# This is necessary. Do not remove it unless you know exactly what
# you are doing.
import loader # noqa
import submain


Expand Down Expand Up @@ -44,14 +46,14 @@ def validate(path, format="json",
Whether the app is headed for the app marketplace or AMO. Defaults to
`True`.
`expectation`:
The type of package that should be expected. Must be a symbolic constant
from validator.constants (i.e.: validator.constants.PACKAGE_*). Defaults
to PACKAGE_ANY.
The type of package that should be expected. Must be a symbolic
constant from validator.constants (i.e.:
validator.constants.PACKAGE_*). Defaults to PACKAGE_ANY.
`for_appversions`:
A dict of app GUIDs referencing lists of versions. Determines which
version-dependant tests should be run.
`timeout`:
Number of seconds before aborting addon validation, or -1 for to
Number of seconds before aborting addon validation, or -1 to
run with no timeout.
`compat_tests`:
A flag to signal the validator to skip tests which should not be run
Expand Down

0 comments on commit 7f123a2

Please sign in to comment.