How to use the pkgcore.config.basics.HardCodedConfigSection function in pkgcore

To help you get started, we’ve selected a few pkgcore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pkgcore / pkgcore / tests / module / config / test_basics.py View on Github external
def test_section_ref(self):
        ref = basics.HardCodedConfigSection({})
        self.assertRaises(errors.ConfigurationError,
            basics.convert_asis, None, 42, 'ref:spoon')
        self.assertIdentical(
            ref, basics.convert_asis(None, ref, 'ref:spoon').section)
        self.assertEqual(
            ('ref', ref), basics.convert_asis(None, ref, 'repr'))
github pkgcore / pkgcore / tests / module / config / test_central.py View on Github external
def test_alias(self):
        def myspork():
            return object
        manager = central.ConfigManager(
            [{'spork': basics.HardCodedConfigSection({'class': myspork}),
              'foon': basics.section_alias('spork', 'myspork'),
              }])
        # This tests both the detected typename of foon and the caching.
        self.assertIdentical(manager.objects.myspork['spork'], manager.objects.myspork['foon'])
github pkgcore / pkgcore / tests / module / scripts / test_pconfig.py View on Github external
"        'foo' = 'bar'",
             '',
             '',
             '# type: list',
             "'seq' = 'a' 'b c'",
             '# type: str',
             "'str' = 'quote \\'\" unquote'",
             '',
             'spork',
             '=====',
             '# type: callable',
             "'class' = module.scripts.test_pconfigspork",
             '',
             ],
            spork=basics.HardCodedConfigSection({'class': spork}),
            foon=basics.HardCodedConfigSection({
                    'class': spork,
                    'inherit-only': True,
                    'refs': [
                        basics.HardCodedConfigSection({'crystal': 'clear'}),
                        WeirdSection(),
                        ],
                    'seq': ['a', 'b c'],
                    'str': 'quote \'" unquote',
                    }),
github pkgcore / pkgcore / tests / module / config / test_central.py View on Github external
def test_allow_unknowns(self):
        @configurable(allow_unknowns=True)
        def myrepo(**kwargs):
            return kwargs

        manager = central.ConfigManager(
            [{'spork': basics.HardCodedConfigSection({
                            'class': myrepo, 'spork': 'foon'})}])

        self.assertEqual(
            {'spork': 'foon'},
            manager.collapse_named_section('spork').instantiate())
github pkgcore / pkgcore / tests / module / scripts / test_pshowkw.py View on Github external
pkgcore_config_type = ConfigHint({}, typename='repo')

    def __init__(self, repo_id='faker', arches=('amd64', 'x86', 'arm', 'arm64')):
        config = RepoConfig('nonexistent')
        object.__setattr__(config, 'known_arches', frozenset(arches))
        pkgs = [
            FakePkg('app-arch/bzip2-1.0.1-r1', repo=self, data={'SLOT': '0'}, keywords=('x86',)),
            FakePkg('app-arch/bzip2-1.0.5-r2', repo=self, data={'SLOT': '0'}, keywords=('x86',)),
            FakePkg('sys-apps/coreutils-8.25', repo=self, data={'SLOT': '0'}),
            FakePkg('x11-libs/gtk+-2.24', repo=self, data={'SLOT': '2'}, keywords=('amd64',)),
            FakePkg('x11-libs/gtk+-3.20', repo=self, data={'SLOT': '3'}, keywords=('amd64', 'x86')),
        ]
        super().__init__(repo_id=repo_id, pkgs=pkgs, config=config)


domain_config = basics.HardCodedConfigSection({
    'class': FakeDomain,
    'repos': [basics.HardCodedConfigSection({'class': FakeRepo})],
    'default': True,
})


class TestCommandline(ArgParseMixin):

    _argparser = pshowkw.argparser

    def test_unknown_arches(self, capsys):
        fake_repo = FakeRepo()
        ns_kwargs = {'color': False, 'selected_repo': fake_repo}
        with pytest.raises(SystemExit):
            self.parse('-a', 'unknown', domain=domain_config, ns_kwargs=ns_kwargs)
        captured = capsys.readouterr()
github pkgcore / pkgcore / tests / module / config / test_central.py View on Github external
def test_autoload_uncollapsable(self):
        self.check_error(
            "Failed collapsing autoload section 'autoload_broken':\n"
            "Collapsing section named 'autoload_broken':\n"
            "Failed converting argument 'class' to callable:\n"
            "'spork' is not callable",
            central.ConfigManager, [{
                    'autoload_broken': basics.HardCodedConfigSection({
                            'class': 'spork'})}])
github pkgcore / pkgcore / tests / module / config / test_central.py View on Github external
def test_inherit_unknown_type(self):
        manager = central.ConfigManager(
            [{'baserepo': basics.HardCodedConfigSection({
                            'cache': 'available',
                            }),
              'actual repo': basics.HardCodedConfigSection({
                            'class': drawer,
                            'inherit': ['baserepo'],
                            }),
              }])
        self.check_error(
            "Collapsing section named 'actual repo':\n"
            "Type of 'cache' unknown",
            self.get_config_obj, manager, 'repo', 'actual repo')
github pkgcore / pkgcore / tests / module / scripts / test_pquery.py View on Github external
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_no_domain(self):
github pkgcore / pkgcore / tests / module / scripts / test_pconfig.py View on Github external
"'seq' = 'a' 'b c'",
             '# type: str',
             "'str' = 'quote \\'\" unquote'",
             '',
             'spork',
             '=====',
             '# type: callable',
             "'class' = module.scripts.test_pconfigspork",
             '',
             ],
            spork=basics.HardCodedConfigSection({'class': spork}),
            foon=basics.HardCodedConfigSection({
                    'class': spork,
                    'inherit-only': True,
                    'refs': [
                        basics.HardCodedConfigSection({'crystal': 'clear'}),
                        WeirdSection(),
                        ],
                    'seq': ['a', 'b c'],
                    'str': 'quote \'" unquote',
                    }),
github pkgcore / pkgcore / tests / module / config / test_central.py View on Github external
def test_pargs(self):
        @configurable(types={'p': 'str', 'notp': 'str'},
                      positional=['p'], required=['p'])
        def myrepo(*args, **kwargs):
            return args, kwargs
        manager = central.ConfigManager(
            [{'myrepo': basics.HardCodedConfigSection({
                            'class': myrepo,
                            'p': 'pos',
                            'notp': 'notpos',
                            }),
              }])

        self.assertEqual(
            manager.objects.myrepo['myrepo'], (('pos',), {'notp': 'notpos'}))