コード例 #1
0
ファイル: defaults.py プロジェクト: zhang3125/libmodulemd
    def test_constructors(self):
        # Test that the new() function works
        defs = Modulemd.Defaults.new(Modulemd.DefaultsVersionEnum.ONE, "foo")
        assert defs

        assert defs.props.mdversion == Modulemd.DefaultsVersionEnum.ONE
        assert defs.get_mdversion() == Modulemd.DefaultsVersionEnum.ONE

        assert defs.props.module_name == "foo"
        assert defs.get_module_name() == "foo"

        # Test that we cannot instantiate directly
        with self.assertRaisesRegexp(TypeError,
                                     "cannot create instance of abstract"):
            Modulemd.Defaults()

        # Test with a zero mdversion
        with self.assertRaisesRegexp(TypeError, "constructor returned NULL"):
            with self.expect_signal():
                defs = Modulemd.Defaults.new(0, "foo")

        # Test with an unknown mdversion
        with self.assertRaisesRegexp(TypeError, "constructor returned NULL"):
            with self.expect_signal():
                defs = Modulemd.Defaults.new(
                    Modulemd.DefaultsVersionEnum.LATEST + 1, "foo")

        # Test with no name
        with self.assertRaisesRegexp(TypeError,
                                     "does not allow None as a value"):
            defs = Modulemd.Defaults.new(Modulemd.DefaultsVersionEnum.ONE,
                                         None)
コード例 #2
0
ファイル: test_modules.py プロジェクト: sshyran/dnf
    def test_find_module_version(self):
        rmd = RepoModuleDict(None)

        mmd = self._create_mmd(name="module-name", stream="stream", version=1,
                               profiles={"default": {}})
        rmv = RepoModuleVersion(mmd, None, None)
        rmd.add(rmv)

        mmd = self._create_mmd(name="module-name", stream="stream", version=2,
                               profiles={"default": {}})
        rmv = RepoModuleVersion(mmd, None, None)
        rmd.add(rmv)

        mmd = self._create_mmd(name="module-name", stream="enabled_stream", version=1,
                               profiles={"default": {}})
        rmv = RepoModuleVersion(mmd, None, None)
        rmd.add(rmv)

        mmd = self._create_mmd(name="module-name", stream="default_stream", version=1,
                               profiles={"default": {}})
        rmv = RepoModuleVersion(mmd, None, None)
        rmd.add(rmv)

        # set defaults
        defaults = Modulemd.Defaults()
        defaults.set_module_name("module-name")
        defaults.set_default_stream("stream")
        # no default profiles provided
        rmd["module-name"].defaults = defaults

        # no default, no active -> can't find stream automatically
        rmv = rmd.find_module_version(name="module-name")
        self.assertEqual(rmv.full_version, "module-name:stream:2")

        # set enabled stream
        conf = dnf.conf.ModuleConf(section="test")
        conf.state._set("enabled")
        conf.stream._set("enabled_stream")
        rmd["module-name"].conf = conf

        # stream provided by user
        rmv = rmd.find_module_version(name="module-name", stream="stream")
        self.assertEqual(rmv.full_version, "module-name:stream:2")

        # stream and version provided by user
        rmv = rmd.find_module_version(name="module-name", stream="stream", version=1)
        self.assertEqual(rmv.full_version, "module-name:stream:1")

        # stream == active stream
        rmv = rmd.find_module_version(name="module-name")
        self.assertEqual(rmv.full_version, "module-name:enabled_stream:1")

        # stream == default stream
        conf.state._set("")
        rmv = rmd.find_module_version(name="module-name")
        self.assertEqual(rmv.full_version, "module-name:stream:2")
コード例 #3
0
    def test_construction(self):
        defaults = Modulemd.Defaults()
        defaults.set_version(1)
        defaults.set_module_name("foo")
        defaults.set_default_stream("stable")
        defaults.set_profiles_for_stream("stable", ['default'])

        intent = Modulemd.Intent.new('server')
        intent.set_default_stream('stable')
        intent.set_profiles_for_stream('stable', ['server', 'microservice'])
        intent.set_profiles_for_stream('PoC', ['cloud', 'microservice'])
        defaults.add_intent(intent)

        assert 'server' in defaults.props.intents
        assert 'server' in defaults.props.intents[
            'server'].props.profile_defaults['stable'].dup()
        assert 'microservice' in defaults.props.intents[
            'server'].props.profile_defaults['stable'].dup()
        assert 'cloud' in defaults.props.intents[
            'server'].props.profile_defaults['PoC'].dup()
        assert 'microservice' in defaults.props.intents[
            'server'].props.profile_defaults['PoC'].dup()
コード例 #4
0
ファイル: repo_module.py プロジェクト: stefb965/dnf
 def defaults(self):
     if self._defaults is None:
         self._defaults = Modulemd.Defaults()
         self._defaults.set_module_name(self.name)
         # default stream and profiles remain unset
     return self._defaults