Beispiel #1
0
def main(specification=None, values=None):
    # this won't be used in check-googlefonts
    add_spec_arg = False
    if specification is None:
        specification = get_spec()
        add_spec_arg = True
    argument_parser = ArgumentParser(specification, spec_arg=add_spec_arg)
    args = argument_parser.parse_args()
    runner = runner_factory(specification,
                            args.fonts,
                            explicit_tests=args.checkid,
                            custom_order=args.order,
                            values=values)

    # the most verbose loglevel wins
    loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL
    tr = TerminalReporter(runner=runner,
                          is_async=False,
                          print_progress=not args.no_progress,
                          test_threshold=loglevel,
                          log_threshold=args.loglevel_messages or loglevel,
                          usecolor=not args.no_colors,
                          collect_results_by=args.gather_by)
    reporters = [tr.receive]
    if args.json:
        sr = SerializeReporter(runner=runner,
                               collect_results_by=args.gather_by)
        reporters.append(sr.receive)
    distribute_generator(runner.run(), reporters)

    if args.json:
        import json
        json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)
Beispiel #2
0
def main(specification=None, values=None):
    # specification can be injected by e.g. check-googlefonts injects it's own spec
    add_spec_arg = False
    if specification is None:
        specification = get_spec()
        add_spec_arg = True

    argument_parser, values_keys = ArgumentParser(specification,
                                                  spec_arg=add_spec_arg)
    args = argument_parser.parse_args()

    if args.list_checks:
        for section_name, section in specification._sections.items():
            checks = section.list_checks()
            sys.exit("Available checks on {} are:\n{}".format(
                section_name, "\n".join(checks)))

    values_ = {}
    if values is not None:
        values_.update(values)

    # values_keys are returned by specification.setup_argparse
    # these are keys for custom arguments required by the spec.
    if values_keys:
        for key in values_keys:
            if hasattr(args, key):
                values_[key] = getattr(args, key)

    runner = runner_factory(specification,
                            explicit_checks=args.checkid,
                            custom_order=args.order,
                            values=values_)

    # the most verbose loglevel wins
    loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL
    tr = TerminalReporter(runner=runner,
                          is_async=False,
                          print_progress=not args.no_progress,
                          check_threshold=loglevel,
                          log_threshold=args.loglevel_messages or loglevel,
                          usecolor=not args.no_colors,
                          collect_results_by=args.gather_by)
    reporters = [tr.receive]
    if args.json:
        sr = SerializeReporter(runner=runner,
                               collect_results_by=args.gather_by)
        reporters.append(sr.receive)
    distribute_generator(runner.run(), reporters)

    if args.json:
        import json
        json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)
Beispiel #3
0
def main(profile=None, values=None):
    # profile can be injected by e.g. check-googlefonts injects it's own profile
    add_profile_arg = False
    if profile is None:
        profile = get_profile()
        add_profile_arg = True

    argument_parser, values_keys = ArgumentParser(profile,
                                                  profile_arg=add_profile_arg)
    args = argument_parser.parse_args()

    if args.list_checks:
        if args.loglevels == [PASS]:  # if verbose:
            from fontbakery.constants import WHITE_STR, CYAN_STR, BLUE_STR
            for section in profile._sections.values():
                print(WHITE_STR.format("\nSection:") + " " + section.name)
                for check in section._checks:
                    print(
                        CYAN_STR.format(check.id) + "\n" +
                        BLUE_STR.format(f'"{check.description}"') + "\n")
        else:
            for section_name, section in profile._sections.items():
                for check in section._checks:
                    print(check.id)
        sys.exit()

    values_ = {}
    if values is not None:
        values_.update(values)

    # values_keys are returned by profile.setup_argparse
    # these are keys for custom arguments required by the profile.
    if values_keys:
        for key in values_keys:
            if hasattr(args, key):
                values_[key] = getattr(args, key)

    try:
        runner = CheckRunner(profile,
                             values=values_,
                             custom_order=args.order,
                             explicit_checks=args.checkid,
                             exclude_checks=args.exclude_checkid)
    except ValueValidationError as e:
        print(e)
        argument_parser.print_usage()
        sys.exit(1)

    # The default Windows Terminal just displays the escape codes. The argument
    # parser above therefore has these options disabled.
    if sys.platform == "win32":
        args.no_progress = True
        args.no_colors = True

    # the most verbose loglevel wins
    loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL
    tr = TerminalReporter(runner=runner, is_async=False
                         , print_progress=not args.no_progress
                         , check_threshold=loglevel
                         , log_threshold=args.loglevel_messages or loglevel
                         , usecolor=not args.no_colors
                         , collect_results_by=args.gather_by
                         , skip_status_report=None if args.show_sections\
                                                        else (STARTSECTION, ENDSECTION)

                         )
    reporters = [tr.receive]

    if args.json:
        sr = SerializeReporter(runner=runner,
                               collect_results_by=args.gather_by)
        reporters.append(sr.receive)

    if args.ghmarkdown:
        mdr = GHMarkdownReporter(loglevels=args.loglevels,
                                 runner=runner,
                                 collect_results_by=args.gather_by)
        reporters.append(mdr.receive)

    if args.html:
        hr = HTMLReporter(loglevels=args.loglevels,
                          runner=runner,
                          collect_results_by=args.gather_by)
        reporters.append(hr.receive)

    distribute_generator(runner.run(), reporters)

    if args.json:
        import json
        json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)
        print("A report in JSON format has been"
              " saved to '{}'".format(args.json.name))

    if args.ghmarkdown:
        args.ghmarkdown.write(mdr.get_markdown())
        print("A report in GitHub Markdown format which can be useful\n"
              " for posting issues on a GitHub issue tracker has been\n"
              " saved to '{}'".format(args.ghmarkdown.name))

    if args.html:
        args.html.write(hr.get_html())
        print(f"A report in HTML format has been saved to '{args.html.name}'")

    # Fail and error let the command fail
    return 1 if tr.worst_check_status in (ERROR, FAIL) else 0
Beispiel #4
0
def main(profile=None, values=None):
    # profile can be injected by e.g. check-googlefonts injects it's own profile
    add_profile_arg = False
    if profile is None:
        profile = get_profile()
        add_profile_arg = True

    argument_parser, values_keys = ArgumentParser(profile,
                                                  profile_arg=add_profile_arg)
    args = argument_parser.parse_args()

    # The default Windows Terminal just displays the escape codes. The argument
    # parser above therefore has these options disabled.
    if sys.platform == "win32":
        args.no_progress = True
        args.no_colors = True

    theme = get_theme(args)
    # the most verbose loglevel wins
    loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL

    if args.list_checks:
        list_checks(profile, theme, verbose=loglevel > DEFAULT_LOG_LEVEL)

    values_ = {}
    if values is not None:
        values_.update(values)

    # values_keys are returned by profile.setup_argparse
    # these are keys for custom arguments required by the profile.
    if values_keys:
        for key in values_keys:
            if hasattr(args, key):
                values_[key] = getattr(args, key)

    if args.configfile:
        configuration = Configuration.from_config_file(args.configfile)
    else:
        configuration = Configuration()

    # Command line args overrides config, but only if given
    configuration.maybe_override(
        Configuration(custom_order=args.order,
                      explicit_checks=args.checkid,
                      exclude_checks=args.exclude_checkid))
    runner_kwds = dict(values=values_, config=configuration)
    try:
        runner = CheckRunner(profile, **runner_kwds)
    except ValueValidationError as e:
        print(e)
        argument_parser.print_usage()
        sys.exit(1)

    is_async = args.multiprocessing != 0

    tr = TerminalReporter(runner=runner, is_async=is_async
                         , print_progress=not args.no_progress
                         , succinct=args.succinct
                         , check_threshold=loglevel
                         , log_threshold=args.loglevel_messages or loglevel
                         , theme=theme
                         , collect_results_by=args.gather_by
                         , skip_status_report=None if args.show_sections \
                                                   else (SECTIONSUMMARY, )
                         )
    reporters = [tr]
    if "reporters" not in args:
        args.reporters = []

    for reporter_class, output_file in args.reporters:
        reporters.append(
            reporter_class(loglevels=args.loglevels,
                           runner=runner,
                           collect_results_by=args.gather_by,
                           output_file=output_file))

    if args.multiprocessing == 0:
        status_generator = runner.run()
    else:
        status_generator = multiprocessing_runner(args.multiprocessing, runner,
                                                  runner_kwds)

    distribute_generator(status_generator,
                         [reporter.receive for reporter in reporters])

    for reporter in reporters:
        reporter.write()

    # Fail and error let the command fail
    return 1 if tr.worst_check_status in (ERROR, FAIL) else 0
Beispiel #5
0
def main(profile=None, values=None):
    # profile can be injected by e.g. check-googlefonts injects it's own profile
    add_profile_arg = False
    if profile is None:
        profile = get_profile()
        add_profile_arg = True

    argument_parser, values_keys = ArgumentParser(profile,
                                                  profile_arg=add_profile_arg)
    args = argument_parser.parse_args()

    # The default Windows Terminal just displays the escape codes. The argument
    # parser above therefore has these options disabled.
    if sys.platform == "win32":
        args.no_progress = True
        args.no_colors = True

    from fontbakery.constants import NO_COLORS_THEME, DARK_THEME, LIGHT_THEME
    if args.no_colors:
        theme = NO_COLORS_THEME
    else:
        if args.light_theme:
            theme = LIGHT_THEME
        elif args.dark_theme:
            theme = DARK_THEME
        elif sys.platform == "darwin":
            # The vast majority of MacOS users seem to use a light-background on the text terminal
            theme = LIGHT_THEME
        else:
            # For orther systems like GNU+Linux and Windows, a dark terminal seems to be more common.
            theme = DARK_THEME

    if args.list_checks:
        if args.loglevels == [PASS]:  # if verbose:
            for section in profile._sections.values():
                print(theme["list-checks: section"]("\nSection:") + " " +
                      section.name)
                for check in section._checks:
                    print(theme["list-checks: check-id"](check.id) + "\n" +
                          theme["list-checks: description"]
                          (f'"{check.description}"') + "\n")
        else:
            for section_name, section in profile._sections.items():
                for check in section._checks:
                    print(check.id)
        sys.exit()

    values_ = {}
    if values is not None:
        values_.update(values)

    # values_keys are returned by profile.setup_argparse
    # these are keys for custom arguments required by the profile.
    if values_keys:
        for key in values_keys:
            if hasattr(args, key):
                values_[key] = getattr(args, key)

    runner_kwds = dict(values=values_,
                       custom_order=args.order,
                       explicit_checks=args.checkid,
                       exclude_checks=args.exclude_checkid)
    try:
        runner = CheckRunner(profile, **runner_kwds)
    except ValueValidationError as e:
        print(e)
        argument_parser.print_usage()
        sys.exit(1)

    is_async = args.multiprocessing != 0

    # the most verbose loglevel wins
    loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL
    tr = TerminalReporter(runner=runner, is_async=is_async
                         , print_progress=not args.no_progress
                         , succinct=args.succinct
                         , check_threshold=loglevel
                         , log_threshold=args.loglevel_messages or loglevel
                         , theme=theme
                         , collect_results_by=args.gather_by
                         , skip_status_report=None if args.show_sections \
                                                   else (SECTIONSUMMARY, )
                         )
    reporters = [tr.receive]

    if args.json:
        sr = SerializeReporter(runner=runner,
                               collect_results_by=args.gather_by)
        reporters.append(sr.receive)

    if args.ghmarkdown:
        mdr = GHMarkdownReporter(loglevels=args.loglevels,
                                 runner=runner,
                                 collect_results_by=args.gather_by)
        reporters.append(mdr.receive)

    if args.html:
        hr = HTMLReporter(loglevels=args.loglevels,
                          runner=runner,
                          collect_results_by=args.gather_by)
        reporters.append(hr.receive)

    if args.multiprocessing == 0:
        status_generator = runner.run()
    else:
        status_generator = multiprocessing_runner(args.multiprocessing, runner,
                                                  runner_kwds)

    distribute_generator(status_generator, reporters)

    if args.json:
        import json
        json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)
        print(f'A report in JSON format has been'
              f' saved to "{args.json.name}"')

    if args.ghmarkdown:
        args.ghmarkdown.write(mdr.get_markdown())
        print(f'A report in GitHub Markdown format which can be useful\n'
              f' for posting issues on a GitHub issue tracker has been\n'
              f' saved to "{args.ghmarkdown.name}"')

    if args.html:
        args.html.write(hr.get_html())
        print(f'A report in HTML format has been saved to "{args.html.name}"')

    # Fail and error let the command fail
    return 1 if tr.worst_check_status in (ERROR, FAIL) else 0
def main(specification=None, values=None):
    # specification can be injected by e.g. check-googlefonts injects it's own spec
    add_spec_arg = False
    if specification is None:
        specification = get_spec()
        add_spec_arg = True

    argument_parser, values_keys = ArgumentParser(specification,
                                                  spec_arg=add_spec_arg)
    args = argument_parser.parse_args()

    if args.list_checks:
        print('Available checks')
        for section_name, section in specification._sections.items():
            checks = section.list_checks()
            message = "# {}:\n  {}".format(section_name, "\n  ".join(checks))
            print(message)
        sys.exit()

    values_ = {}
    if values is not None:
        values_.update(values)

    # values_keys are returned by specification.setup_argparse
    # these are keys for custom arguments required by the spec.
    if values_keys:
        for key in values_keys:
            if hasattr(args, key):
                values_[key] = getattr(args, key)

    try:
        runner = runner_factory(specification,
                                explicit_checks=args.checkid,
                                exclude_checks=args.exclude_checkid,
                                custom_order=args.order,
                                values=values_)
    except ValueValidationError as e:
        print(e)
        argument_parser.print_usage()
        sys.exit(1)

    # The default Windows Terminal just displays the escape codes. The argument
    # parser above therefore has these options disabled.
    if sys.platform == "win32":
        args.no_progress = True
        args.no_colors = True

    # the most verbose loglevel wins
    loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL
    tr = TerminalReporter(runner=runner, is_async=False
                         , print_progress=not args.no_progress
                         , check_threshold=loglevel
                         , log_threshold=args.loglevel_messages or loglevel
                         , usecolor=not args.no_colors
                         , collect_results_by=args.gather_by
                         , skip_status_report=None if args.show_sections\
                                                        else (STARTSECTION, ENDSECTION)

                         )
    reporters = [tr.receive]

    if args.json:
        sr = SerializeReporter(runner=runner,
                               collect_results_by=args.gather_by)
        reporters.append(sr.receive)

    if args.ghmarkdown:
        mdr = GHMarkdownReporter(loglevels=args.loglevels,
                                 runner=runner,
                                 collect_results_by=args.gather_by)
        reporters.append(mdr.receive)

    distribute_generator(runner.run(), reporters)

    if args.json:
        import json
        json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)

    if args.ghmarkdown:
        args.ghmarkdown.write(mdr.get_markdown())

    # Fail and error let the command fail
    return 1 if tr.worst_check_status in (ERROR, FAIL) else 0
@register_test
@test(id='com.google.fonts/2', conditions=['not isOddFontName'])
def evenNameBiggerThanTwo(fontNameNumber):
    """Is the even fontname bigger than two?"""
    return PASS if fontNameNumber > 2 else FAIL, fontNameNumber


@register_test
@test(id='com.google.fonts/3')
def fontNameStartsWithFont_(font):
    """Fontname starts with "font_"."""
    test = 'font_2'
    for i in range(len(test)):
        if len(font) >= i and font[i] == test[i]:
            yield PASS, 'Char at index {} is "{}".'.format(i, test[i])
        else:
            yield FAIL, 'Char at index {} is not "{}" in "{}".'.format(
                i, test[i], font)
            1 / 0


if __name__ == '__main__':
    fonts = ['font_1', 'font_2', 'font_3', 'font_4']
    runner = TestRunner(specification, {'fonts': fonts})
    tr = TerminalReporter(runner=runner,
                          is_async=False,
                          print_progress=True,
                          collect_results_by='font')
    # sr = SerializeReporter(runner=runner, collect_results_by='font')
    distribute_generator(runner.run(), [tr.receive])  # sr.receive
        logging.warning("Skipping '{}' as it does not seem "
                        "to be valid TrueType font file.".format(fullpath))
  return fonts_to_check

if __name__ == '__main__':
  args = parser.parse_args()
  values = dict(fonts=get_fonts(args.arg_filepaths))
  runner = TestRunner(specification, values
                     , explicit_tests=args.checkid
                     , custom_order=args.order
                     )

  # the most verbose loglevel wins
  loglevel = min(args.loglevels) if args.loglevels else DEFAULT_LOG_LEVEL
  tr = TerminalReporter(runner=runner, is_async=False
                       , print_progress=not args.no_progress
                       , test_threshold=loglevel
                       , log_threshold=args.loglevel_messages or loglevel
                       , usecolor=not args.no_colors
                       , collect_results_by=args.gather_by
                       )
  reporters = [tr.receive]
  if args.json:
    sr = SerializeReporter(runner=runner, collect_results_by=args.gather_by)
    reporters.append(sr.receive)
  distribute_generator(runner.run(), reporters)

  if args.json:
    import json
    json.dump(sr.getdoc(), args.json, sort_keys=True, indent=4)