diff --git a/packtools/sps/validation/article_abstract.py b/packtools/sps/validation/article_abstract.py index 87f4942ff..a3d9493d2 100644 --- a/packtools/sps/validation/article_abstract.py +++ b/packtools/sps/validation/article_abstract.py @@ -1,4 +1,8 @@ -from packtools.sps.models.article_abstract import ArticleVisualAbstracts, ArticleHighlights, ArticleAbstract +from packtools.sps.models.article_abstract import ( + ArticleVisualAbstracts, + ArticleHighlights, + ArticleAbstract, +) from packtools.sps.validation.utils import format_response @@ -32,7 +36,7 @@ def validate_unexpected_kwd(self, error_level="ERROR"): validation_type="exist", obtained=self.abstract.get("kwds"), advice=f"Remove keywords () from ", - error_level=error_level + error_level=error_level, ) def validate_tag_title_in_abstract(self, error_level="ERROR"): @@ -53,11 +57,20 @@ def validate_tag_title_in_abstract(self, error_level="ERROR"): is_valid=False, expected="title", advice="Provide title", - error_level=error_level + error_level=error_level, ) - def _format_response(self, title, sub_item, is_valid, validation_type, expected=None, obtained=None, advice=None, - error_level='WARNING'): + def _format_response( + self, + title, + sub_item, + is_valid, + validation_type, + expected=None, + obtained=None, + advice=None, + error_level="WARNING", + ): """ Formats the validation response. @@ -88,7 +101,7 @@ def _format_response(self, title, sub_item, is_valid, validation_type, expected= obtained=obtained, advice=advice, data=self.abstract, - error_level=error_level + error_level=error_level, ) @@ -101,38 +114,62 @@ class AbstractsValidationBase: abstracts (list): List of abstracts to be validated. """ - def __init__(self, xml_tree, abstracts): + def __init__(self, xml_tree): self.xml_tree = xml_tree - # this is a list of dictionaries with abstract data - self.abstracts = abstracts - - def validate_exists(self, error_level="WARNING"): - """ - Validates if the article contains any abstracts. - - Args: - error_level (str): Error level to be reported. Default is "WARNING". - - Returns: - dict: Formatted validation response if no abstracts are found. - """ - if not self.abstracts: - return format_response( - title="Article abstracts", - parent="article", - parent_id=None, - parent_article_type=self.xml_tree.get("id"), - parent_lang=self.xml_tree.get("{http://www.w3.org/XML/1998/namespace}lang"), - item="abstract", - sub_item=None, - validation_type="exist", - is_valid=False, - expected="abstracts", - obtained=self.abstracts, - advice="article has no abstract", - data=None, - error_level=error_level + self.article_type = xml_tree.find(".").get("article-type") + self.lang = xml_tree.get("{http://www.w3.org/XML/1998/namespace}lang") + + def validate_exists( + self, + article_type_requires, + article_type_unexpects, + article_type_neutral, + article_type_accepts, + ): + data = self.abstracts + obtained = self.abstracts + error_level = "INFO" + is_valid = True + + if self.article_type in article_type_requires: + expected = f"{self.abstract_title} is required" + if not self.abstracts: + is_valid = False + error_level = "CRITICAL" + advice = f"It is required that documents which article-type={self.article_type} have {self.abstract_title}. Check if article-type is correct." + elif self.article_type in article_type_unexpects: + expected = f"{self.abstract_title} is unexpected" + if self.abstracts: + is_valid = False + error_level = "CRITICAL" + advice = f"It is unexpected that documents which article-type={self.article_type} have {self.abstract_title}. Check if article-type is correct." + elif self.article_type in article_type_neutral: + expected = f"{self.abstract_title} is not required and not unexpected" + advice = None + elif self.article_type in article_type_accepts: + expected = f"{self.abstract_title} is acceptable" + advice = None + error_level = "INFO" + else: + raise ValueError( + f"Unable to identify if {self.abstract_title} is required or unexpected or neutral or acceptable" ) + return format_response( + title=self.abstract_title, + parent="article", + parent_id=None, + parent_article_type=self.article_type, + parent_lang=self.lang, + item=self.abstract_title, + sub_item=None, + validation_type="exist", + is_valid=is_valid, + expected=expected, + obtained=obtained, + advice=advice, + data=data, + error_level=error_level, + ) class HighlightValidation(AbstractValidationBase): @@ -156,9 +193,9 @@ def validate_tag_list_in_abstract(self, error_level="ERROR"): sub_item="list", validation_type="exist", is_valid=False, - obtained=self.abstract.get('list'), + obtained=self.abstract.get("list"), advice="Remove and add

", - error_level=error_level + error_level=error_level, ) def validate_tag_p_in_abstract(self, error_level="ERROR"): @@ -180,7 +217,7 @@ def validate_tag_p_in_abstract(self, error_level="ERROR"): expected="p", obtained=self.abstract.get("highlights"), advice="Provide more than one p", - error_level=error_level + error_level=error_level, ) @@ -191,11 +228,17 @@ class HighlightsValidation(AbstractsValidationBase): def __init__(self, xml_tree): # this is a list of dictionaries with highlight abstract data + super().__init__(xml_tree) self.abstracts = list(ArticleHighlights(xml_tree).article_abstracts()) - super().__init__(xml_tree, self.abstracts) - - def validate(self, kwd_error_level="ERROR", title_error_level="ERROR", p_error_level="ERROR", - list_error_level="ERROR"): + self.abstract_title = "abstracts (key-points)" + + def validate( + self, + kwd_error_level="ERROR", + title_error_level="ERROR", + p_error_level="ERROR", + list_error_level="ERROR", + ): """ Runs the validation checks for keywords, title, paragraph, and list tags in highlights. @@ -239,7 +282,7 @@ def validate_tag_graphic_in_abstract(self, error_level="ERROR"): is_valid=False, expected="graphic", advice="Provide graphic", - error_level=error_level + error_level=error_level, ) @@ -250,10 +293,16 @@ class VisualAbstractsValidation(AbstractsValidationBase): def __init__(self, xml_tree): # this is a list of dictionaries with visual abstract data + super().__init__(xml_tree) self.abstracts = list(ArticleVisualAbstracts(xml_tree).article_abstracts()) - super().__init__(xml_tree, self.abstracts) - - def validate(self, kwd_error_level="ERROR", title_error_level="ERROR", graphic_error_level="ERROR"): + self.abstract_title = "abstracts (graphical)" + + def validate( + self, + kwd_error_level="ERROR", + title_error_level="ERROR", + graphic_error_level="ERROR", + ): """ Runs the validation checks for keywords, title, and graphic tags in visual abstracts. @@ -272,6 +321,20 @@ def validate(self, kwd_error_level="ERROR", title_error_level="ERROR", graphic_e yield validations.validate_tag_graphic_in_abstract(graphic_error_level) +class AbstractsValidation(AbstractsValidationBase): + """ + Standard abstracts validation + """ + + def __init__(self, xml_tree): + # this is a list of dictionaries with highlight abstract data + super().__init__(xml_tree) + self.abstracts = list( + ArticleAbstract(xml_tree, selection="standard").get_abstracts() + ) + self.abstract_title = "standard abstracts" + + class ArticleAbstractsValidation: """ Class to validate various types of abstracts in an article. @@ -282,9 +345,14 @@ class ArticleAbstractsValidation: def __init__(self, xml_tree): # this is a list of dictionaries with abstract data - self.abstracts = list(ArticleAbstract(xml_tree, selection="all").get_abstracts()) + self.xml_tree = xml_tree + self.abstracts = list( + ArticleAbstract(xml_tree, selection="all").get_abstracts() + ) - def validate_abstracts_type(self, error_level="ERROR", expected_abstract_type_list=None): + def validate_abstracts_type( + self, error_level="ERROR", expected_abstract_type_list=None + ): """ Validates if the abstract types are within an expected list of types. @@ -298,18 +366,18 @@ def validate_abstracts_type(self, error_level="ERROR", expected_abstract_type_li for abstract in self.abstracts: if abstract.get("abstract_type") not in (expected_abstract_type_list or []): yield format_response( - title="abstract-type attribute", + title="@abstract-type", parent=abstract.get("parent"), parent_id=abstract.get("parent_id"), parent_article_type=abstract.get("parent_article_type"), parent_lang=abstract.get("parent_lang"), item="abstract", - sub_item='@abstract-type', + sub_item="@abstract-type", validation_type="value in list", is_valid=False, - expected=' or ', - obtained=f'', - advice='Provide or ', + expected=expected_abstract_type_list, + obtained=abstract.get("abstract_type"), + advice=f"Use one of {expected_abstract_type_list} as abstract-type", data=abstract, - error_level=error_level + error_level=error_level, ) diff --git a/packtools/sps/validation/xml_validations.py b/packtools/sps/validation/xml_validations.py index 1d27eb740..b05cca663 100644 --- a/packtools/sps/validation/xml_validations.py +++ b/packtools/sps/validation/xml_validations.py @@ -77,12 +77,16 @@ def validate_abstracts(xmltree, params): expected_abstract_type_list=abstract_rules["abstract_type_list"], ) - # FIXME - # yield from validator.validate_exists( - # error_level=abstract_rules["abstract_presence_error_level"], - # ) + validator = AbstractsValidation(xmltree) + yield from validator.validate_exists( + article_type_requires=abstract_rules["article_type_requires"], + article_type_unexpects=abstract_rules["article_type_unexpects"], + article_type_neutral=abstract_rules["article_type_neutral"], + article_type_accepts=[] + ) highlight_rules = params["highlight_rules"] + validator = HighlightsValidation(xmltree) yield from validator.validate( kwd_error_level=highlight_rules["kwd_error_level"], @@ -90,14 +94,27 @@ def validate_abstracts(xmltree, params): p_error_level=highlight_rules["p_error_level"], list_error_level=highlight_rules["list_error_level"], ) + yield validator.validate_exists( + article_type_requires=[], + article_type_unexpects=highlight_rules["article_type_unexpects"], + article_type_neutral=highlight_rules["article_type_neutral"], + article_type_accepts=highlight_rules["article_type_accepts"] + ) graphical_abstract_rules = params["graphical_abstract_rules"] + validator = VisualAbstractsValidation(xmltree) yield from validator.validate( kwd_error_level=graphical_abstract_rules["kwd_error_level"], title_error_level=graphical_abstract_rules["title_error_level"], graphic_error_level=graphical_abstract_rules["graphic_error_level"], ) + yield validator.validate_exists( + article_type_requires=[], + article_type_unexpects=graphical_abstract_rules["article_type_unexpects"], + article_type_neutral=graphical_abstract_rules["article_type_neutral"], + article_type_accepts=graphical_abstract_rules["article_type_accepts"] + ) def validate_article(xmltree, params): diff --git a/packtools/sps/validation_rules/abstract_rules.json b/packtools/sps/validation_rules/abstract_rules.json index 880c4f939..132cb92d5 100644 --- a/packtools/sps/validation_rules/abstract_rules.json +++ b/packtools/sps/validation_rules/abstract_rules.json @@ -8,6 +8,31 @@ "key-points", "graphical", null + ], + "article_type_requires": [ + "case-report", + "research-article", + "review-article", + ], + "article_type_unexpects": [ + "addendum", + "article-commentary", + "book-review", + "brief-report", + "correction", + "editorial", + "letter", + "obituary", + "partial-retraction", + "product-review", + "rapid-communication", + "reply", + "retraction", + "other" + ], + "article_type_neutral": [ + "reviewer-report", + "data-article", ] } } \ No newline at end of file diff --git a/packtools/sps/validation_rules/graphical_abstract_rules.json b/packtools/sps/validation_rules/graphical_abstract_rules.json index 2fce13cdf..07985e7ce 100644 --- a/packtools/sps/validation_rules/graphical_abstract_rules.json +++ b/packtools/sps/validation_rules/graphical_abstract_rules.json @@ -2,6 +2,32 @@ "graphical_abstract_rules": { "kwd_error_level": "CRITICAL", "title_error_level": "WARNING", - "graphic_error_level": "CRITICAL" + "graphic_error_level": "CRITICAL", + "absence_error_level": "WARNING", + "article_type_accepts": [ + "case-report", + "research-article", + "review-article", + ], + "article_type_unexpects": [ + "addendum", + "article-commentary", + "book-review", + "brief-report", + "correction", + "editorial", + "letter", + "obituary", + "partial-retraction", + "product-review", + "rapid-communication", + "reply", + "retraction", + "other" + ], + "article_type_neutral": [ + "reviewer-report", + "data-article", + ] } } \ No newline at end of file diff --git a/packtools/sps/validation_rules/highlight_rules.json b/packtools/sps/validation_rules/highlight_rules.json index a83ef71a7..60341a1a0 100644 --- a/packtools/sps/validation_rules/highlight_rules.json +++ b/packtools/sps/validation_rules/highlight_rules.json @@ -3,6 +3,32 @@ "kwd_error_level": "CRITICAL", "title_error_level": "WARNING", "p_error_level": "CRITICAL", - "list_error_level": "CRITICAL" + "list_error_level": "CRITICAL", + "absence_error_level": "WARNING", + "article_type_accepts": [ + "case-report", + "research-article", + "review-article", + ], + "article_type_unexpects": [ + "addendum", + "article-commentary", + "book-review", + "brief-report", + "correction", + "editorial", + "letter", + "obituary", + "partial-retraction", + "product-review", + "rapid-communication", + "reply", + "retraction", + "other" + ], + "article_type_neutral": [ + "reviewer-report", + "data-article", + ] } } \ No newline at end of file diff --git a/tests/sps/validation/test_article_abstract.py b/tests/sps/validation/test_article_abstract.py index e293bf30e..e635d3a6d 100644 --- a/tests/sps/validation/test_article_abstract.py +++ b/tests/sps/validation/test_article_abstract.py @@ -2,12 +2,49 @@ from lxml import etree as ET -from packtools.sps.validation.article_abstract import HighlightValidation, HighlightsValidation, VisualAbstractValidation, VisualAbstractsValidation, ArticleAbstractsValidation -from packtools.sps.models.article_abstract import ArticleHighlights, ArticleVisualAbstracts +from packtools.sps.validation.article_abstract import ( + HighlightValidation, + HighlightsValidation, + VisualAbstractValidation, + VisualAbstractsValidation, + ArticleAbstractsValidation, +) +from packtools.sps.models.article_abstract import ( + ArticleHighlights, + ArticleVisualAbstracts, +) + +VALIDATE_EXISTS_PARAMS = { + "article_type_requires": [], + "article_type_unexpects": [ + "addendum", + "article-commentary", + "book-review", + "brief-report", + "correction", + "editorial", + "letter", + "obituary", + "partial-retraction", + "product-review", + "rapid-communication", + "reply", + "retraction", + "other", + ], + "article_type_neutral": [ + "reviewer-report", + "data-article", + ], + "article_type_accepts": [ + "case-report", + "research-article", + "review-article", + ], +} class HighlightsValidationTest(TestCase): - def test_highlight_validate_exists(self): self.maxDiff = None xml_tree = ET.fromstring( @@ -23,24 +60,26 @@ def test_highlight_validate_exists(self): """ ) - obtained = HighlightsValidation(xml_tree).validate_exists() + obtained = HighlightsValidation(xml_tree).validate_exists( + **VALIDATE_EXISTS_PARAMS + ) expected = { - 'title': 'Article abstracts', - 'parent': 'article', - 'parent_id': None, - 'parent_article_type': None, - 'parent_lang': 'en', - 'item': 'abstract', - 'sub_item': None, - 'validation_type': 'exist', - 'response': 'WARNING', - 'expected_value': 'abstracts', - 'got_value': [], - 'message': 'Got [], expected abstracts', - 'advice': 'article has no abstract', - 'data': None, - } + "title": "abstracts (key-points)", + "parent": "article", + "parent_id": None, + "parent_article_type": "research-article", + "parent_lang": "en", + "item": "abstracts (key-points)", + "sub_item": None, + "validation_type": "exist", + "response": "OK", + "expected_value": "abstracts (key-points) is acceptable", + "got_value": [], + "message": "Got [], expected abstracts (key-points) is acceptable", + "advice": None, + "data": [], + } self.assertDictEqual(expected, obtained) @@ -77,7 +116,9 @@ def test_highlight_validate_tag_list_in_abstract(self): obtained = [] for abstract in ArticleHighlights(xmltree).article_abstracts(): - obtained.append(HighlightValidation(abstract).validate_tag_list_in_abstract()) + obtained.append( + HighlightValidation(abstract).validate_tag_list_in_abstract() + ) expected = [ { @@ -88,23 +129,23 @@ def test_highlight_validate_tag_list_in_abstract(self): "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (key-points)', - "sub_item": 'list', + "item": "abstract (key-points)", + "sub_item": "list", "expected_value": None, - "got_value": ['highlight 1', 'highlight 2'], + "got_value": ["highlight 1", "highlight 2"], "message": "Got ['highlight 1', 'highlight 2'], expected None", - "advice": 'Remove and add

', + "advice": "Remove and add

", "data": { - 'abstract_type': 'key-points', + "abstract_type": "key-points", "highlights": [], - 'kwds': [], - "list": ['highlight 1', 'highlight 2'], + "kwds": [], + "list": ["highlight 1", "highlight 2"], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": "HIGHLIGHTS", - } + }, }, { "title": "list", @@ -114,24 +155,24 @@ def test_highlight_validate_tag_list_in_abstract(self): "parent_lang": "es", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (key-points)', - "sub_item": 'list', + "item": "abstract (key-points)", + "sub_item": "list", "expected_value": None, - "got_value": ['highlight 1', 'highlight 2'], + "got_value": ["highlight 1", "highlight 2"], "message": "Got ['highlight 1', 'highlight 2'], expected None", - "advice": 'Remove and add

', + "advice": "Remove and add

", "data": { - 'abstract_type': 'key-points', + "abstract_type": "key-points", "highlights": [], - 'kwds': [], - "list": ['highlight 1', 'highlight 2'], + "kwds": [], + "list": ["highlight 1", "highlight 2"], "parent": "sub-article", "parent_article_type": "translation", "parent_id": "01", "parent_lang": "es", "title": "HIGHLIGHTS", - } - } + }, + }, ] self.assertEqual(len(obtained), 2) @@ -177,23 +218,23 @@ def test_highlight_validate_tag_p_in_abstract(self): "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (key-points)', - "sub_item": 'p', - "expected_value": 'p', - "got_value": ['highlight 1'], + "item": "abstract (key-points)", + "sub_item": "p", + "expected_value": "p", + "got_value": ["highlight 1"], "message": "Got ['highlight 1'], expected p", - "advice": 'Provide more than one p', + "advice": "Provide more than one p", "data": { - 'abstract_type': 'key-points', - "highlights": ['highlight 1'], + "abstract_type": "key-points", + "highlights": ["highlight 1"], "list": [], - 'kwds': [], + "kwds": [], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": "HIGHLIGHTS", - } + }, } ] @@ -227,30 +268,30 @@ def test_highlight_validate_unexpected_kwd(self): expected = [ { - "title": 'unexpected kwd', + "title": "unexpected kwd", "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (key-points)', - "sub_item": 'kwd', + "item": "abstract (key-points)", + "sub_item": "kwd", "expected_value": None, - "got_value": ['kwd_01', 'kwd_02'], + "got_value": ["kwd_01", "kwd_02"], "message": "Got ['kwd_01', 'kwd_02'], expected None", "advice": "Remove keywords () from ", "data": { - 'abstract_type': 'key-points', + "abstract_type": "key-points", "highlights": [], "list": [], - 'kwds': ['kwd_01', 'kwd_02'], + "kwds": ["kwd_01", "kwd_02"], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": None, - } + }, } ] @@ -284,34 +325,36 @@ def test_highlight_validate_tag_title_in_abstract(self): obtained = [] for abstract in ArticleHighlights(xmltree).article_abstracts(): - obtained.append(HighlightValidation(abstract).validate_tag_title_in_abstract()) + obtained.append( + HighlightValidation(abstract).validate_tag_title_in_abstract() + ) expected = [ { - "title": 'title', + "title": "title", "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (key-points)', - "sub_item": 'title', - "expected_value": 'title', + "item": "abstract (key-points)", + "sub_item": "title", + "expected_value": "title", "got_value": None, - "message": 'Got None, expected title', - "advice": 'Provide title', + "message": "Got None, expected title", + "advice": "Provide title", "data": { - 'abstract_type': 'key-points', - "highlights": ['highlight 1'], + "abstract_type": "key-points", + "highlights": ["highlight 1"], "list": [], - 'kwds': [], + "kwds": [], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": None, - } + }, } ] @@ -338,24 +381,26 @@ def test_visual_abstracts_validate_exists(self): """ ) - obtained = VisualAbstractsValidation(xml_tree).validate_exists() + obtained = VisualAbstractsValidation(xml_tree).validate_exists( + **VALIDATE_EXISTS_PARAMS + ) expected = { - 'title': 'Article abstracts', - 'parent': 'article', - 'parent_id': None, - 'parent_article_type': None, - 'parent_lang': 'en', - 'item': 'abstract', - 'sub_item': None, - 'validation_type': 'exist', - 'response': 'WARNING', - 'expected_value': 'abstracts', - 'got_value': [], - 'message': 'Got [], expected abstracts', - 'advice': 'article has no abstract', - 'data': None, - } + "title": "abstracts (graphical)", + "parent": "article", + "parent_id": None, + "parent_article_type": "research-article", + "parent_lang": "en", + "item": "abstracts (graphical)", + "sub_item": None, + "validation_type": "exist", + "response": "OK", + "expected_value": "abstracts (graphical) is acceptable", + "got_value": [], + "message": "Got [], expected abstracts (graphical) is acceptable", + "advice": None, + "data": [], + } self.assertDictEqual(obtained, expected) @@ -380,35 +425,37 @@ def test_visual_abstracts_validate_unexpected_kwd(self): obtained = [] for abstract in ArticleVisualAbstracts(xml_tree).article_abstracts(): - obtained.append(VisualAbstractValidation(abstract).validate_unexpected_kwd()) + obtained.append( + VisualAbstractValidation(abstract).validate_unexpected_kwd() + ) expected = [ { - "title": 'unexpected kwd', + "title": "unexpected kwd", "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (graphical)', - "sub_item": 'kwd', + "item": "abstract (graphical)", + "sub_item": "kwd", "expected_value": None, - "got_value": ['kwd_01', 'kwd_02'], + "got_value": ["kwd_01", "kwd_02"], "message": "Got ['kwd_01', 'kwd_02'], expected None", "advice": "Remove keywords () from ", "data": { - 'abstract_type': 'graphical', - 'caption': None, - 'fig_id': None, - 'graphic': None, - 'kwds': ['kwd_01', 'kwd_02'], + "abstract_type": "graphical", + "caption": None, + "fig_id": None, + "graphic": None, + "kwds": ["kwd_01", "kwd_02"], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": None, - } + }, } ] @@ -438,35 +485,37 @@ def test_visual_abstracts_validate_tag_title_in_abstract(self): obtained = [] for abstract in ArticleVisualAbstracts(xml_tree).article_abstracts(): - obtained.append(VisualAbstractValidation(abstract).validate_tag_title_in_abstract()) + obtained.append( + VisualAbstractValidation(abstract).validate_tag_title_in_abstract() + ) expected = [ { - "title": 'title', + "title": "title", "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (graphical)', - "sub_item": 'title', - "expected_value": 'title', + "item": "abstract (graphical)", + "sub_item": "title", + "expected_value": "title", "got_value": None, - "message": 'Got None, expected title', - "advice": 'Provide title', + "message": "Got None, expected title", + "advice": "Provide title", "data": { - 'abstract_type': 'graphical', - 'caption': None, - 'fig_id': None, - 'graphic': None, - 'kwds': ['kwd_01', 'kwd_02'], + "abstract_type": "graphical", + "caption": None, + "fig_id": None, + "graphic": None, + "kwds": ["kwd_01", "kwd_02"], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": None, - } + }, } ] @@ -496,35 +545,37 @@ def test_visual_abstracts_validate_tag_graphic_in_abstract(self): obtained = [] for abstract in ArticleVisualAbstracts(xml_tree).article_abstracts(): - obtained.append(VisualAbstractValidation(abstract).validate_tag_graphic_in_abstract()) + obtained.append( + VisualAbstractValidation(abstract).validate_tag_graphic_in_abstract() + ) expected = [ { - "title": 'graphic', + "title": "graphic", "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "validation_type": "exist", "response": "ERROR", - "item": 'abstract (graphical)', - "sub_item": 'graphic', - "expected_value": 'graphic', + "item": "abstract (graphical)", + "sub_item": "graphic", + "expected_value": "graphic", "got_value": None, - "message": 'Got None, expected graphic', - "advice": 'Provide graphic', + "message": "Got None, expected graphic", + "advice": "Provide graphic", "data": { - 'abstract_type': 'graphical', - 'caption': None, - 'fig_id': None, - 'graphic': None, - 'kwds': ['kwd_01', 'kwd_02'], + "abstract_type": "graphical", + "caption": None, + "fig_id": None, + "graphic": None, + "kwds": ["kwd_01", "kwd_02"], "parent": "article", "parent_article_type": "research-article", "parent_id": None, "parent_lang": "en", "title": None, - } + }, } ] @@ -562,11 +613,15 @@ def test_abstract_type_validation(self): """ ) - obtained = list(ArticleAbstractsValidation(xml_tree).validate_abstracts_type(expected_abstract_type_list=["key-points", "graphical"])) + obtained = list( + ArticleAbstractsValidation(xml_tree).validate_abstracts_type( + expected_abstract_type_list=["key-points", "graphical"] + ) + ) expected = [ { - "title": "abstract-type attribute", + "title": "@abstract-type", "parent": "article", "parent_article_type": "research-article", "parent_id": None, @@ -575,10 +630,10 @@ def test_abstract_type_validation(self): "sub_item": "@abstract-type", "validation_type": "value in list", "response": "ERROR", - "got_value": '', - "expected_value": ' or ', - "message": 'Got , expected or ', - "advice": 'Provide or ', + "got_value": "invalid-value", + "expected_value": ["key-points", "graphical"], + "message": "Got invalid-value, expected ['key-points', 'graphical']", + "advice": "Use one of ['key-points', 'graphical'] as abstract-type", "data": { "abstract_type": "invalid-value", "html_text": "HIGHLIGHTS highlight 1 highlight 2", @@ -591,7 +646,7 @@ def test_abstract_type_validation(self): }, }, { - "title": "abstract-type attribute", + "title": "@abstract-type", "parent": "sub-article", "parent_article_type": "translation", "parent_id": "01", @@ -600,10 +655,10 @@ def test_abstract_type_validation(self): "sub_item": "@abstract-type", "validation_type": "value in list", "response": "ERROR", - "got_value": '', - "expected_value": ' or ', - "message": 'Got , expected or ', - "advice": 'Provide or ', + "got_value": "invalid-value", + "expected_value": ["key-points", "graphical"], + "message": "Got invalid-value, expected ['key-points', 'graphical']", + "advice": "Use one of ['key-points', 'graphical'] as abstract-type", "data": { "abstract_type": "invalid-value", "html_text": "HIGHLIGHTS highlight 1 highlight 2", @@ -615,8 +670,7 @@ def test_abstract_type_validation(self): "parent_lang": "es", "plain_text": "HIGHLIGHTS highlight 1 highlight 2", }, - } - + }, ] self.assertEqual(len(obtained), 2)