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_parser(self):
self.assertError(
'the following arguments are required: target',
'spork')
self.assertError(
"argument source: couldn't find cache 'spork'",
'spork', 'spork2')
self.assertError(
"argument target: couldn't find cache 'spork2' (available: spork)",
'spork', 'spork2',
spork=basics.HardCodedConfigSection({'class': Cache}))
self.assertError(
"argument target: cache 'spork2' is readonly",
'spork', 'spork2',
spork=basics.HardCodedConfigSection({'class': Cache,}),
spork2=basics.HardCodedConfigSection({'class': Cache,}))
def test_load_config(self):
manager = load_config(user_conf_file=self.user_config.name)
self.assertEqual(manager.foo['foo'], ((), {}))
# Test user config overrides system config.
manager = load_config(
user_conf_file=self.user_config.name,
system_conf_file=self.system_config.name)
self.assertEqual(manager.foo['foo'], ((), {}))
# Test prepends.
manager = load_config(
user_conf_file=self.user_config.name,
prepend_sources=[{'myfoo': basics.HardCodedConfigSection({
'inherit': ['foo']})}])
self.assertEqual(manager.foo['myfoo'], ((), {}))
# Test disabling loading.
manager = load_config(
user_conf_file=self.user_config.name,
skip_config_files=True)
self.assertRaises(
KeyError,
operator.getitem, manager.foo, 'foo')
object.__init__(self)
self.source_repos = repos
self.installed_repos = vdb
@configurable(typename='repo')
def fake_repo():
return util.SimpleTree({'spork': {'foon': ('1', '2')}})
@configurable(typename='repo')
def fake_vdb():
return util.SimpleTree({})
domain_config = basics.HardCodedConfigSection({
'class': FakeDomain,
'repos': [basics.HardCodedConfigSection({'class': fake_repo})],
'vdb': [basics.HardCodedConfigSection({'class': fake_vdb})],
'default': True,
})
class CommandlineTest(TestCase, ArgParseMixin):
_argparser = pquery.argparser
def test_parser(self):
self.assertError(
'argument --min: not allowed with argument --max',
'--max', '--min')
self.parse('--all', domain=domain_config)
def test_alias(self):
def spoon():
"""Noop."""
foon = central.CollapsedConfig(basics.ConfigType(spoon), {}, None)
class MockManager:
def collapse_named_section(self, name):
if name == 'foon':
return foon
return object()
manager = MockManager()
alias = basics.section_alias('foon', 'spoon')
type_obj = basics.ConfigType(alias.render_value(manager, 'class',
'callable'))
self.assertEqual('spoon', type_obj.name)
self.assertIdentical(
foon,
alias.render_value(manager, 'target', 'ref:spoon').collapse())
def test_parser(self):
self.assertError(
'the following arguments are required: target',
'spork')
self.assertError(
"argument source: couldn't find cache 'spork'",
'spork', 'spork2')
self.assertError(
"argument target: couldn't find cache 'spork2' (available: spork)",
'spork', 'spork2',
spork=basics.HardCodedConfigSection({'class': Cache}))
self.assertError(
"argument target: cache 'spork2' is readonly",
'spork', 'spork2',
spork=basics.HardCodedConfigSection({'class': Cache,}),
spork2=basics.HardCodedConfigSection({'class': Cache,}))
def my_convert_hybrid(manager, val, arg_type):
"""Modified convert_hybrid using a sequence of strings for section_refs."""
if arg_type.startswith('refs:'):
subtype = 'ref:' + arg_type.split(':', 1)[1]
return [basics.LazyNamedSectionRef(manager, subtype, name) for name in val]
return basics.convert_hybrid(manager, val, arg_type)
def describe_class_main(options, out, err):
"""Describe the arguments a class needs."""
try:
type_obj = basics.ConfigType(options.target_class)
except errors.TypeDefinitionError:
err.write('Not a valid type!')
return 1
write_type(out, type_obj)
def _compat_mangle_config(self, config):
if hasattr(config, 'sections'):
return config
return basics.GeneratedConfigSource(config, "unknown")
_section_contents = pyp.dictOf(
_value, pyp.Group(pyp.OneOrMore(_value | _section)) + pyp.Suppress(';'))
# "statement seems to have no effect"
# pylint: disable-msg=W0104
_section << pyp.Group(pyp.Suppress('{') + _section_contents +
pyp.Suppress('}'))
parser = (
pyp.stringStart +
pyp.dictOf(_value, _section).ignore(pyp.pythonStyleComment) +
pyp.stringEnd)
class ConfigSection(basics.ConfigSection):
"""Expose a section_contents from pyparsing as a ConfigSection.
mke2fsformat also uses this.
"""
def __init__(self, section):
super().__init__()
self.section = section
def __contains__(self, name):
return name in self.section
def keys(self):
return list(self.section.keys())
def render_value(self, central, name, arg_type):
from pkgcore.config import basics
from pkgcore.ebuild import (
portage_conf, repository as ebuild_repo, profiles, domain, eclass_cache,
overlay_repository, formatter)
from pkgcore.pkgsets import system, filelist, installed, glsa
from pkgcore.vdb import ondisk
from pkgcore.cache import flat_hash, metadata
from pkgcore.fetch import custom
from pkgcore.binpkg import repository as binpkg_repo
from pkgcore.sync import rsync, base
pkgcore_plugins = {
'configurable': [
basics.section_alias,
basics.parse_config_file,
portage_conf.SecurityUpgradesViaProfile,
portage_conf.config_from_make_conf,
system.SystemSet,
ondisk.tree,
flat_hash.database,
metadata.database,
metadata.paludis_flat_list,
custom.fetcher,
binpkg_repo.tree,
ebuild_repo.UnconfiguredTree,
ebuild_repo.SlavedTree,
profiles.OnDiskProfile,
domain.domain,
eclass_cache.cache,
eclass_cache.StackedCaches,