示例#1
0
  def FromPythonFile(file_path):
    page_set_classes = []
    module = util.GetPythonPageSetModule(file_path)
    for m in dir(module):
      if m.endswith('PageSet') and m != 'PageSet':
        page_set_classes.append(getattr(module, m))
    if len(page_set_classes) != 1:
      raise PageSetError("Pageset file needs to contain exactly 1 pageset class"
                         " with prefix 'PageSet'")
    page_set = page_set_classes[0]()
    page_set.file_path = file_path
    for page in page_set.pages:
      page_class = page.__class__

      for method_name, method in inspect.getmembers(page_class,
                                                    predicate=inspect.ismethod):
        if method_name.startswith("Run"):
          args, _, _, _ = inspect.getargspec(method)
          if not (args[0] == "self" and args[1] == "action_runner"):
            raise PageSetError("""Definition of Run<...> method of all
pages in %s must be in the form of def Run<...>(self, action_runner):"""
                                     % file_path)
      # Set page's _base_dir attribute.
      page_file_path = sys.modules[page_class.__module__].__file__
      page._base_dir = os.path.dirname(page_file_path)

    page_set._Initialize() # pylint: disable=W0212
    return page_set
示例#2
0
def IsPageSetFile(file_path):
    root_name, ext_name = os.path.splitext(file_path)
    if 'unittest' in root_name or 'page_sets/data' in root_name:
        return False
    if ext_name != '.py':
        return False
    module = util.GetPythonPageSetModule(file_path)
    return bool(DiscoverClassesInModule(module, page_set.PageSet))
示例#3
0
def IsPageSetFile(file_path):
    root_name, ext_name = os.path.splitext(file_path)
    if ext_name == '.json':
        return True
    elif ext_name != '.py':
        return False
    if 'unittest' in root_name or root_name in ('PRESUBMIT', '__init__'):
        return False
    module = util.GetPythonPageSetModule(file_path)
    for class_name in dir(module):
        if class_name.endswith('PageSet') and class_name != 'PageSet':
            return True
    return False
示例#4
0
    def FromPythonFile(file_path):
        page_set_classes = []
        module = util.GetPythonPageSetModule(file_path)
        for m in dir(module):
            if m.endswith('PageSet') and m != 'PageSet':
                page_set_classes.append(getattr(module, m))
        if len(page_set_classes) != 1:
            raise PageSetError(
                "Pageset file needs to contain exactly 1 pageset class"
                " with suffix 'PageSet'")
        page_set = page_set_classes[0]()
        for page in page_set.pages:
            page_class = page.__class__

            for method_name, method in inspect.getmembers(
                    page_class, predicate=inspect.ismethod):
                if method_name.startswith("Run"):
                    args, _, _, _ = inspect.getargspec(method)
                    if not (args[0] == "self" and args[1] == "action_runner"):
                        raise PageSetError(
                            """Definition of Run<...> method of all
pages in %s must be in the form of def Run<...>(self, action_runner):""" %
                            file_path)
        return page_set