def main(argv=None): parser = argparse.ArgumentParser(description='List metric parsers') # optional options.add_color(parser) options.add_generate_config_filename(parser) parsed_args = parser.parse_args(argv) color_setting = parsed_args.color in ('always', 'auto') args = get_options_from_config(parsed_args.config_filename) metric_parsers = get_metric_parsers_from_args( args.metric_package_names, args.skip_default_metrics, ) metric_parsers_sorted = sorted( metric_parsers, key=lambda cls: cls.__module__ + cls.__name__, ) for metric_parser_cls in metric_parsers_sorted: print( '{} {}'.format( color(metric_parser_cls.__module__, CYAN, color_setting), metric_parser_cls.__name__, ), ) for name, description in metric_parser_cls().get_metrics_info(): description = ': {}'.format(description) if description else '' print(' {}{}'.format(name, description))
def main(argv: Optional[Sequence[str]] = None) -> int: parser = argparse.ArgumentParser(description='List metric parsers') # optional options.add_color(parser) options.add_generate_config_filename(parser) parsed_args = parser.parse_args(argv) color_setting = parsed_args.color in ('always', 'auto') args = get_options_from_config(parsed_args.config_filename) metric_parsers = get_metric_parsers_from_args( args.metric_package_names, args.skip_default_metrics, ) metric_parsers_sorted = sorted( metric_parsers, key=lambda cls: cls.__module__ + cls.__name__, ) for metric_parser_cls in metric_parsers_sorted: print( '{} {}'.format( color(metric_parser_cls.__module__, CYAN, color_setting), metric_parser_cls.__name__, ), ) for name, description in metric_parser_cls().get_metrics_info(): description = f': {description}' if description else '' print(f' {name}{description}') return 0
def test_fields_equivalent(tempdir_factory): tmpdir = tempdir_factory.get() config_filename = os.path.join(tmpdir, 'config.yaml') with io.open(config_filename, 'w') as config_file: config_file.write( 'repo: .\n' 'database: database.db\n' ) config_output = get_options_from_config([ '--config-filename', config_filename, ]) config_fields = set(config_output._fields) argparse_output = get_options_from_argparse(['.', 'database.db']) argparse_fields = set(vars(argparse_output)) # Assert that we got the same fields assert ( argparse_fields - set(('config_filename', 'create_config')) == config_fields ) # Assert that we got the same values for field in config_fields: assert getattr(config_output, field) == getattr(argparse_output, field)
def test_fields_equivalent(tempdir_factory): tmpdir = tempdir_factory.get() config_filename = os.path.join(tmpdir, 'config.yaml') with io.open(config_filename, 'w') as config_file: config_file.write( 'repo: .\n' 'database: database.db\n' ) config_output = get_options_from_config([ '--config-filename', config_filename, ]) # pylint:disable=no-member,protected-access config_fields = set(config_output._fields) argparse_output = get_options_from_argparse(['.', 'database.db']) argparse_fields = set(vars(argparse_output)) # Assert that we got the same fields assert ( argparse_fields - set(('config_filename', 'create_config')) == config_fields ) # Assert that we got the same values for field in config_fields: assert getattr(config_output, field) == getattr(argparse_output, field)
def test_get_options_from_config_create_config(tempdir_factory): tmpdir = tempdir_factory.get() with cwd(tmpdir): ret = get_options_from_config([ '--create-config', '.', 'database.db', ]) assert os.path.exists('generate_config.yaml') assert yaml.load(io.open('generate_config.yaml').read()) == { 'repo': '.', 'database': 'database.db', } assert ret == GenerateOptions( skip_default_metrics=False, metric_package_names=[], repo='.', database='database.db', )
def test_get_options_from_config_no_config_file(): with pytest.raises(SystemExit): get_options_from_config('i-dont-exist')
def test_get_options_from_config_no_config_file(): with pytest.raises(SystemExit): get_options_from_config(['--config-filename', 'i-dont-exist'])