示例#1
0
    def test_update_modulemd_with_multiple_pairs_of_deps(self):
        """
        While uncommon, it's not impossible for there to be more than one
        Dependencies object in the list.
        """
        validate(yaml6_multiple_pairs_of_deps)
        mod1 = yaml.safe_load(yaml6_multiple_pairs_of_deps)
        self.assertEqual(len(mod1["data"]["dependencies"]), 2)

        dependencies = [
            {
                "buildrequires": {
                    "platform": ["-epel8"]
                },
                "requires": {
                    "platform": ["-epel8"]
                }
            },
            {
                "buildrequires": {
                    "libfoo": ["rolling"],
                    "platform": ["epel8"]
                },
                "requires": {
                    "libfoo": ["rolling"],
                    "platform": ["epel8"]
                }
            },
        ]
        self.assertEqual(mod1["data"]["dependencies"], dependencies)

        requires = {"foo": ["bar"]}
        with self.assertRaises(AttributeError) as context:
            update(yaml6_multiple_pairs_of_deps, requires=requires)
        self.assertIn(
            "Provided YAML contains multiple pairs of dependencies. "
            "It is ambiguous which one to update.", str(context.exception))

        buildrequires = {"baz": ["qux"]}
        with self.assertRaises(AttributeError) as context:
            update(yaml6_multiple_pairs_of_deps, buildrequires=buildrequires)
        self.assertIn(
            "Provided YAML contains multiple pairs of dependencies. "
            "It is ambiguous which one to update.", str(context.exception))

        result = update(yaml6_multiple_pairs_of_deps,
                        requires=requires,
                        buildrequires=buildrequires)
        mod2 = yaml.safe_load(result)
        self.assertEqual(len(mod2["data"]["dependencies"]), 1)
        self.assertEqual(mod2["data"]["dependencies"][0], {
            "requires": {
                "foo": ["bar"]
            },
            "buildrequires": {
                "baz": ["qux"]
            },
        })
示例#2
0
    def test_update_without_dependencies(self):
        """
        The logic for updating dependencies is a bit complicated and can fail
        when dependencies are not present in the modulemd YAML at all.
        """
        validate(yaml3_no_deps)
        mod1 = yaml.safe_load(yaml3_no_deps)
        self.assertNotIn("dependencies", mod1["data"])

        result = update(yaml3_no_deps, summary="Updated summary")
        mod2 = yaml.safe_load(result)
        self.assertEqual(mod2["data"]["summary"], "Updated summary")
        self.assertNotIn("dependencies", ["data"])

        result = update(yaml3_no_deps, requires={"foo": ["bar"]})
        mod3 = yaml.safe_load(result)
        self.assertEqual(mod3["data"]["dependencies"][0]["requires"],
                         {"foo": ["bar"]})
示例#3
0
 def test_validate_wrong_format(self):
     with self.assertRaises(RuntimeError) as context:
         validate("this is not yaml")
     self.assertIsInstance(context.exception, RuntimeError)
     self.assertIn("Unexpected YAML event in document stream",
                   str(context.exception))
示例#4
0
 def test_validate(self):
     self.assertTrue(validate(yaml1))
     with self.assertRaises(Exception) as context:
         validate(yaml2_invalid)
     self.assertIn("The module and stream names are required",
                   str(context.exception))