Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_list_merging():
"""
Load two configs and check we loaded up in proper older with
replacing based on TOML syntax
"""
cfg = Config(TEST_LIST1)
assert len(cfg.configuration['Filters']) == 1
assert cfg.configuration['ValidGroups'][0] == 'bullshitgroup'
cfg.load_config(TEST_LIST2)
assert len(cfg.conf_files) == 3
assert len(cfg.configuration['Filters']) == 1
assert len(cfg.configuration['ValidGroups']) == 1
assert cfg.configuration['ValidGroups'][0] == 'System/Libraries'
def test_filters():
"""
Load some filters and make sure we generate nice regexp
"""
cfg = Config(TEST_CONFIG_FILTERS)
assert len(cfg.configuration['Filters']) == 7
assert cfg.configuration['Filters'][0] == '.*invalid-buildhost.*'
def test_broken_config(capsys):
cfg = Config(TEST_BROKEN)
out, err = capsys.readouterr()
assert 'error parsing configuration' in err
assert cfg.conf_files
assert len(cfg.conf_files) == 1
def test_description_from_toml(tmpdir):
"""
Test if description loaded from toml shows up details
"""
cfg = Config(TEST_CONFIG_FILTERS)
result = Filter(cfg)
assert result.get_description('uncompressed-zip')
assert result.get_description('uncompressed-zip') == 'The zip file is not compressed.\n\n'
def test_filters_regexp():
"""
Load some filters and make sure we generate nice regexp
"""
cfg = Config(TEST_CONFIG_FILTERS)
result = Filter(cfg)
assert len(cfg.configuration['Filters']) == 7
assert cfg.configuration['Filters'][0] == '.*invalid-buildhost.*'
assert isinstance(result.filters_re, Pattern)
def test_custom_config(capsys):
cfg = Config()
# bullshit config
cfg.find_configs(Path('BULLSHIT'))
out, err = capsys.readouterr()
assert Path('BULLSHIT') not in cfg.conf_files
assert 'BULLSHIT' in err
# existing config
cfg.find_configs(TEST_CONFIG)
out, err = capsys.readouterr()
assert cfg.conf_files
assert not err
def test_printing(capsys):
cfg = Config()
cfg.print_config()
out, err = capsys.readouterr()
assert not err
assert out
def test_data_storing(tmpdir):
"""
Load some filters and make sure we generate nice regexp
"""
cfg = Config(TEST_CONFIG_FILTERS)
cfg.load_rpmlintrc(TEST_RPMLINTRC)
result = Filter(cfg)
pkg = get_tested_package(TEST_PACKAGE, tmpdir)
# this should be upgraded to error
result.add_info('I', pkg, 'suse-other-error', '')
assert len(result.results) == 1
assert result.printed_messages['I'] == 0
assert result.printed_messages['E'] == 1
# this should be downgraded
result.add_info('E', pkg, 'suse-dbus-unauthorized-service', '')
assert len(result.results) == 2
assert result.printed_messages['W'] == 1
assert result.printed_messages['E'] == 1
])
except getopt.GetoptError as e:
print_warning('%s: %s' % (argv0, e))
usage(argv0)
sys.exit(1)
# process options
checks = []
verbose = False
extract_dir = None
info_error = set()
config_overrides = {}
# load global config files
cfg = Config()
extract_dir = cfg.configuration['ExtractDir']
# process command line options
for o in opt:
if o[0] in ('-c', '--check'):
checks.append(o[1])
elif o[0] in ('-i', '--info'):
cfg.info = True
elif o[0] in ('-I', '--explain'):
# split by comma for deprecated backwards compatibility with < 1.2
info_error.update(o[1].split(','))
elif o[0] in ('-h', '--help'):
usage(argv0)
sys.exit(0)
elif o[0] in ('-v', '--verbose'):
verbose = True
def __init__(self, options):
# initialize configuration
self.checks = {}
self.options = options
self.packages_checked = 0
self.specfiles_checked = 0
if options['config']:
self.config = Config(options['config'])
else:
self.config = Config()
self._load_rpmlintrc()
if options['verbose']:
self.config.info = options['verbose']
if options['strict']:
self.config.strict = options['strict']
if options['permissive']:
self.config.permissive = options['permissive']
if not self.config.configuration['ExtractDir']:
self.config.configuration['ExtractDir'] = gettempdir()
# initialize output buffer
self.output = Filter(self.config)
# preload the check list
self.load_checks()