diff --git a/python-scripts/metadatavalidator/src/metadatavalidator/checks/check_root.py b/python-scripts/metadatavalidator/src/metadatavalidator/checks/check_root.py
index 5979af2f2..008247a1a 100644
--- a/python-scripts/metadatavalidator/src/metadatavalidator/checks/check_root.py
+++ b/python-scripts/metadatavalidator/src/metadatavalidator/checks/check_root.py
@@ -21,3 +21,4 @@ def check_namespace(tree: etree._ElementTree, config: dict[t.Any, t.Any]):
tag = etree.QName(tree.getroot().tag)
if tag.namespace != DOCBOOK_NS:
raise InvalidValueError(f"Root element {tag.localname!r} doesn't belong to DocBook 5.")
+
diff --git a/python-scripts/metadatavalidator/src/metadatavalidator/config.py b/python-scripts/metadatavalidator/src/metadatavalidator/config.py
index d028bf5de..a96892750 100644
--- a/python-scripts/metadatavalidator/src/metadatavalidator/config.py
+++ b/python-scripts/metadatavalidator/src/metadatavalidator/config.py
@@ -155,15 +155,11 @@ def validate_valid_meta_architecture(config: dict) -> list[str]:
:param config: the configuration object
:return: a list of valid meta architecture
"""
- try:
- # architectures = re.split(r"[;,]", config.get("metadata", {}).get("valid_meta_architecture", []))
- return [x.strip() for x in re.split(r"[;,]",
+ return [x.strip() for x in re.split(r"[;,]",
config.get("metadata", {}).get("valid_meta_architecture", "")
)
if x
- ]
- except TypeError:
- raise MissingKeyError("metadata.valid_meta_architecture")
+ ]
def validate_valid_meta_category(config: dict) -> list[str]:
@@ -172,14 +168,11 @@ def validate_valid_meta_category(config: dict) -> list[str]:
:param config: the configuration object
:return: a list of valid meta category
"""
- try:
- return [x.strip() for x in re.split(r"[;,]",
+ return [x.strip() for x in re.split(r"[;,]",
config.get("metadata", {}).get("valid_meta_category", "")
)
if x
- ]
- except TypeError:
- raise MissingKeyError("metadata.valid_meta_category")
+ ]
def validate_and_convert_config(config: configparser.ConfigParser) -> dict[t.Any, t.Any]:
diff --git a/python-scripts/metadatavalidator/tests/unit/checks/test_check_info.py b/python-scripts/metadatavalidator/tests/unit/checks/test_check_info.py
index fbb9d9d16..fa6a79e88 100644
--- a/python-scripts/metadatavalidator/tests/unit/checks/test_check_info.py
+++ b/python-scripts/metadatavalidator/tests/unit/checks/test_check_info.py
@@ -2,7 +2,8 @@
from lxml import etree
from metadatavalidator.checks import (
- check_info, check_info_revhistory,
+ check_info,
+ check_info_revhistory,
check_info_revhistory_revision,
check_info_revhistory_revision_date,
check_info_revhistory_revision_order,
@@ -49,7 +50,7 @@ def test_check_info_revhistory_missing(xmlparser):
with pytest.raises(InvalidValueError,
match="Couldn't find a revhistory element"):
- check_info_revhistory(tree, {})
+ check_info_revhistory(tree, {"metadata": {"require_revhistory": True}})
def test_check_info_revhistory(xmlparser):
@@ -76,7 +77,6 @@ def test_check_info_revhistory_without_info(xmlparser):
)
assert check_info_revhistory(tree, {}) is None
- assert check_info_revhistory(tree, {}) is None
def test_check_info_revhistory_xmlid(xmlparser):
@@ -94,11 +94,11 @@ def test_check_info_revhistory_xmlid(xmlparser):
assert check_info_revhistory(tree, {}) is None
-def test_check_info_revhistory_missing_xmlid(xmlparser):
+def test_info_revhistory_missing_xmlid(xmlparser):
xmlcontent = """
Test
-
+
"""
@@ -169,20 +169,6 @@ def test_check_info_revhistory_revision_missing_xmlid(xmlparser):
{"metadata": {"require_xmlid_on_revision": True}})
-def test_check_info_revhistory_missing(xmlparser):
- xmlcontent = """
-
- Test
-
-
-"""
- tree = etree.ElementTree(
- etree.fromstring(xmlcontent, parser=xmlparser)
- )
-
- check_info_revhistory_revision(tree, {}) is None
-
-
def test_check_info_revhistory_revision_missing(xmlparser):
xmlcontent = """
@@ -334,3 +320,31 @@ def test_check_info_revhistory_revision_order_one_invalid_date(xmlparser):
match=".*Couldn't convert all dates.*see position dates=1.*"
):
check_info_revhistory_revision_order(tree, {})
+
+
+def test_check_info_revhistory_revision_wrong_order(xmlparser):
+ xmlcontent = """
+
+ Test
+
+
+ 2024-12
+
+
+ 2023-12-12
+
+
+ 2026-04
+
+
+
+
+"""
+ tree = etree.ElementTree(
+ etree.fromstring(xmlcontent, parser=xmlparser)
+ )
+
+ with pytest.raises(InvalidValueError,
+ match=".*Dates in revhistory/revision are not in descending order.*"
+ ):
+ check_info_revhistory_revision_order(tree, {})
\ No newline at end of file
diff --git a/python-scripts/metadatavalidator/tests/unit/checks/test_check_meta.py b/python-scripts/metadatavalidator/tests/unit/checks/test_check_meta.py
index c3e51ecce..bf6377dfe 100644
--- a/python-scripts/metadatavalidator/tests/unit/checks/test_check_meta.py
+++ b/python-scripts/metadatavalidator/tests/unit/checks/test_check_meta.py
@@ -422,4 +422,70 @@ def test_meta_category(xmlparser):
tree = etree.ElementTree(etree.fromstring(xmlcontent, parser=xmlparser))
config = dict(metadata=dict(require_meta_category=True,
valid_meta_category=["Systems Management"]))
- assert check_meta_category(tree, config) is None
\ No newline at end of file
+ assert check_meta_category(tree, config) is None
+
+
+def test_missing_optional_meta_category(xmlparser):
+ xmlcontent = """
+
+ Test
+
+
+"""
+ tree = etree.ElementTree(etree.fromstring(xmlcontent, parser=xmlparser))
+ config = dict(metadata=dict(require_meta_category=True))
+ with pytest.raises(InvalidValueError,
+ match=r".*Couldn't find required meta.*"):
+ check_meta_category(tree, config)
+
+
+def test_missing_child_meta_category(xmlparser):
+ xmlcontent = """
+
+ Test
+
+
+
+"""
+ tree = etree.ElementTree(etree.fromstring(xmlcontent, parser=xmlparser))
+ config = dict(metadata=dict(require_meta_category=True))
+ with pytest.raises(InvalidValueError,
+ match=r".*Couldn't find any child elements in meta.*"):
+ check_meta_category(tree, config)
+
+
+def test_duplicate_child_meta_category(xmlparser):
+ xmlcontent = """
+
+ Test
+
+ Systems Management
+ Systems Management
+
+
+
+"""
+ tree = etree.ElementTree(etree.fromstring(xmlcontent, parser=xmlparser))
+ config = dict(metadata=dict(require_meta_category=True))
+ with pytest.raises(InvalidValueError,
+ match=r".*Duplicate categories found in meta.*"):
+ check_meta_category(tree, config)
+
+
+def test_unknown_category_meta_category(xmlparser):
+ xmlcontent = """
+
+ Test
+
+ Systems Management
+ Foo
+
+
+
+"""
+ tree = etree.ElementTree(etree.fromstring(xmlcontent, parser=xmlparser))
+ config = dict(metadata=dict(require_meta_category=True,
+ valid_meta_category=["Systems Management"]))
+ with pytest.raises(InvalidValueError,
+ match=r".*Unknown category.*"):
+ check_meta_category(tree, config)
\ No newline at end of file
diff --git a/python-scripts/metadatavalidator/tests/unit/test_script_config.py b/python-scripts/metadatavalidator/tests/unit/test_script_config.py
index 6960d0cf2..59d94701d 100644
--- a/python-scripts/metadatavalidator/tests/unit/test_script_config.py
+++ b/python-scripts/metadatavalidator/tests/unit/test_script_config.py
@@ -58,6 +58,13 @@ def test_missing_validator_section():
validate_and_convert_config(config)
+def test_missing_metadata_section():
+ config = ConfigParser()
+ config.add_section("validator")
+ with pytest.raises(MissingSectionError, match=".*metadata.*"):
+ validate_and_convert_config(config)
+
+
def test_missing_key_check_root_elements(config):
config.remove_option("validator", "check_root_elements")
with pytest.raises(MissingKeyError, match=".*validator.check_root_elements.*"):