コード例 #1
0
ファイル: record_wpr.py プロジェクト: bbmjja8123/chromium-1
def Main(base_dir):
    measurements = discover.DiscoverClasses(base_dir, base_dir,
                                            page_measurement.PageMeasurement)
    options = browser_options.BrowserOptions()
    parser = options.CreateParser('%prog <page_set>')
    page_runner.AddCommandLineOptions(parser)

    recorder = RecordPage(measurements)
    recorder.AddCommandLineOptions(parser)
    recorder.AddOutputOptions(parser)

    _, args = parser.parse_args()

    if len(args) != 1:
        parser.print_usage()
        sys.exit(1)

    ps = page_set.PageSet.FromFile(args[0])

    # Set the archive path to something temporary.
    temp_target_wpr_file_path = tempfile.mkstemp()[1]
    ps.wpr_archive_info.AddNewTemporaryRecording(temp_target_wpr_file_path)

    # Do the actual recording.
    options.wpr_mode = wpr_modes.WPR_RECORD
    options.no_proxy_server = True
    recorder.CustomizeBrowserOptions(options)
    results = page_runner.Run(recorder, ps, options)

    if results.errors or results.failures:
        logging.warning(
            'Some pages failed. The recording has not been updated for '
            'these pages.')
        logging.warning('Failed pages:\n%s',
                        '\n'.join(zip(*results.errors + results.failures)[0]))

    if results.skipped:
        logging.warning('Some pages were skipped. The recording has not been '
                        'updated for these pages.')
        logging.warning('Skipped pages:\n%s',
                        '\n'.join(zip(*results.skipped)[0]))

    if results.successes:
        # Update the metadata for the pages which were recorded.
        ps.wpr_archive_info.AddRecordedPages(results.successes)
    else:
        os.remove(temp_target_wpr_file_path)

    return min(255, len(results.failures))
コード例 #2
0
    def ParseCommandLine(self, args, base_dir, page_set_filenames):
        # Need to collect profile creators before creating command line parser.
        profile_types.FindProfileCreators(base_dir, base_dir)

        self._options = browser_options.BrowserOptions()
        self._parser = self._options.CreateParser(
            '%%prog [options] %s page_set' % self.test_class_name)

        test_constructors = self.FindTestConstructors(base_dir)
        test_name = self.FindTestName(test_constructors, args)
        test = None
        if test_name:
            test = test_constructors[test_name]()
            if isinstance(test, test_module.Test):
                page_test = test.test()
            else:
                page_test = test
            page_test.AddOutputOptions(self._parser)
            page_test.AddCommandLineOptions(self._parser)
        page_runner.AddCommandLineOptions(self._parser)

        _, self._args = self._parser.parse_args()

        if len(self._args) < 1:
            error_message = 'No %s specified.\nAvailable %ss:\n' % (
                self.test_class_name, self.test_class_name)
            test_list_string = ',\n'.join(sorted(test_constructors.keys()))
            self.PrintParseError(error_message + test_list_string)

        if not test:
            error_message = 'No %s named %s.\nAvailable %ss:\n' % (
                self.test_class_name, self._args[0], self.test_class_name)
            test_list_string = ',\n'.join(sorted(test_constructors.keys()))
            self.PrintParseError(error_message + test_list_string)

        if isinstance(test, test_module.Test):
            ps = test.CreatePageSet(self._options)
            expectations = test.CreateExpectations(ps)
        else:
            ps = self.GetPageSet(test, page_set_filenames)
            expectations = test.CreateExpectations(ps)

        if len(self._args) > 2:
            self.PrintParseError('Too many arguments.')

        return page_test, ps, expectations
コード例 #3
0
def Main():
    profile_creators = _DiscoverProfileCreatorClasses()
    legal_profile_creators = '|'.join(profile_creators.keys())

    options = browser_options.BrowserFinderOptions()
    parser = options.CreateParser(
        "%%prog <--profile-type-to-generate=...> <--browser=...>"
        " <--output-directory>")
    page_runner.AddCommandLineOptions(parser)

    group = optparse.OptionGroup(parser, 'Profile generation options')
    group.add_option('--profile-type-to-generate',
                     dest='profile_type_to_generate',
                     default=None,
                     help='Type of profile to generate. '
                     'Supported values: %s' % legal_profile_creators)
    group.add_option('--output-dir',
                     dest='output_dir',
                     help='Generated profile is placed in this directory.')
    parser.add_option_group(group)

    _, _ = parser.parse_args()

    # Sanity check arguments.
    if not options.profile_type_to_generate:
        raise Exception("Must specify --profile-type-to-generate option.")

    if options.profile_type_to_generate not in profile_creators.keys():
        raise Exception("Invalid profile type, legal values are: %s." %
                        legal_profile_creators)

    if not options.browser_type:
        raise Exception("Must specify --browser option.")

    if not options.output_dir:
        raise Exception("Must specify --output-dir option.")

    if options.browser_options.dont_override_profile:
        raise Exception("Can't use existing profile when generating profile.")

    # Generate profile.
    profile_creator_class = profile_creators[options.profile_type_to_generate]
    return GenerateProfiles(profile_creator_class,
                            options.profile_type_to_generate, options)
コード例 #4
0
ファイル: test.py プロジェクト: MyAOSP/external_chromium_org
 def AddCommandLineOptions(parser):
   page_runner.AddCommandLineOptions(parser)
コード例 #5
0
def Main(base_dir):
    measurements = discover.DiscoverClasses(base_dir, base_dir,
                                            page_measurement.PageMeasurement)
    tests = discover.DiscoverClasses(base_dir,
                                     base_dir,
                                     test.Test,
                                     index_by_class_name=True)
    options = browser_options.BrowserFinderOptions()
    parser = options.CreateParser('%prog <PageSet|Measurement|Test|URL>')
    page_runner.AddCommandLineOptions(parser)

    recorder = RecordPage(measurements)
    recorder.AddCommandLineOptions(parser)

    _, args = parser.parse_args()

    if len(args) != 1:
        parser.print_usage()
        sys.exit(1)

    if args[0].endswith('.json'):
        ps = page_set.PageSet.FromFile(args[0])
    elif args[0] in tests:
        ps = tests[args[0]]().CreatePageSet(options)
    elif args[0] in measurements:
        ps = measurements[args[0]]().CreatePageSet(args, options)
    elif args[0].startswith('http'):
        ps = _CreatePageSetForUrl(args[0])
    else:
        parser.print_usage()
        sys.exit(1)

    expectations = test_expectations.TestExpectations()

    # Set the archive path to something temporary.
    temp_target_wpr_file_path = tempfile.mkstemp()[1]
    ps.wpr_archive_info.AddNewTemporaryRecording(temp_target_wpr_file_path)

    # Do the actual recording.
    options.browser_options.wpr_mode = wpr_modes.WPR_RECORD
    options.browser_options.no_proxy_server = True
    recorder.CustomizeBrowserOptions(options)
    results = page_runner.Run(recorder, ps, expectations, options)

    if results.errors or results.failures:
        logging.warning(
            'Some pages failed. The recording has not been updated for '
            'these pages.')
        logging.warning('Failed pages:\n%s',
                        '\n'.join(zip(*results.errors + results.failures)[0]))

    if results.skipped:
        logging.warning('Some pages were skipped. The recording has not been '
                        'updated for these pages.')
        logging.warning('Skipped pages:\n%s',
                        '\n'.join(zip(*results.skipped)[0]))

    if results.successes:
        # Update the metadata for the pages which were recorded.
        ps.wpr_archive_info.AddRecordedPages(results.successes)
    else:
        os.remove(temp_target_wpr_file_path)

    return min(255, len(results.failures))