def _get_modules(self): """Gets modules given the repo paths passed in to init""" modules = [] error = False for repo in self.testrepos: # We're assuming only packages have __file__ attribute strings # that end with __init__.py (or .pyc). If this doesn't match # that pattern, assume it's a module. if "__init__.py" not in getattr(repo, "__file__", ""): modules.append(repo) continue # We're still in a package, so walk it and find the rest of the # modules. prefix = "{0}.".format(repo.__name__) for _, modname, is_pkg in pkgutil.walk_packages( path=repo.__path__, prefix=prefix, onerror=lambda x: None): if not is_pkg: try: modules.append(importlib.import_module(modname)) except Exception as exception: print_exception("Suite Builder", "import_module", modname, exception) error = True if self.exit_on_error and error: exit(get_error(exception)) return modules
def _get_modules(self): """Gets modules given the repo paths passed in to init""" modules = [] error = False for repo in self.testrepos: # We're assuming only packages have __file__ attribute strings # that end with __init__.py (or .pyc). If this doesn't match # that pattern, assume it's a module. if "__init__.py" not in getattr(repo, "__file__", ""): modules.append(repo) continue # We're still in a package, so walk it and find the rest of the # modules. prefix = "{0}.".format(repo.__name__) for _, modname, is_pkg in pkgutil.walk_packages( path=repo.__path__, prefix=prefix, onerror=lambda x: None): if not is_pkg: try: modules.append(importlib.import_module(modname)) except Exception as exception: print_exception( "Suite Builder", "import_module", modname, exception) error = True if self.exit_on_error and error: exit(get_error(exception)) return modules
def import_repos(repo_list): """Imports the repos passed in on the command line""" repos = [] for repo_name in repo_list: try: repos.append(importlib.import_module(repo_name)) except Exception as exception: print_exception("Runner", "import_repos", repo_name, exception) if len(repo_list) != len(repos): exit(get_error(exception)) return repos
def __call__(self, parser, namespace, value, option_string=None): dic = {} try: lines = open(value).readlines() for count, line in enumerate(lines): temp = line.replace(")", "").strip().split(" (") dic[temp[1]] = dic.get(temp[1], []) + [temp[0]] except IndexError as exception: parser.error("InputFileAction: Parsing of {0} failed: {1}".format(line, exception)) except IOError as exception: parser.error("InputFileAction: File open failed: {0}".format(exception)) exit(get_error(exception)) setattr(namespace, self.dest, dic)
def __call__(self, parser, namespace, value, option_string=None): dic = {} try: lines = open(value).readlines() for count, line in enumerate(lines): temp = line.replace(")", "").strip().split(" (") dic[temp[1]] = dic.get(temp[1], []) + [temp[0]] except IndexError as exception: parser.error("InputFileAction: Parsing of {0} failed: {1}".format( line, exception)) except IOError as exception: parser.error( "InputFileAction: File open failed: {0}".format(exception)) exit(get_error(exception)) setattr(namespace, self.dest, dic)
def _get_modules(self): """Gets modules given the repo paths passed in to init""" modules = [] error = False for repo in self.testrepos: if not repo.__file__.endswith("__init__.pyc"): modules.append(repo) continue prefix = "{0}.".format(repo.__name__) for _, modname, is_pkg in pkgutil.walk_packages( path=repo.__path__, prefix=prefix, onerror=lambda x: None): if not is_pkg: try: modules.append(importlib.import_module(modname)) except Exception as exception: print_exception("Suite Builder", "import_module", modname, exception) error = True if self.exit_on_error and error: exit(get_error(exception)) return modules
def _get_modules(self): """Gets modules given the repo paths passed in to init""" modules = [] error = False for repo in self.testrepos: if not repo.__file__.endswith("__init__.pyc"): modules.append(repo) continue prefix = "{0}.".format(repo.__name__) for _, modname, is_pkg in pkgutil.walk_packages( path=repo.__path__, prefix=prefix, onerror=lambda x: None): if not is_pkg: try: modules.append(importlib.import_module(modname)) except Exception as exception: print_exception( "Suite Builder", "import_module", modname, exception) error = True if self.exit_on_error and error: exit(get_error(exception)) return modules
def error(self, message): self.print_usage(sys.stderr) print_exception("Argument Parser", message) exit(get_error())